Skip to content

Commit

Permalink
Added support for Hakyll style categories.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgoulter committed Jun 28, 2014
1 parent 549c8b8 commit 336e3ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions index.html
Expand Up @@ -18,4 +18,7 @@ <h2>Posts</h2>
<div id="secondary">
<h3>Tags</h3>
$taglist$

<h3>Categories</h3>
$categorylist$
</div>
31 changes: 25 additions & 6 deletions site.hs
Expand Up @@ -6,6 +6,8 @@ import Hakyll
-- for tags, follow tutorial from:
-- http://javran.github.io/posts/2014-03-01-add-tags-to-your-hakyll-blog.html

-- postsGlob :: Pattern
-- postsGlob = "posts/*"

--------------------------------------------------------------------------------
main :: IO ()
Expand All @@ -25,23 +27,39 @@ main = hakyll $ do
>>= relativizeUrls

-- build up tags
tags <- buildTags "posts/*" (fromCapture "tags/*.html")
tags <- buildTags "posts/**.markdown" (fromCapture "tags/*.html")

categories <- buildCategories "posts/**.markdown" (fromCapture "categories/*.html")

tagsRules tags $ \tag pattern -> do
let title = "Posts tagged\"" ++ tag ++ "\""
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

tagsRules categories $ \tag pattern -> do
let title = "Posts in category \"" ++ 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

match "posts/*" $ do
match "posts/**.markdown" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
Expand All @@ -51,7 +69,7 @@ main = hakyll $ do
create ["archive.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
posts <- recentFirst =<< loadAll "posts/**.markdown"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Archives" `mappend`
Expand All @@ -66,11 +84,12 @@ main = hakyll $ do
match "index.html" $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
posts <- recentFirst =<< loadAll "posts/**.markdown"
let indexCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Home" `mappend`
field "taglist" (\_ -> renderTagList tags) `mappend`
field "categorylist" (\_ -> renderTagList categories) `mappend`
defaultContext

getResourceBody
Expand Down

0 comments on commit 336e3ae

Please sign in to comment.