Create multiple pages out of one source file

27 views
Skip to first unread message

Stephan Schiffels

unread,
Jun 30, 2023, 3:40:54 PM6/30/23
to hakyll
Hi.

I have a data file listing data for items. I would like to generate multiple pages from that one source file.

Right now I simply read the source file outside of Hakyll, and then use it from inside the Rules Monad. But I think it would be nicer to have it all inside Hakyll for consistency.

So instead of doing something like

main :: IO ()
main = parseDataFile "data/myData.json" >>= runHakyll

runHakyll :: [(String, MyData)] -> Rules ()
runHakyll listOfData = hakyll $ do
create (map fst data) $ do
-- this will create one page per item in data
...

I would like to do

main = hakyll $ do
match "data/myData.json" $ do
rawStr <- getResourceString
let data = parse ... rawStr
return data

create (map fst data) $ do
-- this won't work because I would have to "load" the data, which is only possible in the Compiler Monad, not in the Rules Monad.

Is there a best practice for something like this? I looked at "makeItem", but that is weird because it associates the newly created items with the one identifier used in the Rules. As far as I can see, I cannot create new identifiers once I am in the Compiler.

So there is the following dilemma:
- loading compiled data is only possible within Compiler, not Rules
- Creating new identifiers is only possible within Rules, not Compiler.

Any help would be appreciated.
Thanks, Stephan

Reply all
Reply to author
Forward
0 new messages