Adding Tags

Posted on December 15, 2014
Tags: [ meta, hakyll ]

As an experiment, I added tags to the comics on the site. I’m not sure yet whether to keep the tag cloud on the front page, as I normally don’t use tag clouds on other sites. We’ll see.

In general, adding tags was quite easy, I mostly followed this tutorial and the Hakyll documentation on tags. The only complication was that I generate the comic page HTML on the fly, based on the image files and their metadata (which I store in .metadata files along with the images). The symptom was that the links on the tag pages linked to the images, not to their HTML. I fixed this by adding a custom URL field to the context from which the list entries on the tag pages are rendered, which simply replaces the file extension:

let myUrlField = mapContext (flip replaceExtension "html") . urlField

let postCtx' = myUrlField "url" `mappend`

let ctx = constField "title" title
          `mappend` listField "posts" postCtx' (return posts)
          `mappend` defaultContext

Compare the code above to the corresponding code on the tutorial linked above to see it in context.