Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of YAML syntax support #1018

Open
tomhepworth opened this issue Feb 12, 2024 · 1 comment
Open

Example of YAML syntax support #1018

tomhepworth opened this issue Feb 12, 2024 · 1 comment

Comments

@tomhepworth
Copy link

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
Copy link
Author

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 -> ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant