How to get tags in original case?

I have tags in my frontmatter, of which I use for i18n, those are in camel case, while I use others without any translations, some of them are capitalized, because they are abbreviations. Example:

tags:
    - digitalImages
    - Photoshop
    - HDR

That is: “digitalImages” (with capital “I”), to be passed to i18n, “Photoshop” and “HDR” should end up in their given case in the output.

How do I get the with the casing preserved using a function like .Site.Taxonomies.tags.ByCount?

I know I can do .Term, this mangles the case, .Page.Title, changes everything to title case, which respects subsequent capitalization, but not camel case, in the example above “Photoshop” and “HDR” work, but “digitalImages” is mangled to “DigitalImages” (with a capital “D”))

Setting preserveTaxonomyNames = true doesn’t help either. Can this be changed without editing every tag and language mapping?

By default, taxonomy names are normalized.

If preserveTaxonomyNames = true doesn’t help possibly some part of your layout/theme is changing it.

Like here to lower letters.

{{ with .GetTerms "tags" }}
        {{ range . }}
            <strong>#</strong><a class="article-tag" href="{{ .RelPermalink }}">{{ .LinkTitle | lower }}</a>
        {{ end }}
{{ end }}

Same with counting,

      {{ range .Site.Taxonomies.tags.ByCount }}
        <strong>#</strong><a href="{{ .Page.RelPermalink }}">{{ .Page.Title | lower }}</a>  <sup>{{ .Count }} </sup>
      {{ end }}

Check your layout/theme.

Well, sure I can just rename my tags to match the capitalisation rules of Hugo but a clean would be to have a method to just access the given string…
Sometimes there is jus to much magic in Hugo…

You misread things. Nobody asking you to rewrite your tags. Please re read what I wrote. It’s likely that your layout/theme preventing from working as you specifying in config.

No, its’ not likely at all, since I wrote about Hugo functions / methods, like .Term and .Page.Title.

As I wrote, I’m in the context of .Site.Taxonomies.tags.ByCount, actually this is happening while rangeing over the returned slice - but this was only implied.

To my knowledge it’s not possible for themes to overwrite internal Hugo functions (that aren’t templates themselves).

We might get a faster and appropriate result if you could prepare a small showcase repo visualizing the problem.

So one can check and test if there’s a solution

The preserveTaxonomyNames configuration option was removed 5 years ago in v0.55.0.

Do this in your site configuration:

capitalizeListTitles = false

Then you can do something like this to list a page’s tags:

{{ with .GetTerms "tags" }}
  <p>Tags:
    {{ range . }}
      <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
    {{ end }}
  </p>
{{ end }}

Or something like this to list all tags:

<ul>
  {{ range site.Taxonomies.tags.ByCount }}
    <li><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a></li>
  {{ end }}
</ul>
2 Likes

On an unrelated but related note, is there a spot in the docs or source code that let you discover that .Page.LinkTitle is available on site.Taxonomies.tags? I tried using things like .LinkTitle in the past but it errors out saying it’s not available.

The overall pattern I’m trying to discover is to figure out where to go to see what’s available for any resource type. In other languages you could dump all objects of a resource.