gohugoio / hugoDocs

The source for https://gohugo.io/
Apache License 2.0
1.03k stars 1.47k forks source link

site.Taxonomies returns a page.WeightedPages, not a page.TaxonomyList #2603

Closed willfaught closed 1 month ago

willfaught commented 1 month ago

https://gohugo.io/methods/site/taxonomies/ is confusing. It says it returns a page.TaxonomyList, but if you print the type, it prints page.WeightedPages. This confused me, because then it wasn't clear how to get a page.TaxonomyList. After some fumbling around, I tried using .Page on the page.WeightedPages value, and it worked, so apparently page.WeightedPages is equivalent to page.TaxonomyList somehow?

Input:

    {{ range $id, $pages := site.Taxonomies.authors }}
        {{ printf "%T" $id }}
        {{ printf "%T" $pages }}
        {{ printf "%v" $pages.Page }}

Output:

string page.WeightedPages Page(/authors/willa)

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.126.1+extended darwin/arm64 BuildDate=2024-05-15T10:42:34Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

jmooring commented 1 month ago

With an empty site and Hugo's default configuration:

{{ site.Taxonomies | warnf "%#[1]v (%[1]T)" }}

The console emits:

WARN page.TaxonomyList{"categories":page.Taxonomy{}, "tags":page.Taxonomy{}} (page.TaxonomyList)

So the data type is correct.

willfaught commented 1 month ago

I don't know what I was smoking, printing site.Taxonomies.authors elements instead of site.Taxonomies. Sorry about that.