I discovered the following problem:
In my front matter I define a URL, let’s say:
url: my--test
What I would expect from to be the output of this would be a file called “my–test.html”.
Surprisingly the output is: "my**-**test.html.
Two dashes get turned into one, which is not what I would expect and need.
How I can prevent this from happening?
I run Hugo at version:
Hugo Static Site Generator v0.54.0/extended windows/amd64
and configured it to use
I tried to work around this by naming the content file my--test.md and then setting config file permalinks to /:filename/ but it still reduces it to one dash.
This is how Hugo normalizes file paths and it has been like this since Hugo 0.05 or something, i.e. always. @spf13 may tell us why, but I like how it behaves and I believe this is the first time I have seen someone raise this as an issue.
We cannot change the default behaviour. We may add a config option or something, but for me to consider that there have to be more than a handful people wanting it.
thanks for your reply.
For me it is strange that we only encounter this “problem” now, when try building our content with Hugo 0.5x.x, especially when you say, that the normalization behaviour hasn’t changed since 0.05.
We are currently running a project using https://github.com/gohugoio/hugo/releases/download/v0.37.1/hugo_0.37.1_Linux-64bit.tar.gz
and with this version we can create pages with two dashes in the url.
I can even give you a real world example where it is working for us with version 0.37.1 but not with 0.5x.x: we have content where in the frontmatter we define: url: zeeland/nieuw--en-sint-joosland/ name: 'Nieuw- en Sint Joosland' (we get two dashes in the url because we escape whitespaces with dashes)
When we render that page the resulting output is (as we expect): https://www.autoscout24.nl/auto/tweedehands-auto/zeeland/nieuw--en-sint-joosland/ (as you can see two dashes).
So for us it would be great if we could somehow configure Hugo to keep the two dashes.
I take all of this from memory, which isn’t always perfect. But I notice there is a GitHub issue to remind us about it. I vaguely remember we changed the “dash behaviour” at some point, probably to avoid many repeating dashes.
I also would like to be able to use URLs that contain --. For example, I wanted to use the URL https://www.ii.com/hugo--help/ but since that got changed by Hugo to https://www.ii.com/hugo-help/, I’m using the URL https://www.ii.com/hugo-cli/ instead. The good news is that an alias with -- is not munged so the first and third links in this message should work. In case you’re interested, here is part of the YAML front matter of my hugo-cli article:
aliases:
- /hugo-h/
- /hugo--help/
(I originally used the URL hugo-h but changed it because I decided that wasn’t very SE Optimized.)