Hugo generates page on-the-fly but gives a 404 when stopped and restarted

I have the following directory structure:

$ cd content
$ tree
.
├── _index.md
├── about
│   ├── _index.md
│   ├── projects
│   │   ├── icedig
│   │   │   ├── img
│   │   │   │   └── icedig.png
│   │   │   └── index.md
│   │   ├── img
│   │   ├── index.md
│

Hugo generates pages for the following

  • server/about/ → a list of all the “abouts” using layouts/about/list.html
  • server/about/projects/ → a list of all the “projects” using layouts/about/single.html

but fails to generate

  • server/about/projects/icedig/ → single page info about “icedig” project. I get a 404

Now here is where I am getting baffled. If, while hugo server is running, I change icedig/index.md to icedig/_index.md then hugo generates a page on-the-fly for server/about/projects/icedig using layouts/about/list.html. Then, if I stop and restart hugo, I again get a 404. However, now if I change the icedig/_index.md back to icedig/index.md, hugo generates a page on-the-fly for server/about/projects/icedig using layouts/about/single.html. Once again, when I stop and restart hugo, that page is no longer there and I get a 404.

So, what would I like? Well, I’d like to understand Hugo’s behavior so I can do the right thing. And, I would like to be able to get a page at server/about/projects/icedig (and all other entries under projects if they have an index.md)

I found a similar thread Hugo renders page, restart server, returns 404. BUG? but not quite.

Your directory structure should be:

content/
├── about/
│   ├── projects/
│   │   ├── icedig/
│   │   │   ├── img/
│   │   │   │   └── icedig.png
│   │   │   └── index.md       <-- icedig (page bundle)
│   │   └── _index.md          <-- projects (section / branch bundle)
│   └── _index.md              <-- about (section / branch bundle)
└── _index.md                  <-- home page

I already tried what you suggest, but I must be doing something wrong.

For one, if I change projects/index.md to projects/_index.md then an automatic entry for projects is not generated in the about/ listing. All other sections under about do get their own entry.

Of course, I can manually add an for projects to layouts/about/list.html but it is not consistent in appearance with other automatically generated list items. And, it is in the wrong order, appearing at the top of the list (because, obviously, it is not a part of the automatically generated list).

And, in any case, how/where do I store a layout for all the individual projects? Each project entry in its own folder has a different name. I want a standardized layout for all the individual project entries. My current layouts folder looks like so. I am assuming projects/single.html will be used for each project entry

$ cd layouts/about
$ tree
.
├── list.html
├── projects
│   ├── list.html
│   └── single.html

Then compare to this:

git clone --single-branch -b hugo-forum-topic-45378 https://github.com/jmooring/hugo-testing hugo-forum-topic-45378
cd hugo-forum-topic-45378
hugo server

If you need additional assistance, please post a link to the public repository for your project.

See Requesting Help.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Then compare to this

well, that didn’t work. I got the following error

hugo-forum-topic-45378 git:(hugo-forum-topic-45378) hugo server
Start building sites …
hugo v0.111.3+extended darwin/arm64 BuildDate=unknown VendorInfo=macports
ERROR 2023/07/20 21:07:46 render of "section" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/list.html:2:15: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2023/07/20 21:07:46 render of "section" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/list.html:2:15: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2023/07/20 21:07:46 render of "page" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/single.html:2:15: executing "_default/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Error: Error building site: failed to render pages: render of "home" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/home.html:2:15: executing "_default/home.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Built in 4 ms

If you need additional assistance, please post a link to the public repository for your project.

ok thanks, I will make a public version of the repo and come back for help.

I can see you’re running an older version. Current version is v0.115.4.

I can see you’re running an older version. Current version is v0.115.4.

I upgraded and now I can run it successfully. Bloody hell! your example works (and how did you make one up so quickly? I can’t even tie my shoes so fast!).

Ok thanks, I will study your example and see if I can replicate it (and learn what it is that I am doing that is preventing my version to not work).

Many thanks for your (insanely) quick response.