blog post teasers

117 views
Skip to first unread message

Conal Elliott

unread,
Jul 10, 2011, 1:53:45 PM7/10/11
to hak...@googlegroups.com
On my WordPress blog, I use "<!--more-->" to indicate the end of the teaser section. On the blog's front page, the rest of the post is elided, and a link is generated to the full article (part-way through).

Has anyone yet implemented such a feature for Hakyll?

  - Conal

Jasper Van der Jeugt

unread,
Jul 10, 2011, 4:15:07 PM7/10/11
to hak...@googlegroups.com
Not that I know of. But I think it's a good feature and it's probably
a good idea to add this to Hakyll. In the meanwhile, I suggest this
code:

-- | Turns body of the page into the teaser
addTeaser :: Compiler (Page String) (Page String)
addTeaser = arr $
copyBodyToField "teaser" >>> changeField "teaser" extractTeaser
where
extractTeaser :: String -> String
extractTeaser [] = []
extractTeaser xs@(x : xr)
| "<!-- more -->" `isPrefixOf` xs = []
| otherwise = x : extractTeaser xr

(excuse me for the horribly inefficient `extractTeaser` function)

This can be added to your compiler pipeline for a post, *before* you
apply any templates. Then, you should be able to use `$teaser$` in
templates.

Hope this helps,
Cheers,
Jasper

Conal Elliott

unread,
Jul 24, 2011, 1:33:16 AM7/24/11
to hak...@googlegroups.com
Thanks, Jasper. Works great.  - Conal
Reply all
Reply to author
Forward
0 new messages