I currently get a list of taxonomy pages like this:
{{ range $name, $taxonomy := site.Taxonomies }}
{{ $collections = $collections | append $taxonomy.Page }}
{{ end }}
However, I can’t do $collections.ByWeight, because the type is []interface{}, not PageList. I don’t see a way to get a PageList for taxonomy pages. Is there a way to do that? Is there a way to take any []interface{} and convert it to a PageList to use its group-by functionality?
git clone --single-branch -b hugo-forum-topic-50202 https://github.com/jmooring/hugo-testing hugo-forum-topic-50202
cd hugo-forum-topic-50202
hugo server
hugo new site foo
cd foo
hugo new yourpost.md
hugo mod init github.com/carpikes/yourproject
hugo mod get github.com/willfaught/paige@v0.80.2
cat >>hugo.toml <<EOF
[[module.imports]]
path = "github.com/willfaught/paige"
EOF
hugo server -D
Output:
# ...snip...
Start building sites …
hugo v0.127.0+extended darwin/arm64 BuildDate=2024-06-05T10:27:59Z VendorInfo=brew
Built in 164 ms
Error: error building site: render: failed to render pages: render of "home" failed: "/Users/will/Library/Caches/hugo_cache/modules/filecache/modules/pkg/mod/github.com/willfaught/paige@v0.80.2/layouts/_default/list.html:5:3": execute of template failed: template: _default/list.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/will/Library/Caches/hugo_cache/modules/filecache/modules/pkg/mod/github.com/willfaught/paige@v0.80.2/layouts/partials/paige/pages.html:44:17": execute of template failed: template: partials/paige/pages.html:44:17: executing "partials/paige/pages.html" at <.ByWeight>: can't evaluate field ByWeight in type []interface {}
The post above is meant to show you that the code is the same.
The actual problem is that for a new site that has the default category and tag taxonomies left enabled, with a single default post that has no categories or tags defined in its front matter, the code $taxonomy.Page in the loop above returns nil, even though $name is “category” and “tag”. $taxonomy is page.Taxonomy{} for both. So the error can't evaluate field ByTitle in type []interface {} is wrong, because the issue isn’t the type []interface{}, it’s the fact that the slice elements are interface{}(nil), which it can’t call .Weight on.