How does Hugo render tags?
My goal is to prevent Hugo from capitalizing tags during the build process.
Related:
The Hugo layouts that render tags
In a Hugo theme that was created with hugo new <theme-name>, tags for the /tags page are handled
by the /layouts/_partials/taxonomy.html layout, tags that are displayed at the bottom of a post
are handled by the /layouts/_partials/terms.html template.
Both layouts render tags in a link:
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
I’m guessing there’s some sort of modifier (?) function that .LinkTitle could get piped through,
but how do tags get capitalized in the first place?
How tag names get capitalized by Hugo
I’m going to accept Claude’s response here. It seems correct to me.
The key to what’s going on is in the Title part of the LinkTitle field or method (see Go
template basics for details about terms used in Hugo layout actions.)
The Hugo LinkTitle (and Title) methods apply the Hugo title function. The title function
capitalizes the first letter of each word.
How I’m preventing tag names from being capitalized
To prevent tags from being displayed in a capitalized format, I’m adding a pipeline to the action that renders the tags:
taxonomy.html:
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ range .Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle | lower }}</a></h2>
{{ end }}
{{ end }}
The same change has been made to terms.html.
An untested alternate and somewhat more efficient approach would be to use the Name method instead of
LinkTitle. (Edit: I actually tested and went with the Name approach):
taxonomy.html:
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ range .Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .Name }}</a></h2>
{{ end }}
{{ end }}