Currently, Hugo is seemingly picking one at random every time I build my site. I would like to get Hugo to stop doing this, and render both – /content/foo.md is intended to show up at <baseURL>/foo, while /content/foo/index.md is intended to show up at <baseURL>/foo/.
There doesn’t seem to be a way to do this currently. If there is, what is it? If there isn’t, will there ever be?
More details about why I want this, in case this is an x-y-problem:
I have various subdirectories of a site/domain that are each powered by Hugo. The reason why I am doing this is that each subdirectory has vastly different requirements in terms of layout and templating and styling and scripting and so on, to the point that it would be very complicated to combine them all into one Hugo site. Also, some subdirectories are intended to be more or less “hidden” or “unlisted”, so they should not show up in search or in the sitemap. Creating subdomains is not a viable option. Enabling “ugly URLs” and then rewriting them at a web server level is also not viable.
The conflict generally arises with things like having both a “search” page and a “search/” directory. For blog-like sites, a blog post with the slug search will conflict with the search page. For wiki-like sites, an article titled “search” will similarly conflict with the search page. I don’t want to create an arbitrary subdirectory within content and then end up with something like /blog/arbitrary_subfolder/search/ or /wiki/this_is_unnecessary/search/ in my URI structure. At a URI level, search and search/ are different things and ought to be treated differently. It makes sense that /content/search/index.md would be rendered as /search/, but it doesn’t make sense that /content/search.md would suddenly become inaccessible or vice-versa. This problem is multiplied by every single individual root page that shares a name with a slug/title or with a section/kind.
While searching these forums before making this thread, I came across some other threads dealing with “trailing slash” and “ugly urls”, but those aren’t exactly related to what I’m trying to do.
$ hugo new foo.md
$ hugo new foo/index.md
$ hugo --printPathWarnings
WARN Duplicate content path: "/foo" file: "/home/jmooring/code/hugo-testing/content/foo/index.md" file: "/home/jmooring/code/hugo-testing/content/foo.md"
That is correct.
No.
Sure, the strings are different, but whether they are “different things” depends on server configuration.
From a usability standpoint, returning different pages for these URLs seems, at best, questionable:
Typically the lack of trailing slash indicates that something is a resource within the current directory, and the presence of a trailing slash indicates that something is a directory (with an index file). However, Hugo seems to behave in completely unexpected ways regarding this. With uglyURLs = false (the default), we get pages converted into directories. But setting uglyURLs = true does the reverse – it renders the directory index as a page! That is, content/wiki/_index.md does not get rendered as /wiki/index.html, but rather it gets rendered as /wiki.html. I think Hugo is conflating the concept of “prettiness”/“ugliness” with the concept of “directory”/“file”. At the very least, they seem to be weirdly coupled…
In any case, the only way I can see to avoid having content/search.md and content/search/index.md in the same project would be to move the latter into some kind of subdirectory, like content/wiki/search.md for a page, or content/wiki/search/index.md for a page bundle. This produces “pretty URLs” of the form /wiki/wiki/search/ and “ugly URLs” of the form /wiki/wiki/search.html. I suppose I would then have to somehow post-process the output from Hugo to remove the redundant doubling in the path.
So I wouldn’t use it unless you were creating a site that was navigable via the file system (i.e., a serverless site).
Without getting into the merits of your URL patterns or the server configuration required to handle them, have you considered setting the url in front matter?