I’ve been successfully using Hugo on dozens of websites for several years, and just hit a weird bug that I can’t seem to fix or find a working solution for elsewhere.
In my config.yml file, my permalinks look like this…
But I also have an automated deploy from GitHub. When I push new code, my server pulls the latest commit, runs hugo, and copies the build files to production.
For whatever reason, on the server only, Hugo ignores the top-level directory under the courses Type. Instead of building to /courses/course-title/page-1/index.html, it builds to /courses/page-1/index.html.
I just added the courses type this week, but have been building the books Type like this successfully for years.
Both types use similar templates. Both my local machine and the server are running the same exact version of Hugo. Any idea what could be causing this, or where to start looking to debug it?
That’s fine, one of the benefits of having one static binary.
To your problem, I don’t see any good reason why it should behave this way. I suspect the devil lives in some detail here, which is hard without seeing the full picture. I was a little curious and quickly tested a similar setup on my MacBook, and it works as expected running hugo server with version 0.54.
Check your _index.md files. My theory is that you are running hugo server -D locally, and that draft is true is one of the _index.md files.
If you use a recent version of Hugo, if the _index.md file is draft, we don’t render any of the descendants. Not sure when that was changed, but quite some time ago.
I’m actually not running hugo server at all for this one, just hugo for a raw build. I’ve got some custom PHP files being generated by Hugo, so I’m loading up a PHP server instead.
I did check for draft files first as I saw that mentioned in another answer somewhere. Thanks for giving this more thought, though!
I removed my custom permalink configuration, and now the files render with the proper directory structure, BUT… at one point in my template I range over the courses, and on my server only, that .Type isn’t recognized.
On my local machine, it loops fine. On the server, I get back an empty Map.
Any thoughts on what could be causing that discrepancy? Any configuration or setting I should be looking at?
Locally… where .Site.Pages "Type" "courses" gives me 128 pages. So, as you say, this is on the server side.
I looked at the blame history on deploy.sh, and for a while you were pushing to main instead of master. Any chance the mechanism on your server is looking for main? Or a wrong branch there?