Example of YAML syntax support
Opened this issue · 1 comments
tomhepworth commented
Hi, I am inexperienced with Haskell but using Hakyll as an excuse to try and improve at the language.
Is it possible to parse more complex YAML with nested elements, like this:
---
title: Homepage
values:
- value1: 0
- value2: 5
---
and use them in templates? If so, could anyone provide an example of how to achieve this?
tomhepworth commented
So far I have
valuesCtx :: Context String
valuesCtx = field "values" $ \item -> do
metadata <- getMetadata (itemIdentifier item)
trace (show metadata) $ pure ()
let nestedField = lookupString "values" metadata
return $ fromMaybe "none" nestedField
Trace output:
fromList [("author",String "me"),("published",String "2010-09-06"),("title",String "title"),("values",Array [Object (fromList [("value1",String "aaaaa")]),Object (fromList [("value2",String "bbbbbb")])])]
But obviously this will never work. Is there a way to extract the the array object from the metadata?
I can only see lookupString
with the type signature starting String -> Metadata -> ...