Taxonomy term slugs via content adapters

I’m running into some issues setting slug on taxonomy terms used in content adapter pages.

As simple example, I generate a page with a term charlie delta in /content/lyrics/_content.gotmpl

{{ $page := dict
  "content" (dict "mediaType" "text/markdown" "value" "alfa")
  "title" "bravo"
  "params" (dict "collection" "charlie delta")
  "kind" "page"
  "path" (print "echo")
}}

{{ $.AddPage $page }}

Then I generate the corresponding term page in /content/collection/_content.gotmpl

{{ $page := dict
  "content" (dict "mediaType" "text/markdown" "value" "foxtrot")
  "title" "charlie delta"
  "params" (dict "slug" "golf")
  "kind" "term"
  "slug" "golf"
  "path" (print "charlie-delta")
}}

{{ $.AddPage $page }}

While writing this example, I understood that the term’s custom slug will be used when the path matches the generated one – in my case, golf as desired.

Changing charlie delta to my problem string Paulo César Pinheiro - Capoeira de Besouro, the final slug becomes paulo-césar-pinheiro-capoeira-de-besouro or paulo-c%C3%A9sar-pinheiro-capoeira-de-besouro, and when I use one of those for charlie-delta, it doesn’t override with golf.

Any tips would be appreciated.


Some related topics I read were:

Notes as we track this down…

Reproducer

git clone --single-branch -b hugo-forum-topic-55679 https://github.com/jmooring/hugo-testing hugo-forum-topic-55679
cd hugo-forum-topic-55679
hugo && tree public

Question

Although not a factor here, I don’t understand why you’re doing this:

"slug" "golf"
"params" (dict "slug" "golf")

Figured it out.

When I loop through the collections and dump the page:

{{ range $.Site.Taxonomies.collection }}
	{{ debug.Dump .Page }}
{{ end}}

it prints the Path as

"Path": "/collection/paulo-césar-pinheiro---capoeira-de-besouro",

For some reason those three consecutive hyphens were not on the URLs earlier…

If I use paulo-césar-pinheiro---capoeira-de-besouro as my term path on the content adapter, it works, and I can even change the title of the term.

I forgot where to put the slug so I did it twice. "params" (dict "slug" "golf") should be removed.

I don’t understand how this relates to the original problem, where slug has no effect. Use url instead.

And in relation to the original problem, I forgot that the slug front matter field is not applicable to sections:

https://gohugo.io/content-management/front-matter/#slug

And we need to update the docs to explicity state that it is not applicable to taxonomy, term, or section page kinds. (done; see 57fd362).

Perhaps I misunderstood, but I thought url is when you want to rewrite the entire path, whereas I really just want to rewrite the slug.

I’m happy to explain but not sure what exactly is relevant to your question. Maybe I can recap a bit:

  • I was having trouble setting the term slug on one of my content adapter pages. (If it’s helpful, the reason I want to change the slug is the generated one includes the accent/diacritic in césar and as a principle I try to avoid that in URLs. Plus I wanted to use a short nickname.)
  • I understand one needs to set the slug by adding front matter to the term page – in my case, /content/collection/…/_index.md or something
  • It seemed to work with my contrived example without diacritics, so I didn’t understand why the diacritic one didn’t work.
  • Then I discovered there is a .Page.Path that shows what path I need to use when calling AddPage.

Now that all seemed to solve my issue but you say that slug shouldn’t apply to term pages?

Or to be more precise…

https://gohugo.io/content-management/urls/#slug

Set the slug in front matter to override the last segment of the path. This front matter field is not applicable to home, section, taxonomy, or term pages.