How to make content pages from JSON or DB?

I understand using data files, but that is for templates.

Is there anyway to generate content from JSON or a DB connection at all using Hugo? Does or can Hugo ever will access a DB in order to pull data and build?

Currently I am having to use node.js, php, and mysql and go lang together to generate markdown files with front matter into a /section on my site. It’s a hot mess.

Maybe Hugo extended can have SQL features, embed a library or go module and allow the user to talk to a database connection to fetch data.

Is this for a one-time data conversion? For example, to convert a site from WordPress or Drupal to Hugo?

Hello. Thank you for responding.

Is this for a one-time data conversion? For example, to convert a site from WordPress or Drupal to Hugo?

It is not. I use various API and scraping methods to gather data and store in a database. I then use PHP to grab the data using an ORM and generate my .md file for Hugo and place it in /content/ etc.

It would be nice if I can use SQL within Hugo, talk to my DB, grab the data, and build content files from it.

What I can possibly do for now, is to extract the DB data using PHP or something, and then file_put_contents(json_encode($file)) to /data/drugs/$drugname.json

Then I can create a template partial for drugdata.html for example, and include that partial in my /drugs/single.html template.

Then in the drugdata.html partial, I can grab drug/molecule name from front matter, and for that drug name, grab the $drugname.json file, and pull data/render it.

That is still a terrible long winded solution.

Still, I have to use another language to grab data from the DB.

It would be tremendously helpful if Hugo can talk to a DB.

For security reasons, perhaps we can only allow SELECT statements to be used in Hugo Extended SQL functions/features.

What do you think?

There’s been a lot of discussion about creating pages from data.

In the interim, what you’re doing sounds fairly reasonable. If it were me, and I had everything stored in a MySQL database, I’d use mysqlsh to generate the JSON, then iterate with a bash script to create the markdown files. It sounds like you’re doing essentially the same thing.