Re: [hakyll] Include a list of recent posts in the sidebar

103 views
Skip to first unread message

Jasper Van der Jeugt

unread,
Mar 13, 2013, 1:15:20 PM3/13/13
to hak...@googlegroups.com
Hello Sam,

I think there are two possible solutions.

A first solution assumes you're not using the actual body of the post
in the sidebar. If this is the case, you can just create a list of
"fake items" which represent the posts. You can do that like this:

fakePosts :: Compiler [Item String]
fakePosts = do
identifiers <- getMatches "posts/*"
return [Item identifier "" | identifier <- identifiers]

Then, you can just apply templates to this list, all metadata will be
accessible. I think this is the easiest and most straightforward solution.

Alternatively, you can create two versions for each post page. This
tutorial [1] has more info on how to do that. Then, you use one
version for the sidebar and the other for the actual pages.

Let me know if you need more help with either solution.

[1]: http://jaspervdj.be/hakyll/tutorials/06-versions.html

Hope this helps,
Peace,
Jasper

On Wed, Mar 13, 2013 at 5:25 PM, Samuel Tardieu <s...@rfc1149.net> wrote:
> Hi.
>
> I'm trying to include a list of recent posts in the sidebar of every page on
> my site. However, Hakyll is not happy and detect a dependency cycle on posts
> pages, since indeed, there is one.
>
> Is there a recipe to include such a list in the sidebar?
>
> Sam
>
> --
> 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+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Samuel Tardieu

unread,
Mar 20, 2013, 10:58:37 AM3/20/13
to hak...@googlegroups.com


Le mercredi 13 mars 2013 18:15:20 UTC+1, jaspervdj a écrit :

I think there are two possible solutions.

A first solution assumes you're not using the actual body of the post
in the sidebar. If this is the case, you can just create a list of
"fake items" which represent the posts. You can do that like this:

    fakePosts :: Compiler [Item String]
    fakePosts = do
        identifiers <- getMatches "posts/*"
        return [Item identifier "" | identifier <- identifiers]

Then, you can just apply templates to this list, all metadata will be
accessible. I think this is the easiest and most straightforward solution.

Thank you. Looks like the most straightforward solution indeed, and it is usable in any MonadMetadata context, including Rules. I hadn't seen your answer before (I fixed my group parameters), and I resorted to a similar way of doing this.


Alternatively, you can create two versions for each post page. This
tutorial [1] has more info on how to do that. Then, you use one
version for the sidebar and the other for the actual pages.

Makes sense!

Thanks.

  Sam
Reply all
Reply to author
Forward
0 new messages