From eb676545687f41825dda4bd4fa8212332c094dec Mon Sep 17 00:00:00 2001 From: Dhananjay Balan Date: Mon, 28 Jan 2019 16:42:01 -0500 Subject: [PATCH] Implement Tags! --- site.hs | 24 +++++++++++++++++++++--- templates/post.html | 12 ++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/site.hs b/site.hs index 563b4e8..21b70ba 100644 --- a/site.hs +++ b/site.hs @@ -34,7 +34,7 @@ feedConfig = FeedConfiguration { main :: IO () main = hakyllWith config $ do - tags <- extractTags + tags <- buildTags "blog/*" (fromCapture "tags/*.html") match "images/*" $ do route idRoute @@ -59,9 +59,9 @@ main = hakyllWith config $ do match "blog/*" $ do route $ octopressRoute compile $ pandocCompiler - >>= loadAndApplyTemplate "templates/post.html" postCtx + >>= loadAndApplyTemplate "templates/post.html" (postCtxWTags tags) >>= saveSnapshot "content" - >>= loadAndApplyTemplate "templates/default.html" postCtx + >>= loadAndApplyTemplate "templates/default.html" (postCtxWTags tags) >>= relativizeUrls match "index.html" $ do @@ -93,6 +93,21 @@ main = hakyllWith config $ do >>= loadAndApplyTemplate "templates/default.html" archiveCtx >>= relativizeUrls + -- tags! + tagsRules tags $ \tag pattern -> do + let title = "Posts tagged \"" ++ tag ++ "\"" + route idRoute + compile $ do + posts <- recentFirst =<< loadAll pattern + let ctx = constField "title" title + `mappend` listField "posts" postCtx (return posts) + `mappend` defaultContext + + makeItem "" + >>= loadAndApplyTemplate "templates/tag.html" ctx + >>= loadAndApplyTemplate "templates/default.html" ctx + >>= relativizeUrls + create ["atom.xml"] $ do route idRoute compile $ do @@ -107,6 +122,9 @@ extractTags = do tags <- buildTags ("blogs/**" .&&. hasNoVersion) $ fromCapture "tags/*.html" return $ sortTagsBy caseInsensitiveTags tags +postCtxWTags :: Tags -> Context String +postCtxWTags tags = tagsField "tags" tags <> postCtx + postCtx :: Context String postCtx = dateField "date" "%B %e, %Y" `mappend` diff --git a/templates/post.html b/templates/post.html index 7336351..ac0d2ce 100644 --- a/templates/post.html +++ b/templates/post.html @@ -1,12 +1,12 @@

$title$

-

$date$

+

$date$ + $if(tags)$ + , posted in $tags$ + $endif$ +

+
$body$
-
- $if(tags)$ -
Posted in $tags$ - $endif$ -