I’ve been away from Hugo for a while but recently was looking the Hugo live road map #10939 and the following catched my eye:
The “million pages” release.
Pages from other data sources (including relevant plugin support)
What is the status and can more be shared how this will look like?
My use case is I have a database and I want to generate many pages from database records.
Like Movie pages, Actor pages etc.
In the past I used a script to generate these pages but at the end it was not really maintainable unfortunately.
Similar as with Gatbsy/Nextjs I would like to use some getStaticPaths/getStaticProps mechanism that would generate pages from database queries.
One important part is that for performance reasons generating these “dynamic” pages should be on the fly when a page is requested.
A plugin system could maybe help with this and as that is mentioned in the roadmap I want to see if Hugo could be of any interest for some (future) projects I’m working on.
Hugo is a static site generator. So, I doubt this will work (but I stand to be corrected). The current workaround recommended fetches the data when building the site, not on the fly.
With on the fly I mean during development.
Of course when building the static site for deployment it should build all pages directly.
The reason is that I would like to avoid that e.g. changing something in a layout, partial or page, thousands of “dynamic” pages will be generated and querying the database.
This is a really simple “pages from data” example:
git clone --single-branch -b hugo-forum-topic-45433 https://github.com/jmooring/hugo-testing hugo-forum-topic-45433
cd hugo-forum-topic-45433
hugo -s prebuild && hugo server
The first build converts the external data to local markdown files, while the second build builds the site.
Try Joe’s example. I followed the tutorial I shared to generate around 40k pages from external JSON data. Whole thing takes around 10 minutes to build the last time I tried it.
That is a really interesting read and proposes an approach that should be workable for me as well already, without a future Pages from other data sources (including relevant plugin support).
In my case I need to collect the data from a (SQLite) database so I could create e.g. a npm script that queries the data and creates the .md files with json front matter similar as in the article.
That being said, I still wonder what Hugo’s plans are for Pages from other data sources (including relevant plugin support) as described in the roadmap
The Hugo inside Hugo (inception) approach to generate markdown pages using resources.GetRemote is really smart, but it wouldn’t help directly for accessing data from a database.
Of course I could create a script which does something really similar; calling the db and write some .md files. The roadmap also mentioned including relevant plugin support which I wonder what it will mean.
Reason I’m “pushing” is that I would now write a node script to generate these .md pages,
but if I would know later on I could easily integrate a go script/plugin within Hugo, I might go for that approach already.