Everything was working great up until about a month or so ago...
Suddenly I\'m getting
berkson.github.io/source/blog.hs: 333, 42
• Couldn\'t match
Before hakyll 4.8 the Metadata
type synonym was defined as follows:
type Metadata = HashMap.Map String String
The metadata were just a flat list of key – value pairs.
In hakyll 4.8, metadata parsing was changed (issue, commit, release anouncement) to use YAML parser, to allow more complex metadata structure. Now, the type synonym is following:
type Metadata = Aeson.Object
This is the Object from aeson package – Data.Yaml library shares the types.
Unfortunately, handling the Aeson.Object
is not as straightforward as the Map
was. To learn how to use Aeson properly, you can read a lengthy tutorial.
Luckily, Jasper provided us with a function lookupString which is almost a drop-in replacement of HashMap.!
:
(!) :: Metadata -> String -> String
lookupString :: String -> Metadata -> Maybe String
Unwrapping the Maybe value, you will then get something like the following code:
directorizeDateAndAuthor :: Routes
directorizeDateAndAuthor = metadataRoute $ \md ->
case lookupString "author" md of
Just author ->
gsubRoute "/[0-9]{4}-[0-9]{2}-[0-9]{2}-" $ \s ->
replaceAll "-" (const "/") s ++ author ++ "/"
Nothing -> error "The author metadata field is missing."