From 7170488c37105691f4a690cbcf1e43000d779b59 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 9 Apr 2015 01:41:37 +0200 Subject: Minor code cleanup --- build/generate-rss.hs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'build') diff --git a/build/generate-rss.hs b/build/generate-rss.hs index f6ecfa6..2263ba8 100755 --- a/build/generate-rss.hs +++ b/build/generate-rss.hs @@ -25,8 +25,16 @@ type FeedState = (Feed, Maybe T.ClockTime) feedKind = RSSKind $ Just "2.0" +baseurl = "http://dirty-haskell.org" + +description = "dirty-haskell.org — a blog" + +mkUrl' :: FilePath -> String +mkUrl' path = (++) (baseurl ++ "/posts/") $ (flip FP.replaceExtension) "html" $ FP.takeFileName path + + extract_title :: Pandoc -> String -extract_title d@(Pandoc m _) = do +extract_title (Pandoc m _) = do title <- render Nothing $ cat $ map pretty (docTitle m) return title where pretty :: Inline -> Doc @@ -38,9 +46,13 @@ main :: IO () main = do (title:entries) <- getArgs currentTime <- T.getClockTime - let feed = withFeedHome "http://dirty-haskell.org" $ withFeedTitle title $ newFeed feedKind + let feed = foldl1 (.) + [ withFeedDescription description + , withFeedHome baseurl + , withFeedTitle title + ] $ newFeed feedKind (populatedFeed, itemTime) <- S.execStateT (sequence $ map addItem' entries) (feed, Nothing) - let populatedFeed' = withFeedDate (toFeedDateString feedKind $ fromMaybe currentTime itemTime) populatedFeed + let populatedFeed' = withFeedPubDate (toFeedDateString feedKind $ fromMaybe currentTime itemTime) $ withFeedLastUpdate (toFeedDateString feedKind currentTime) $ populatedFeed putStrLn $ X.ppElement $ xmlFeed populatedFeed' addItem' :: FilePath -> S.StateT FeedState IO () @@ -54,11 +66,13 @@ addItem' mdFile = do (feed, time) <- S.get let fileTime = maximum ([F.modificationTime, F.statusChangeTime] <-> fileStatus) :: System.Posix.Types.EpochTime fileTime' = T.TOD (toInteger $ fromEnum fileTime) 0 - let item = [ withItemTitle title + let item = foldl1 (.) + [ withItemTitle title , withItemLink url + , withItemId True url , withItemDate $ toFeedDateString feedKind fileTime' , withItemDescription contents - ] <--> (newItem feedKind) :: Item + ] $ newItem feedKind :: Item S.put (addItem item feed, if (Just fileTime' > time) then Just fileTime' else time) mkUrl :: FilePath -> IO String @@ -69,13 +83,6 @@ mkUrl link = do mkUrl $ FP.combine (FP.takeDirectory link) target else return $ mkUrl' link -mkUrl' :: FilePath -> String -mkUrl' path = (++) "http://dirty-haskell.org/posts/" $ (flip FP.replaceExtension) "html" $ FP.takeFileName path - (<->) :: [(a -> b)] -> a -> [b] [] <-> _ = [] (f:fs) <-> x = (f x:fs <-> x) - -(<-->) :: [(a -> a)] -> a -> a -[] <--> x = x -(f:fs) <--> x = fs <--> (f x) -- cgit v1.2.3