Capitals and slashes in tags

I’ve got a fairly simple blog with tags and I’m having difficulty getting the links and titles of tags to be what I want.

Links to tag pages

In the front matter of a post I have:

tags = ["website", "CI/CD", "Gitlab"]

And at the bottom of the page I list the tags with:

  {{ range .Params.Tags }}
      <li><a href="/tags/{{ . | urlize }} ">{{ . }}</a></li>
  {{ end }}

the problem is that URL goes to /tags/ci/cd whereas Hugo makes the directory at /tags/ci-cd (result of the change here that replaces slashes in tags with hyphens)
How do I apply the same transform to the link automatically?

Titles

On the terms (list of tags) page and the list (pages matching a single tag) page, I’m not sure how to get the tag “CI/CD” to display correctly.
For a single term page (/tags/ci-cd/), I’ve tried the following options:

{{ .Title }}  = "Ci/Cd"
{{ .Data.Term }} = "ci/cd"

I tried turning preserveTaxonomyNames on and off in config.toml but it doesn’t seem to be making a difference.

How about (untested):

{{ ( replace . "/" "-" )  | urlize }}
1 Like

Use the snippet by @rdwatters to resolve this.


To keep the case of “CI/CD”, add this line to your config.toml:

disablePathToLower = true

Thanks @rdwatters, that works. I thought there might be some built in function for that transformation, but if not, that does the trick!
Replaced it with the following because I couldn’t find the right way to escape the quote characters in the href string:

  {{ range .Params.Tags }}
      {{ $link := (replace . "/" "-") | urlize}}
      <li><a href="/tags/{{ $link }}">{{ . }}</a></li>
  {{ end }}
1 Like

Thanks for the suggestion @zwbetz, actually as it turned out I needed preserveTaxonomyNames but I was putting it into the TOML wrong:

[taxonomies]
    tag = "tags"
preserveTaxonomyNames = true

Once I moved it above the [taxonomies] section, it worked as desired (page titles of taxonomy pages use the uppercase term).

 preserveTaxonomyNames = true
[taxonomies]
    tag = "tags"

Is there a way to mark this thread as solved?

Awesome, I’ve been looking for something that would fix this for me. Thanks!

1 Like

@ronnie Good deal. And yep, just click the checkbox on one of the replies.

1 Like