Discussion:
[hakyll] List of posts in a post page
Giedrius Kudelis
2015-12-06 16:53:16 UTC
Permalink
Hello!

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:
<ul class="post-list">
$for(allPosts)$
<li>
<a href="$url$">$title$</a> - $date$
</li>
$endfor$
</ul>

If you need to have a look at the whole
repo: https://github.com/gkudelis/gkudelis.github.io/tree/source

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 :).

Best Regards,
Giedrius Kudelis
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Giedrius Kudelis
2015-12-06 17:36:27 UTC
Permalink
Hi again,

I had a look at https://groups.google.com/forum/#!topic/hakyll/F2j7iztwKEc
and at the tutorial again and figured out what was missing. After I add the
line

route $ setExtension "html"

to the "plain" version - everything works! Sorry to bother :).

The other approach in that thread was using getMetadata, but I imagine I
won't be able to get the urls that way. Correct?

Regards,
Giedrius Kudelis
Post by Giedrius Kudelis
Hello!
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
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
<ul class="post-list">
$for(allPosts)$
<li>
<a href="$url$">$title$</a> - $date$
</li>
$endfor$
</ul>
https://github.com/gkudelis/gkudelis.github.io/tree/source
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 :).
Best Regards,
Giedrius Kudelis
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...