Hugo to fetch data on build

Hello, when I run the hugo command is there a way to create a SITE.Data structure based on a URL? Can Hugo fetch data early in the build step then use that to build? I want to create an entire section of content populated with data from an API. I am searching the docs and forums but have not yet found a resource that describes this type of functionality. Thank you.

There is an in-progress effort to enable this capability, and I suspect it will be available in a few months, if not weeks. This was made possible by a number of the structural changes that were made in v0.123.0.

In the interim, there are a couple of approaches you can use, one of which (prebuild) is described/exemplified here:

The other approach is to use resources.FromString and publish each file. This has several limitations, so the prebuild approach is preferable.


This is great for resources used within a layout but how will you create multiple pages with that?

Thank you. Yeah I remember reacting to some posts on Twitter I think last summer about this topic. I feel it is a real game changer, for me at least.

Regis’ solution with a “nested” Hugo project is quite amazing and saved me lots of time. :pray: Properly integrating pages generated from data into Hugo would be great, because running two instances of Hugo during development is very error-prone. :sweat_smile:

Wow, that’s a great idea. I think I will wait on this one for an official solution.

bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024 (last week)

The milestones are not terribly meaningful. They are automatically pushed forward each time there’s a new release. If I were you I’d subscribe to this issue:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.