CSV/JSON files as basis for posts

I’ve collected roughly 750+ recipe cards (printed in Germany in the '70). It was called Heidis Koch Klub (Heidi’s cooking club).

With some help from Nanonets for helping with OCR of the text on them, I have collected a lot of JSON files. I want to publish the recipes as a pet project and as a way to liberate a lot of great recipes from paper.

I found this resource on data templates; I can’t seem to get it working. With this step, it gives an error. (it’s below the code). I feel that I am very close to understanding how this works.

I have [these JSON files] with the recipes. My goal is to have a post per recipe and the ability to browser on a tag (dessert, starter, etc). Demo JSON file.

Questions

  • Where do I place the code below? I’ve tried it with single and that resulted in the error below.
  • Any pointers on how to start with publishing posts with recipes are more than welcome!
{{ range $.Site.Data.jazz.bass }}
   {{ partial "artist.html" . }}
{{ end }}
Rebuild failed:

Failed to render pages: render of "page" failed: "/Users/x/Desktop/HKK/HKK/themes/Blonde/layouts/post/single.html:3:6": execute of template failed: template: post/single.html:3:6: executing "post/single.html" at <partial "artist.html" .>: error calling partial: partial "artist.html" not found

Hugo env

hugo v0.89.4+extended darwin/amd64 BuildDate=unknown
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.17.2"

The natural place for the code is at single.html

As per the error message that partial is not found. You need to define it under /layouts/partials/artist.html for the build to succeed.


One more thing.If you want the JSON files published as individual pages then I suggest that you place them under the content folder instead of data.

JSON is an acceptable front matter format for content files in Hugo projects.

But you will need to batch convert them from JSON to MD, since JSON is not an acceptable content file format.

2 Likes

Thanks, this was extremely helpful!

I now can access the information from the example .json file from the data template. See the attached screenshot;

Any pointers on how I can structure the posts so that they will all display a desperate recipe (input JSON or CSV)? I can collect the recipes based on the type (dessert, starter).

Unfortunately Hugo does not currently support generating pages from data files.

The way you described the issue originally it seemed like you had a separate data file for each recipe. That is why above I suggested that you move the files in the content folder and convert them to MD so that you have separate pages.

The only way to generate separate pages would be to split the JSON (or CSV) with a third party script and then perhaps it would be best to move these files (after converting them to MD) in the content directory or perhaps render each recipe with a shortcode.

See this GitHub issue, it contains some user tips about splitting a data file (make sure to expand the hidden comments).

The way you described the issue originally it seemed like you had a separate data file for each recipe. That is why above I suggested that you move the files in the content folder and convert them to MD so that you have separate pages.

That’s still the case, I have the recipes as CSV files, without a lot of effort, I can also translate them to a JSON format.

I’ll look into a bulk action from CSV to Markdown. Thanks for the link to the issue. It’s a massive thread!

There is also another related issue: Pages from data, take 5 · Issue #6310 · gohugoio/hugo · GitHub

Pages from Data is the single most requested feature in Hugo.

Hopefully one day it will be possible, but until then we have to use other tools to achieve it.

1 Like

To bad, I think I need to switch to Jekyll. That has native support for it … to bad.

You can use Eleventy, too :wink:

The pagination feature is your friend: Create Pages From Data—Eleventy, a simpler static site generator.

[Forum is closed but @alexandros and @jmooring continue the thread ?!]

1 Like

Oh this is cool! Let me try if I can get this working :slight_smile:

Good.
However may I remind everyone that this is the Hugo forum.
You can have this discussion elsewhere.
Thank you.

@Ramon Sorry to see you go. Please reach out if you want to try Hugo again. Converting your 750 JSON files to usable content is a trivial exercise.

1 Like