I recently implemented an atom feed on my site. I wrote a post about it [
http://blaenkdenum.com/posts/post-feed-in-hakyll/ ] detailing how I did it.
I couldn't just take a snapshot after compiling each post, because the way I compile each post manipulates each post in such a ways that don't mesh well with feed readers -- i.e. adds a table of contents, syntax highlights codeblocks with Pygments, uses MathJax. So the solution I came up with was to define another pandoc compiler that did _not_ include these additional transformations, and that did not use MathJax in its writer options.
To accomplish this, I essentially created a snapshot of each post, and then I have a rule for a separate "feed" version of each post.
The reason I create a snapshot is because I want to run the item body through a filter in both cases (regular post and feed version), but then I want to compile them using different Pandoc Compilers (i.e. using a simpler one for the feed version). So in the feed version rule I load the snapshot I saved in the regular, no-version rule, after it had been run through the filter, and then compile that using the simpler Pandoc compiler.
The feed itself is then generated using the "feed" versions of the posts, using the typical:
> fmap (take 10) . recentFirst =<< loadAll "etc"
when I'm rendering the feed.
The problem of course is that I'm effectively compiling every post twice, albeit with different compilers each time. I couldn't figure out a better way to do this, so I was hoping that lazy evaluation would save the day by only compiling the ten most recent (according to the above code) posts using the simpler feed compiler. However, upon testing it seems that there's a (feed) version of every post being compiled, even if it's not ultimately included in the rendered atom feed.
Is this expected behavior? Or am I perhaps doing something wrong that's causing this to happen? Perhaps an implicit dependency is created somewhere that is forcing all of them to be compiled? What in the above code forces/causes all posts to be compiled, loadAll?
The relevant code is available here [
https://github.com/blaenk/blaenk.github.io/blob/source/src/Site.hs#L67-L109 ].
If this is expected behavior, and lazy evaluation doesn't save me from the unnecessary work, perhaps someone can propose a different way of doing this? It just seems like this approach might not scale well in the future if every single post has to be compiled twice.
Thanks!