| 77 | | applyStory :: (String -> [(String, String)] -> IO String) -> Entry -> IO String |
| 78 | | applyStory fill e = fill "story" [("title", title e), |
| 79 | | ("body", concat (body e)), |
| 80 | | ("time", formatCalendarTime defaultTimeLocale "%Y-%m-%d %H:%M:%S" (toUTCTime (time e))), |
| 81 | | ("path", path e)] |
| | 77 | |
| | 78 | getResult :: [(String, String)] -> IO (String, String) |
| | 79 | getResult cgiparams = do |
| | 80 | { |
| | 81 | ; entries <- getTextFileEntries "data" |
| | 82 | ; ct <- fill "content_type" [] |
| | 83 | ; ch <- fill "head" [] |
| | 84 | ; cs <- mapM |
| | 85 | (\e -> fill "story" |
| | 86 | [("title", title e), |
| | 87 | ("body", concat (body e)), |
| | 88 | ("time", formatCalendarTime defaultTimeLocale "%Y-%m-%d %H:%M:%S" (toUTCTime (time e))), |
| | 89 | ("path", path e)]) |
| | 90 | $ take 7 $ reverse $ sortBy (\a b -> compare (time a) (time b)) entries |
| | 91 | ; cf <- fill "foot" [] |
| | 92 | ; return $ (ct, concat $ [ch, concat cs, cf]) |
| | 93 | } where |
| | 94 | fill place params = fillFlavour "html" place (params ++ [("title", "Blosxkel.hs"), |
| | 95 | ("version", "aaa")] ++ cgiparams) |
| 86 | | ; entries <- liftIO $ getTextFileEntries "data" |
| 87 | | ; ct <- liftIO $ fill "content_type" [] |
| 88 | | ; ch <- liftIO $ fill "head" [] |
| 89 | | ; cs <- liftIO $ mapM (applyStory fill) $ take 7 $ reverse $ sortBy (\a b -> compare (time a) (time b)) entries |
| 90 | | ; cf <- liftIO $ fill "foot" [] |
| 91 | | ; setHeader "Content-Type" ct |
| 92 | | ; output $ concat $ [ch, concat cs, cf] |
| 93 | | } where |
| 94 | | fill place params = fillFlavour "html" place (params ++ [("title", "Blosxkel.hs"), |
| 95 | | ("version", "aaa")]) |
| | 100 | ; home <- scriptName |
| | 101 | ; result <- liftIO $ getResult [("home", home)] |
| | 102 | ; setHeader "Content-Type" $ fst result |
| | 103 | ; output $ snd result |
| | 104 | } |