Changeset 1158 for lang/haskell

Show
Ignore:
Timestamp:
11/05/07 22:06:28 (13 months ago)
Author:
jknaoya
Message:

lang/haskell/blosxkel/blosxkel.hs:

blosxom の感じにあわせました。path は data とか拡張子とかふくまないように

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/blosxkel/blosxkel.hs

    r1157 r1158  
    44module Main where 
    55 
     6import System.FilePath 
    67import System.Directory 
    78import System.Time 
     
    1112import Data.Maybe 
    1213import Data.Char 
     14import Data.Eq 
    1315 
    1416import Network.CGI 
     
    3133 
    3234data Entry = Entry { 
    33     path  :: FilePath, 
     35    file  :: FilePath, 
     36    path  :: String, 
    3437    title :: String, 
    3538    time  :: ClockTime, 
     
    3841 
    3942 
    40 getFileEntry :: FilePath -> IO Entry 
    41 getFileEntry f = do 
    42     { mtime <- getModificationTime f 
     43getFileEntry :: String -> FilePath -> IO Entry 
     44getFileEntry d f = do 
     45    { 
     46    ; mtime <- getModificationTime f 
    4347    ; cs    <- readFile f 
    4448    ; case lines cs of 
    45         h:tl -> return $ Entry { path  = f 
     49        h:tl -> return $ Entry { file  = f 
     50                               , path  = dropExtension $ drop (length d) f 
    4651                               , title = h 
    4752                               , time  = mtime 
     
    5358getRecursiveContents :: FilePath -> IO [FilePath] 
    5459getRecursiveContents fp = getDirectoryContents fp >>= mapM (fx fp) >>= return . concat 
    55  where 
    56    fx :: FilePath -> FilePath -> IO [FilePath] 
    57    fx bp "."  = return [bp] 
    58    fx bp ".." = return [] 
    59    fx bp f    = do let np = bp ++ ('/':f) 
    60                    b <- doesDirectoryExist np 
    61                    if b then getRecursiveContents np 
    62                         else return [np] 
     60    where 
     61       fx :: FilePath -> FilePath -> IO [FilePath] 
     62       fx bp "."  = return [bp] 
     63       fx bp ".." = return [] 
     64       fx bp f    = do let np = bp ++ ('/':f) 
     65                       b <- doesDirectoryExist np 
     66                       if b then getRecursiveContents np 
     67                            else return [np] 
    6368 
    6469 
     
    6772getTextFileEntries d = do 
    6873    { 
    69     ; cdir <- getCurrentDirectory 
    70     ; setCurrentDirectory d 
    71     ; fs <- getRecursiveContents "." 
    72     ; es <- mapM getFileEntry $ filter (isSuffixOf ".txt") fs 
    73     ; setCurrentDirectory cdir 
     74    ; fs <- getRecursiveContents d 
     75    ; es <- mapM (getFileEntry d) $ filter (isSuffixOf ".txt") fs 
    7476    ; return es 
    7577    } 
     
    99101    { 
    100102    ; home <- scriptName 
    101     ; result <- liftIO $ getResult [("home", home)] 
     103    ; pathinfo <- pathInfo 
     104    ; result <- liftIO $ getResult [("home", home), ("pathinfo", pathinfo)] 
    102105    ; setHeader "Content-Type" $ fst result 
    103106    ; output $ snd result