haskellhakyll

How to filter Hakyll posts with a custom metadata


I would like to filter some posts of my website based on a metadata value. I would like to create a specific metadata called status (like title or date) which could take several values (draft, published, archive) :

---
title: The title
author: Myself
date: 2016-11-29
tags: tag1, tag2
status: draft
---

According to the value of the status metadata, the post should be published or not.

I have a look in the hackage documentation but I'm not sure of the functions to use.

Do you know how to make that with Hakyll ?


Solution

  • You are probably looking for matchMetadata:

    matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules ()
    

    With it, instead of, say...

    match "posts/*.md" $ do -- etc.
    

    ... you might have:

    matchMetadata "posts/*.md" (\m -> lookupString "status" m == Just "published") $ do -- etc.