ANN: Hakyll 4.8

148 views
Skip to first unread message

Jasper Van der Jeugt

unread,
Apr 19, 2016, 1:47:47 PM4/19/16
to hakyll
Hi all,

I've just released Hakyll-4.8. The main change is that we now use the
yaml package to parse page metadata. This was a frequently requested
feature and it will allow for having more structure in your metadata.

The metadata type changed from:

type Metadata = Map String String

To:

type Metadata = Aeson.Object

Most configurations do not rely on the internals of this object, so
this should not pose a big problem.

What can happen is that your metadata contains invalid YAML, e.g.:

---
title: My first blogpost: Hello world
---

The ':' character is invalid, and you would have to change this to:

---
title: 'My first blogpost: Hello world'
---

Hakyll will generate a nice error message if you have this problem
anywhere in your posts, so this should be easy to fix.

Let me know if you run into any trouble.

Peace,
Jasper
Message has been deleted

Sergey Bushnyak

unread,
May 25, 2016, 2:59:13 PM5/25/16
to hakyll
Just switched to the 4.8 and needed to apply changes. I'm using Metadata heavily to manipulate different parts based of page based on meta, some parts of it considered optional. 
For those who will also need changes, here is an example code. 

```
titleCtx :: Context a
titleCtx =
  field "ptitle" $ \item ->
    do
      metadata <- getMetadata $ itemIdentifier item
      let title =
            case Map.lookup "title" metadata of
              Just value -> "Sigrlami - " ++ value
              Nothing    -> "Sigrlami" 
      return title
```
will change to

```
import              Data.Aeson.Types
import qualified Data.HashMap.Strict as HM

titleCtx :: Context a
titleCtx =
  field "ptitle" $ \item ->
    do
      metadata <- getMetadata $ itemIdentifier item
      let title =
              case HM.lookup "title" metadata of
                Nothing    -> ""
                Just value ->   -- this is not actual value, case it again
                  case value of
                    String x -> "Sigrlami - " ++ T.unpack x 
                    _          -> "Sigrlami"
      return title
```
and you'll need to add `aeson` and `unordered-containers` to your cabal dependencies.

Hope this will help someone.

k...@eunchan.net

unread,
Sep 20, 2016, 10:34:40 PM9/20/16
to hakyll
Hi,

What I did was to use 'lookupString' function inside Hakyll.Core.Metadata 

Here's excerpt from the code:

-- | Filter Public for match funciton
-- Usage : matchMetadata "pattern/**" postIsPublic
metadataFieldIs
:: String -> String -> Metadata -> Bool
metadataFieldIs key value metadata
=
   
case lookupString key metadata of
       
Just v  -> value == v
       
Nothing -> False


Regards,
Eunchan
Reply all
Reply to author
Forward
0 new messages