From: Lucian Mogosanu Date: Sat, 20 Jul 2013 13:31:14 +0000 (+0300) Subject: add support for tags X-Git-Tag: v0.1~27 X-Git-Url: https://git.mogosanu.ro/?a=commitdiff_plain;h=a6901d9551d97d90ccc81d0b2572ab4f8e480902;p=thetarpit.git add support for tags --- diff --git a/css/default.css b/css/default.css index d4fb30d..4b538dd 100644 --- a/css/default.css +++ b/css/default.css @@ -29,7 +29,7 @@ a:hover { color: #555; font-size: 15px; font-style: italic; - margin-top: -12px; + margin-top: -15px; } .info sup { @@ -37,6 +37,10 @@ a:hover { font-style: normal; } +.tags { + color: #333; +} + #header { border-bottom: 1.5px dashed #aaa; margin-bottom: 30px; diff --git a/posts/000-first-post.markdown b/posts/000-first-post.markdown index 55af945..66aef3f 100644 --- a/posts/000-first-post.markdown +++ b/posts/000-first-post.markdown @@ -3,6 +3,7 @@ postid: 000 title: First post author: Lucian Mogoșanu date: July 17, 2013 +tags: asphalt --- First post. diff --git a/site.hs b/site.hs index a4543ea..c4f327d 100644 --- a/site.hs +++ b/site.hs @@ -2,14 +2,26 @@ import Data.Monoid (mappend) import Hakyll +-- wrapping it up main :: IO () main = hakyll $ do + -- tags + tags <- buildTags "posts/*" $ fromCapture "tags/*.html" + + -- content match "index.html" compileIndex match "css/*" compileCss - match "posts/*" compilePosts + match "posts/*" $ compilePosts tags match (fromList ["about.markdown"]) compilePages create ["archive.html"] compileArchive + + -- tags rules + tagsRules tags $ compileTags tags + + -- rss feed create ["rss.xml"] compileRss + + -- compile templates match "templates/*" $ compile templateCompiler -- compilers go here @@ -32,13 +44,14 @@ compileCss = do route idRoute compile compressCssCompiler -compilePosts :: Rules () -compilePosts = do +compilePosts :: Tags -> Rules () +compilePosts tags = do route $ setExtension "html" + let ctx = tagsCtx tags compile $ pandocCompiler >>= saveSnapshot "content" - >>= loadAndApplyTemplate "templates/post.html" postCtx - >>= loadAndApplyTemplate "templates/default.html" postCtx + >>= loadAndApplyTemplate "templates/post.html" ctx + >>= loadAndApplyTemplate "templates/default.html" ctx >>= relativizeUrls compilePages :: Rules () @@ -62,6 +75,22 @@ compileArchive = do >>= loadAndApplyTemplate "templates/default.html" archiveCtx >>= relativizeUrls +compileTags :: Tags -> String -> Pattern -> Rules () +compileTags tags tag pattern = do + let title = "Posts tagged '" ++ tag ++ "'" + route idRoute + compile $ do + posts <- loadAll pattern >>= recentFirst + let tagCtx = + constField "title" title `mappend` + listField "posts" postCtx (return posts) `mappend` + tagsCtx tags + makeItem "" + >>= loadAndApplyTemplate "templates/post-list.html" tagCtx + >>= loadAndApplyTemplate "templates/default.html" tagCtx + >>= relativizeUrls + + compileRss :: Rules () compileRss = do -- shamelessly stolen from @@ -82,6 +111,9 @@ compileRss = do postCtx :: Context String postCtx = dateField "date" "%B %e, %Y" `mappend` defaultContext +tagsCtx :: Tags -> Context String +tagsCtx tags = tagsField "tags" tags `mappend` postCtx + -- support for RSS feeds tarpitFeed :: FeedConfiguration tarpitFeed = FeedConfiguration diff --git a/templates/post.html b/templates/post.html index 3166e43..54b9e84 100644 --- a/templates/post.html +++ b/templates/post.html @@ -1,9 +1,7 @@
$postid$ - Posted on $date$ - $if(author)$ - by $author$ - $endif$ + $date$ -- + $tags$
$body$