From a3085337222d239350a2684f455b12c17a69d74b Mon Sep 17 00:00:00 2001 From: Lucian Mogosanu Date: Sat, 20 Jul 2013 12:10:47 +0300 Subject: [PATCH] render rss feed --- site.hs | 25 +++++++++++++++++++++++++ templates/default.html | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/site.hs b/site.hs index 768fc3c..27630fd 100644 --- a/site.hs +++ b/site.hs @@ -9,8 +9,10 @@ main = hakyll $ do match "posts/*" compilePosts match (fromList ["about.markdown"]) compilePages create ["archive.html"] compileArchive + create ["rss.xml"] compileRss match "templates/*" $ compile templateCompiler +-- compilers go here compileIndex :: Rules () compileIndex = do route idRoute -- TODO: make a "copy to root" route? @@ -34,6 +36,7 @@ compilePosts :: Rules () compilePosts = do route $ setExtension "html" compile $ pandocCompiler + >>= saveSnapshot "content" >>= loadAndApplyTemplate "templates/default.html" postCtx >>= relativizeUrls @@ -58,5 +61,27 @@ compileArchive = do >>= loadAndApplyTemplate "templates/default.html" archiveCtx >>= relativizeUrls +compileRss :: Rules () +compileRss = do + -- shamelessly stolen from + -- http://jaspervdj.be/hakyll/tutorials/05-snapshots-feeds.html + route idRoute + compile $ do + let feedCtx = postCtx `mappend` bodyField "description" + posts <- loadAllSnapshots "posts/*" "content" + >>= fmap (take 7) . recentFirst + renderRss tarpitFeed feedCtx posts + +-- post context postCtx :: Context String postCtx = dateField "date" "%B %e, %Y" `mappend` defaultContext + +-- support for RSS feeds +tarpitFeed :: FeedConfiguration +tarpitFeed = FeedConfiguration + { feedTitle = "The Tar Pit" + , feedDescription = "tarpit :: IO ()" + , feedAuthorName = "Lucian Mogoșanu" + , feedAuthorEmail = "" + , feedRoot = "http://thetarpit.org" + } diff --git a/templates/default.html b/templates/default.html index 781c585..3f2e7c9 100644 --- a/templates/default.html +++ b/templates/default.html @@ -17,7 +17,7 @@ -- 1.7.10.4