Previously:
- Tag aliases and term canonicalization when applying taxonomies
- Some URL-safe special characters cannot be used in Page path · Issue #12993 · gohugoio/hugo · GitHub
Reproducible build available at GitHub - trwnh/hugo-bug-reproducibles at term-is-empty
term-is-empty
hugo v0.138.0+extended linux/amd64 BuildDate=unknown
data/tags/yugioh.json
{
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"@base": "https://trwnh.com/tags/"
}
],
"id": "yu-gi-oh!",
"name": "Yu-Gi-Oh!",
"summary": "A media franchise including several series mostly revolving around the fictional card game of Duel Monsters.",
"alsoKnownAs": ["yu-gi-oh", "ygo", "yugioh"]
}
content/tags/_content.gotmpl
{{ $data := .Site.Data.tags }}
{{ $ctx := . }}
{{ range $data }}
{{ $id := .id }}
{{ $title := .name }}
{{ $summary := .summary }}
{{ $aliases := .alsoKnownAs }}
{{ $page := dict
"title" $title
"summary" $summary
"params" (dict "tag_aliases" $aliases "tag_name" $id)
"path" .id
"url" (printf "tags/%s" .id)
"kind" "term"
}}
{{ $.AddPage $page }}
{{ range $aliases }}
{{ $page := dict
"params" (dict "tag_canonical" $id "tag_name" .)
"path" .
"url" (printf "tags/%s" .)
"kind" "term"
}}
{{ $.AddPage $page }}
{{ end }}
{{ end }}
layouts/_default/taxonomy.html
{{ define "body" }}
{{/* this fails with "error calling Data: term is empty" */}}
<dl>
{{ range .Data.Terms.ByCount }}
<dt>{{.Name}} -- <a href="{{.Permalink}}">{{.Permalink}}</a></dt>
<dd>used {{.Count}} time(s)</dd>
{{ end }}
</dl>
{{ end }}
I assume that this is because there are no pages in content/
that include at least one of the terms for which I called .AddPage
via a Content Adapter. So for example, if I am defining term aliases such that yu-gi-oh!
is canonical and ["yu-gi-oh", "ygo", "yugioh"]
are aliases, and I am calling .AddPage
a total of 4 times due to this, then the entire build/server fails because Hugo is expecting at least 1 page to be included in each of those 4 terms.
Both .Data
and .Site.Taxonomies
cause this “term is empty” error.
The former is especially problematic because I want to loop over .Data.Terms.ByCount
to sort my tags list on the taxonomy page by most used tags. I am feeling like the answer here might end up being “use Scratch/Store to range over all .Site.Pages/RegularPages
and reimplement the counter/total yourself”, but I am posting this thread just in case there’s an easier option I’m overlooking…