Hakyll Post Matching

Posted on January 23, 2024

Following two match statements are my favourite parts of my site.hs.

match (fromList ["about.rst", "contact.markdown", "cv.rst"]) $ do
    route   $ setExtension "html"
    compile $ pandocMathCompiler
        >>= loadAndApplyTemplate "templates/default.html" defaultContext
        >>= relativizeUrls

match ("posts/*" .&&. (complement "posts/*.draft.*")) $ do
    route $ setExtension "html"
    compile $ pandocMathCompiler
        >>= loadAndApplyTemplate "templates/post.html"    postCtx
        >>= loadAndApplyTemplate "templates/default.html" postCtx
        >>= relativizeUrls

(complement "posts/*.draft.*") filters out every post with draft file extension followed by that of its original. Editing site.hs like this reminds me the time when I was using dwm. If you want something to be different, you don’t work with configuration file read by the system, you just change the C header file and recompile it. Same principle works for Hakyll as well, also more systemically and cleanly, thanks to its monadic interface.

By the way the first match is describing the LaTeX compilation process (pandocMathCompiler is well-defined above in my source).

Planning to make the blog repository public someday to share my modifications.