I'm trying to get all my post pages to show a list of all posts on the blog and link to them. Kind of like an archive on every page in the sidebar. I got the list of posts to be shown using versions. The post titles and dates are correct, however the link URLs are all pointing to the current page. Here's what I have in my site.hs:
main :: IO ()
main = hakyll $ do
(stuff here...)
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/base.html" postCtx
>>= relativizeUrls
-- get unchanged versions too for rendering the post list
match "posts/*" $ version "plain" $ do
compile $ getResourceBody
(more stuff here...)
--------------------------------------------------------------------------------
plainPostCtx :: Context String
plainPostCtx =
dateField "date" "%B %e, %Y" <>
defaultContext
postListCtx :: Context String
postListCtx =
listField "allPosts" plainPostCtx (recentFirst =<< (loadAll $ "posts/*" .&&. hasVersion "plain"))
postCtx :: Context String
postCtx =
postListCtx <>
plainPostCtx
The base template (templates/base.html) uses a partial (templates/post-list.html) which uses the allPosts list. Here's what I have in post-list.html:
I've had a look at the list of pages using hakyll and this does what I want:
http://dannysu.com/2015/10/31/regex-nfa/ (it has a list of most recent posts in the footer). I had a look at the code, but could not figure out what I'm doing wrong. Please help, it feels like I'm missing some small detail, but I'm new to haskell and hakyll and I'm feeling pretty clumsy :).