Open diegovdc opened 6 years ago
This is the expected behavior. Take a look at this tutorial: https://jaspervdj.be/hakyll/tutorials/05-snapshots-feeds.html
The relevant snippet here is
posts <- recentFirst =<< loadAll "posts/*"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
...
You probably know that listField
is going to take each Item
it's fed, and within the body of the for
loop, apply postCtx
to determine the value of the keys. The issue is that by load
ing the posts, you are actually loading the final compiled content, so that's what $body$
refers to.
As mentioned in the tutorial, you can resolve this problem by taking a Snapshot
early on within the post compiler, and replacing load
with loadAllSnapshots
inside the archive compiler.
thanks for the hint @dunnl, but i'm struggling to see how to make this work.
like, how can i define a new field, called content
that has the body
of the posts in them?
that is, the problem i'm having is as the original poster; that i just want a variable for the $body$
of the blog post. maybe i'm wrong, but the tutorial you show is for saving the rendered template of that post, and then using that as the iterable over which to run the atom generating, or such.
the problem i have is different - i just want to be able to print the blog body in a for loop.
-- edit: turns out it works now, for reasons i don't understand. :shrug:
@silky I think you will find it is a matter of at what point you take the snapshot. The snippet above is certainly going to give you the "final output" but if you use 'loadAllSnapshots' instead of 'loadAll' you're going to get you what you fed into the snapshot. If you do this early enough you should be able to get to the most raw content.
Final thought: you might also have an issue with what Context
you are using. I forget entirely how Hakyll works but I recall this being a sensitive thing. If your context is defined to have two fields called content
then one of them takes precedence over the other. Stuff like that. listField
takes a Context
parameter too so that's one way this stuff can bite you.
I was playing with the example at
templates/post-list.html
, and I was trying to print the body of the post, however, it did not only print the body of the post, but the whole html.This:
Gets rendered into this:
Am I doing something wrong?