hof
hof copied to clipboard
How to iterate calls to hof and pass in json data
Hello Can you tell me if the following is possible, if and if so, what is needed to achieve this:
I have a json fie - an array of ojbects - and I'd like to use this to call hof
where each json object is used as the input data, which is then used when manifesting generated code.
From reading the documentation it seems that data - and schema - is in the .cue files. Do I need to convert the json to cue?
All JSON is valid CUE, so you should be able to do this. You can even have a bit more control over how it is used and referenced. There are probably slight differences in how data files work. For JSON you might even get away with just renaming them to .cue
Is it just the input data, or also the schemas and generators, which would be in JSON?
To iterate, call hof once and use CUE's looping / comprehension features to define a generator for each sub object you wish. You can probably have a single generator and use the repeated template pattern https://docs.hofstadter.io/first-example/simple-server/generator/#server-generator
I think this should all work, so if it doesn't, let me know
Just input data.
And the goal is to generate several .md
files, and prepopulate the frontmatter. But then to be able to update the marketdown indepentant of the code generation workflow.
Will I be able to re-run, and update these .md
files, and update the frontmatter without losing edits to the content?
Ah, yes, you should definitely be able to do that. I updated my previous comment about repeated templates. I will think on this a bit more to see if there is a good way to handle arbitrary nested markdown content with globs or something. There seems to be a general pastern here
Thanks, much appreciated
@magick93 I've got a one-liner for you now
hof render data.json -T "template.md;[]content/{{ .filepath }}.md"
This is the repeated template pattern, denoted by the ;[]<filepath>
portion of the -T
/--template
flag
Links to the new command's docs
- https://docs.hofstadter.io/getting-started/test-drive/file-rendering/
- https://docs.hofstadter.io/getting-started/test-drive/type-rendering/
- https://docs.hofstadter.io/hof-render/
Please reopen if you have any more questions or uncertainties
@verdverm you have been very helpful with your support. And you've developed a very powerful tool!
Thank you!