haskellhakyll

How do I modify the body and fields of a page?


Is it possible with Hakyll to modify a field such as "date", "author" and more specifically the body of a page. For example, I wish to modify or delete some part of page.

I looked at the Hakyll documentation on Hackage. There was a function called changeField which seam to make what I want. But this function is from version 3 of Hakyll, and it doesn't exist in Hakyll 4.5.0, which I am using now.


Solution

  • To modify the page body, use withItemBody while compiling the page. You can use it, for instance, with withTags and the tools provided by the tagsoup package for modifying the DOM tree of an HTML page however you want.

    As for metadata, as far as I am aware of, it is read-only. What you can do instead is using Hakyll.Web.Template.Context to define your own custom contexts for filling in template fields, possibly using metadata fields to do so. The implementation of contexts such as dateField illustrates how that might be done.