I want to add a custom field to my posts called coolness, like this:
---
title: Something
coolness: 10
---
and then I want to sort my posts by coolness. How do I do that? I know I can sort by date:
posts <- recentFirst =<< loadAll "posts/*"
using recentFirst, but that's built-in and I don't really know how to modify it to sort by coolness instead because it uses some custom method to find out what date a post has.
We want to use
MonadMetadataandgetMetadataFieldfrom Hakyll to read the coolness, then parse it to a number, and sort by that number.Stealing heavily from The source for
recentFirst, you could write something like:This sorts on the extracted coolness value. It sorts in increasing coolness, so if you want "coolest first" do: