handle tags
authorrekado <rekado@elephly.net>
Sun, 27 Oct 2013 01:41:03 +0000 (09:41 +0800)
committerrekado <rekado@elephly.net>
Sun, 27 Oct 2013 01:41:03 +0000 (09:41 +0800)
site.hs

diff --git a/site.hs b/site.hs
index a25981662126c61c1ebb3fe87a69b4624199f799..e82251830f5bddb9c714702fb0f9a958094c212a 100644 (file)
--- a/site.hs
+++ b/site.hs
@@ -25,6 +25,8 @@ myFeedConfiguration = FeedConfiguration
 --------------------------------------------------------------------------------
 main :: IO ()
 main = hakyllWith config $ do
+    tags <- buildTags "posts/*.markdown" (fromCapture "tags/*.html")
+
     match "css/*" $ do
         route   idRoute
         compile compressCssCompiler
@@ -98,6 +100,21 @@ main = hakyllWith config $ do
         mostRecent <- fmap head . recentFirst =<< loadAllSnapshots "posts/*.markdown" "non-relative"
         makeItem (itemBody mostRecent) >>= relativizeUrls
 
+
+    tagsRules tags $ \tag pattern -> do
+      let title = "Posts tagged &ldquo;" ++ tag ++ "&rdquo;"
+
+      route idRoute
+      compile $ do
+        let ctx = constField "title" title `mappend`
+                  field "posts" (\_ -> postList pattern recentFirst) `mappend`
+                  defaultContext
+
+        makeItem ""
+            >>= loadAndApplyTemplate "templates/archive.html" ctx
+            >>= loadAndApplyTemplate "templates/default.html" ctx
+            >>= relativizeUrls
+
     match "templates/*" $ compile templateCompiler