Post summaries under list of posts like in default template(similar to teasers)

93 views
Skip to first unread message

ice...@gmail.com

unread,
Jan 21, 2014, 6:05:46 PM1/21/14
to hak...@googlegroups.com
Greetings!

I am trying to expand upon the default template which lists recent posts in
the default template by adding post summaries below them, which I guess I will
clip by using the CSS overflow property or something in that direction. When
compiling posts, I currently save a snapshot called "content" before applying
any template to it whatsoever, so this gets me the body.  postCtx now looks
like this(this is temporary, I know all posts now have an extraneous field and
so on which is unnecessary) 


postCtx :: Context String
postCtx =
    field "teaser" foo  `mappend`
    dateField "date" "%B %e, %Y" `mappend`
    defaultContext
  where
    foo :: Item String -> Compiler String
    foo item = loadSnapshotBody (itemIdentifier item) "content"

So this lets me load the body of each item's content snapshot. I like it, it's
pretty smart. 
However, while I could simply do some CSS magic here by limiting the size of
the container and use the overflow property, that could result in some strange
looking summaries if I have Latex in there, or code. I would ideally like to
grab just the first paragraph of the body. I could probably whip something up
in Haskell that does that, but I am not very familiar with neither Hakyll nor
Pandoc, so I figured that some of you might have wanted to do something
similar and maybe solved this problem already.

I would really appreciate any advice and/or input regarding this, even if it's
"don't do this!", as I'm also really new to web design in general.

Jasper Van der Jeugt

unread,
Jan 22, 2014, 10:40:59 AM1/22/14
to hak...@googlegroups.com
Hello!

Hakyll has something built-in for this called "teasers". There is a tutorial about them available here [1]. Would that work in your case?

[1]: http://jaspervdj.be/hakyll/tutorials/using-teasers-in-hakyll.html

Hope this helps,
Peace,
Jasper
> --
> 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.

hata...@gmail.com

unread,
Jan 23, 2014, 2:19:02 PM1/23/14
to hak...@googlegroups.com
Wow, I was just about to ask the same thing - I am having trouble understanding the tutorial, especially when it comes to the teaserField function. I created the template, and am saving the snapshot, but can't figure out how to tie it all together. Would it be possible to upload a site.hs using this function? I would be so very very grateful. :)

Thank you!

Grace

Daniil Frumin

unread,
Jan 24, 2014, 6:08:45 AM1/24/14
to hak...@googlegroups.com
I don't have any examples handy, but if you post your site.hs I might
help you with pointing out places you need to modify in order to get
teasers to work :)
--
Sincerely yours,
-- Daniil

Grace Hatamyar

unread,
Jan 24, 2014, 1:45:42 PM1/24/14
to hak...@googlegroups.com
Okay great. Here is what I have so far: http://lpaste.net/99051

It compiles, but when I try to build I'm getting this error: [ERROR]
Missing field $teaser$ in context for item index.html (first it didn't
find $date$, so I deleted that field in the template, and now it doesn't
find $teaser$)

I have the template in postitem.html (its the same as the example from
the tutorial), and have marked off where the teaser content should be in
an example post file, so I'm assuming this has to do with how i've used
the teaserField function. I'm very much a beginner with Haskell so,
again, I really appreciate the help.

Grace

Daniil Frumin

unread,
Jan 24, 2014, 2:36:40 PM1/24/14
to hak...@googlegroups.com
I would put something like

posts' <- applyTemplateList "template/postitem.html" (teaserField
"teaser" "content" <> defaultContext) posts

after

posts <- recentFirst =<< loadAll "posts/*"

and then use posts' instead.

You are trying to apply a postitem.html template not to each of the
post items, but to the index.html page itself, which doesn't have a
teaser
Sincerely yours,
-- Daniil
Reply all
Reply to author
Forward
0 new messages