Hugo v0.123 seems to anchorize terms in their URLs rather than urlize them

After upgrading to v0.123.x, Hugo seems to be using anchorize rather than urlize when creating urls for term pages.

Given the following categories:

  • Things & Other things
  • Best & Worst of Times
  • Articles & News
  • This & That

Hugo v0.119.0 generates the following relative URLs

  • /categories/articles-news/
  • /categories/best-worst-of-times/
  • /categories/things-other-things/
  • /categories/this-that/

However v0.123.6 generates the following (note the extra double hyphens in place of &):

  • /categories/articles--news/
  • /categories/best--worst-of-times/
  • /categories/things--other-things/
  • /categories/this--that/

Reproduction:

git clone --single-branch -b anchorized-category-urls https://github.com/alanbreck/hugo-testing anchorized-category-urls
cd anchorized-category-urls
rm -rf public && hugo

This is expected/by design (I think).

Ok. This will result in broken URLs. The two options I can think of are:

  1. Accept the change and implement 301 redirects
  2. Add content files for each existing category which specifies a URL.

Is there another option that I’m not thinking of, though?

Either 301 redirects server-side, or generate content pages (as needed) with β€œaliases” in front matter. I guess on some sites it could affect every term, but on most sites it’s probably a subset.

Hang on a second. I misunderstood what was happening here.

This affects more than terms:

content/
└── posts/
    └── The Second & Third Waves.md  <-- front matter: tags: [Concept & Prototypes]

v0.122.0

public/
β”œβ”€β”€ posts/
β”‚   β”œβ”€β”€ the-second-third-waves/
β”‚   β”‚   └── index.html
β”‚   └── index.html
β”œβ”€β”€ tags/
β”‚   β”œβ”€β”€ concept-prototypes/
β”‚   β”‚   └── index.html
β”‚   └── index.html
└── index.html

v0.123.6

public/
β”œβ”€β”€ posts/
β”‚   β”œβ”€β”€ the-second--third-waves/  # URL has changed
β”‚   β”‚   └── index.html
β”‚   └── index.html
β”œβ”€β”€ tags/
β”‚   β”œβ”€β”€ concept--prototypes/      # URL has changed
β”‚   β”‚   └── index.html
β”‚   └── index.html
└── index.html

@bep Please confirm that this (see my previous comment) was an intentional change. It probably doesn’t affect that many URLs in the wild, but redirects are required.

If intentional, one concern I have is that it wasn’t very apparent that this was changed. I didn’t notice until diffing the build folders.

I just raised the same issue here β†’ Special character in URL has new behaviour since 0.123.0 Β· Issue #12241 Β· gohugoio/hugo Β· GitHub
What did you end up doing @AlanBreck ?

I haven’t upgraded yet. I haven’t had time to finish diffing the output folders to find all cases of the above, and other discrepancies.

See https://github.com/gohugoio/hugo/issues/12241#issuecomment-1996883532. This was an intentional breaking change.

Understood. Thanks for following up, @jmooring.

I may just be missing it, but it’s not apparent to me from looking at Preserve triple hyphens etc. in URLs. Β· Issue #10104 Β· gohugoio/hugo Β· GitHub that this behavior would extend to other characters (like &). Could this behavior be documented (maybe on the Content Management/Taxonomies page with examples of which characters result in an extra hyphen, and which do not (e.g. a .)?

Related to the issue of understanding what the precise behavior will be, does it use anchorize or urlize under the hood? At first glance, it appears that it does not since hyphens are added for whitespace, but . is preserved.

Please create an issue in the docs repository. I think this should be about Page.RelPermalink and Page.Permalink… what we’re talking about in this issue is not specific to taxonomy or term pages. The revised documentation should describe the relationship between the content’s file path (or logical path when the content is not backed by a file) and the published URL.

I’ve created https://github.com/gohugoio/hugoDocs/issues/2487.

1 Like

Also note https://github.com/gohugoio/hugoDocs/issues/2307. The concepts referenced/described in the effected pages need to consolidated. It’s a bit of a mess right now, so I’d like to limit the proposed docs change to the Permalink/RelPermalink pages. #2307 is a few days of work, so it’s not going to happen tomorrow.

Thank you so much for creating that issue, and for maintaining the docs, @jmooring!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.