Implement Tags!

This commit is contained in:
Dhananjay Balan 2019-01-28 16:42:01 -05:00
parent f41c5e6a5a
commit eb67654568
2 changed files with 27 additions and 9 deletions

24
site.hs
View File

@ -34,7 +34,7 @@ feedConfig = FeedConfiguration {
main :: IO () main :: IO ()
main = hakyllWith config $ do main = hakyllWith config $ do
tags <- extractTags tags <- buildTags "blog/*" (fromCapture "tags/*.html")
match "images/*" $ do match "images/*" $ do
route idRoute route idRoute
@ -59,9 +59,9 @@ main = hakyllWith config $ do
match "blog/*" $ do match "blog/*" $ do
route $ octopressRoute route $ octopressRoute
compile $ pandocCompiler compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx >>= loadAndApplyTemplate "templates/post.html" (postCtxWTags tags)
>>= saveSnapshot "content" >>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx >>= loadAndApplyTemplate "templates/default.html" (postCtxWTags tags)
>>= relativizeUrls >>= relativizeUrls
match "index.html" $ do match "index.html" $ do
@ -93,6 +93,21 @@ main = hakyllWith config $ do
>>= loadAndApplyTemplate "templates/default.html" archiveCtx >>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls >>= 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 create ["atom.xml"] $ do
route idRoute route idRoute
compile $ do compile $ do
@ -107,6 +122,9 @@ extractTags = do
tags <- buildTags ("blogs/**" .&&. hasNoVersion) $ fromCapture "tags/*.html" tags <- buildTags ("blogs/**" .&&. hasNoVersion) $ fromCapture "tags/*.html"
return $ sortTagsBy caseInsensitiveTags tags return $ sortTagsBy caseInsensitiveTags tags
postCtxWTags :: Tags -> Context String
postCtxWTags tags = tagsField "tags" tags <> postCtx
postCtx :: Context String postCtx :: Context String
postCtx = postCtx =
dateField "date" "%B %e, %Y" `mappend` dateField "date" "%B %e, %Y" `mappend`

View File

@ -1,12 +1,12 @@
<article class="group"> <article class="group">
<h1>$title$</h1> <h1>$title$</h1>
<p class="subtitle">$date$</p> <p class="subtitle">$date$
$if(tags)$
, posted in $tags$
$endif$
</p>
<section> <section>
$body$ $body$
</section> </section>
<section>
$if(tags)$
<br>Posted in <i>$tags$</i>
$endif$
</section>
</article> </article>