add Atom and RSS feeds
authorrekado <rekado@elephly.net>
Fri, 20 Sep 2013 07:46:27 +0000 (15:46 +0800)
committerrekado <rekado@elephly.net>
Fri, 20 Sep 2013 07:46:27 +0000 (15:46 +0800)
site.hs

diff --git a/site.hs b/site.hs
index fd7f541b0ff6a6ceb4d10fa646acf1e75d2ffba6..350d99998c342665896a7f84cf1b464e735c0bdc 100644 (file)
--- a/site.hs
+++ b/site.hs
@@ -13,6 +13,15 @@ config = defaultConfiguration
   { deployCommand =
       "rsync -Havz _site/ rekado@elephly.net:/srv/disk1/rekado/elephly.net" }
 
+myFeedConfiguration :: FeedConfiguration
+myFeedConfiguration = FeedConfiguration
+  { feedTitle       = "Rekado's website"
+  , feedDescription = "Music, words, and hacking"
+  , feedAuthorName  = "Rekado"
+  , feedAuthorEmail = "rekado+feed@elephly.net"
+  , feedRoot        = "http://elephly.net"
+  }
+
 --------------------------------------------------------------------------------
 main :: IO ()
 main = hakyllWith config $ do
@@ -76,6 +85,9 @@ main = hakyllWith config $ do
           >>= loadAndApplyTemplate "templates/default.html" archiveCtx
           >>= relativizeUrls
 
+    create ["rss.xml"] $ postFeed renderRss
+    create ["atom.xml"] $ postFeed renderAtom
+
     -- always show the most recent blog post
     create ["index.html"] $ do
       route idRoute
@@ -108,6 +120,13 @@ photoSnippet   = snippet "photo-snippet" "photo" "templates/photo.html"
 flattrSnippet  = snippet "flattr-snippet" "flattr" "templates/flattr.html"
 licenseSnippet = snippet "license-snippet" "license" "templates/license.html"
 
+postFeed renderer = do
+  route idRoute
+  compile $ do
+    let feedCtx = postCtx `mappend` bodyField "description"
+    posts <- fmap (take 10) . recentFirst =<<
+      loadAllSnapshots "posts/*.markdown" "content"
+    renderer myFeedConfiguration feedCtx posts
 
 --------------------------------------------------------------------------------
 postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
@@ -128,6 +147,7 @@ customPandocCompiler =
 
 defaultCompiler = customPandocCompiler
   >>= loadAndApplyTemplate "templates/post.html"    postCtx
+  >>= saveSnapshot "content"
   >>= loadAndApplyTemplate "templates/default.html" postCtx
   >>= saveSnapshot "non-relative"
   >>= relativizeUrls