Implement Tags!
This commit is contained in:
parent
f41c5e6a5a
commit
eb67654568
24
site.hs
24
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`
|
||||
|
@ -1,12 +1,12 @@
|
||||
<article class="group">
|
||||
<h1>$title$</h1>
|
||||
<p class="subtitle">$date$</p>
|
||||
<p class="subtitle">$date$
|
||||
$if(tags)$
|
||||
, posted in $tags$
|
||||
$endif$
|
||||
</p>
|
||||
|
||||
<section>
|
||||
$body$
|
||||
</section>
|
||||
<section>
|
||||
$if(tags)$
|
||||
<br>Posted in <i>$tags$</i>
|
||||
$endif$
|
||||
</section>
|
||||
</article>
|
||||
|
Loading…
Reference in New Issue
Block a user