hakyll
hakyll copied to clipboard
How to pass a list of something to template context?
Hello. I am a haskell beginner.
I am trying to create a simple website with hakyll where menus could be declared in JSON files.
As I see here https://github.com/jaspervdj/hakyll/blob/67ecff7ad383640bc73d64edc2506c7cc648a134/lib/Hakyll/Web/Template/Context.hs#L119 the listField function is working with Compiler [Item a], but what I have in my program is:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UnicodeSyntax #-}
import Data.Aeson
import Data.ByteString.Lazy as B
-- ...
data Menu =
Menu { title ∷ String
, image ∷ String
, url ∷ String
} deriving (Show, Generic)
instance FromJSON Menu
instance ToJSON Menu
getMenu ∷ String → IO (Maybe [Menu])
getMenu name = decode <$> B.readFile (name :: FilePath)
At this point I am lost.
- How to pass
[Menu]into the template context correctly? - Why do I need this
Compiler ...type to just pass a list data structure into the template context?
Thank you.
I'm trying to do something similar where I reference a file in the post metadata, then parse it and add it to the Context.
Here's where I've got so far: https://gist.github.com/tcyrus/59bc597395536d1095ccaa6794209cb2