Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter Hakyll posts with a custom metadata

Tags:

haskell

hakyll

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 ?

like image 478
JeanJouX Avatar asked Dec 02 '18 23:12

JeanJouX


1 Answers

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.
like image 76
duplode Avatar answered Nov 02 '22 01:11

duplode