I’ve been fighting this for hours now so I guess I’ll post and ask for some help.
I have a few sections in my site, with index pages. Let’s call them /content/cats/_index.md and /content/dogs/_index.md. What I expect is for /cats/index.html and /dogs/index.html pages to be created. But they aren’t being made.
I’ve searched and read and nothing seems to help. I have a custom theme with /layouts/_default/single.html which I then copied around to /layouts/_default/index.html, /layouts/index.html, /layouts/_default/list.html, /layouts/_default/section.html, /layouts/_default/cats.html, /layouts/cats/list.html. It doesn’t matter what names I try, I still don’t get the pages.
One thing I saw is that the template must have {{ .Content }} somewhere in it. But my template does. So that’s not it either.
Any ideas?
I would say you need /content/dogs.html
and /content/cats.html
.
Looks like you are arbitrarily copying files around. It would help to first understand how the layout files precedence works:
I’d suggest removing (When I say removing, I am assuming you keep a backup of all those files somewhere else) all the extra layout files you added and starting from the minimal:
SITE/themes/your-theme/layouts/index.html
(layout for your site home page)
SITE/themes/your-theme/layouts/_default/single.html
(layout for your posts)
SITE/themes/your-theme/layouts/_default/list.html
(layout for your section pages)
Make sure you also remove the SITE/layouts
directory.
If it still does not work, you’ll have to share your site source.
I think he has the content files right based on what he’s saying; just that probably the correct layout files are not present, in the right lookup order.
1 Like
I wasn’t just randomly copying files around. I had read that lookup order page, and that’s exactly why I created those files. It says that /layouts/_default/list.html should work, meaning I can use the same template file for my home _index.md page and my section _index.md pages - yet it doesn’t work for the section ones. So I then copied it to the next thing, but it still doesn’t work. Renamed it to the next thing, still doesn’t work. Renamed it to the next thing, still doesn’t work. Renamed it to the next thing, still doesn’t work. I just don’t get it.
Can you please share the source code of your site in a repository so that we can see what’s going on?
Okay, I have an update, but now I’m even more confused. I was putting together a smaller example to upload, but it turns out the files ARE being created. Just not where I expect them to.
As pkollitsch said (or at least I think that’s what was being said), Hugo is generating /public/cats.html and /public/dogs.html instead of the expected /public/cats/index.html and /public/dogs/index.html.
I didn’t notice this because this location seems completely random and I was looking inside my /public/cats/ and /public/dogs/ directory and wondering where the output is.
It seems like this is related to the setting uglyURLs = true
. If I change it to uglyURLs = false
, Hugo creates the /public/cats/index.html and /public/dogs/index.html files as expected. However, all my other files are then wrong.
Could somebody explain this to me? I want to use uglyURLs = true
. I don’t want folders all over the place. I just want normal files for each page, with URL rewriting on the web server to create pretty URLs instead. But I expect _index.md to map to index.html in the same section/folder. I don’t expect it to be renamed to sectionname.html and put in the root directory. That makes no sense to me.
Is there some documentation for this that I missed somewhere? Is there a flag I can set somewhere to generate the output files I expect (perhaps in the page’s front matter)? Or am I going to have to set up a custom post-build task to move and rename the files?
Thanks.
I looked at this documentation page: https://gohugo.io/content-management/urls/#ugly-urls
The example shows that /content/about/_index.md should generate https://example.com/about/index.html regardless of whether uglyURLs is on or not.
But this isn’t the behavior I’m getting. So either the documentation is wrong or Hugo is bugged.
As a workaround, I’ve tried setting url = "cats/index.html"
in the front matter of /content/cats/_index.md
. When I do this, Hugo does generate a /public/cats/index.html
file. However, the content is just some XML. Hugo still generates the /public/cats.html
junk clutter file, although that has the correct HTML content.
Why does url = "cats/index.html"
generate XML instead of HTML? Does it use a different template file for some reason?