What version of Hugo are you using (hugo version)?
% hugo version
hugo v0.119.0-b84644c008e0dc2c4b67bd69cccf87a41a03937e linux/amd64 BuildDate=2023-09-24T15:20:17Z VendorInfo=gohugoio
Does this issue reproduce with the latest release?
Yes. I the recreation steps with hugo v0.121.2-6d5b44305eaa9d0a157946492a6f319da38de154 linux/amd64 BuildDate=2024-01-05T12:21:15Z VendorInfo=gohugoio. The same misbehavior happens.
I checked specifically:
New Hugo regenerating the static content from the existing Hugo workspace.
Creating a new theme in the new Hugo and using that with the static content generation.
The problem happens in both cases.
Recreation Steps
% hugo new site quickstart
% cd quickstart
% hugo new theme theme
% echo "theme = 'theme'" >> hugo.toml
% echo "uglyURLs = true" >> hugo.toml
% hugo
% less public/index.html
Within step no. 7, verify what the menu link for Home points to. The link will have href="/", which is incorrect per having ugly URLs enabled.
What I Expect to Happen
The default template output from hugo new theme should emit output such that step no. 7 from above shows a href="/index.html" for the Home menu item instead of href="/".
Diagnosis
I am uncertain whether this is a problem with the Hugo new theme generator or the internals of Hugo itself. I suspect it is not the theme generator given that file themes/theme/hugo.toml contains:
baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'
[[menus.main]]
name = 'Home'
pageRef = '/'
weight = 10
[[menus.main]]
name = 'Posts'
pageRef = '/posts'
weight = 20
[[menus.main]]
name = 'Tags'
pageRef = '/tags'
weight = 30
[module]
[module.hugoVersion]
extended = false
min = "0.116.0"
It seems that pageRef should canonicalize to /index.html with ugly URLs enabled.
When running the Hugo development server locally, everything appears to work, as the server remaps / back to /index.html. If someone is using pure static content serving without URL rewriting (cf. Apache mod_dir with the DirectoryIndex directive), then the emitted URL is incorrect. I am in that boat.
Workaround
I found I could work around adjusting the menus.main directive in file themes/theme/hugo.toml to the following:
[[menus.main]]
name = 'Home'
url = "//index.html"
weight = 10
That doesn't seem super scalable/reliable, though.
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
Yes. I the recreation steps with
hugo v0.121.2-6d5b44305eaa9d0a157946492a6f319da38de154 linux/amd64 BuildDate=2024-01-05T12:21:15Z VendorInfo=gohugoio
. The same misbehavior happens.I checked specifically:
The problem happens in both cases.
Recreation Steps
% hugo new site quickstart
% cd quickstart
% hugo new theme theme
% echo "theme = 'theme'" >> hugo.toml
% echo "uglyURLs = true" >> hugo.toml
% hugo
% less public/index.html
Within step no. 7, verify what the menu link for
Home
points to. The link will havehref="/"
, which is incorrect per having ugly URLs enabled.What I Expect to Happen
The default template output from
hugo new theme
should emit output such that step no. 7 from above shows ahref="/index.html"
for theHome
menu item instead ofhref="/"
.Diagnosis
I am uncertain whether this is a problem with the Hugo new theme generator or the internals of Hugo itself. I suspect it is not the theme generator given that file
themes/theme/hugo.toml
contains:It seems that
pageRef
should canonicalize to/index.html
with ugly URLs enabled.When running the Hugo development server locally, everything appears to work, as the server remaps
/
back to/index.html
. If someone is using pure static content serving without URL rewriting (cf. Apachemod_dir
with theDirectoryIndex
directive), then the emitted URL is incorrect. I am in that boat.Workaround
I found I could work around adjusting the
menus.main
directive in filethemes/theme/hugo.toml
to the following:That doesn't seem super scalable/reliable, though.