Doing an intersect
in a term list page, between that term’s list of pages and another taxonomy’s list pages, is broken since version 0.123.0. The code below, when at layouts/term/list.html
, works in version 0.122.0 but doesn’t in version 0.123.x.
(In a category, for example, what it does is showing all tags that are used in the pages with that category.)
{{/* in layouts/term/list.html */}}
{{- $taxo := "tags" -}}
{{- $taxoList := index .Site.Taxonomies $taxo -}}
{{- $termList := .Data.Pages -}}
{{- $taxoByTerm := slice -}}
{{- range $taxoList.ByCount -}}
{{- if intersect $termList .Pages -}} {{/* before 0.123.0 works, in 0.123.x this intersect always returns an empty list */}}
{{- $taxoByTerm = $taxoByTerm | append . -}}
{{- end -}}
{{- if eq (index .Pages 0) (index $termList 0) -}} {{/* this block is just for testing */}}
{{ warnf "eq: true but intersect:%t\t%s\t%s" (intersect $termList .Pages)
(index .Pages 0)
(index $termList 0) }}
{{- end -}}
{{- end -}}
{{- $taxoByTerm = uniq $taxoByTerm -}}
<ul>
{{- range $index, $term := $taxoByTerm -}}
<li><a href="{{ $term.Page.RelPermalink }}">{{ $term.Page.Title }}</a></li>
{{- end -}}
</ul>
How to reproduce
- generate a new site (
hugo new site test-site
) with a skeleton new theme (hugo new theme test
), and puttheme = "test"
inhugo.toml
- in the theme folder, open the three posts and add two different categories (like,
article
andpost
) - in
themes/layouts
, createterm/list.html
and copy content from_default/list.html
- before closing the
define "main"
, put the code above - run
hugo server
, navigate tolocalhost:1313/categories
and then to one of the categories - the list of tags used in that category will not appear, because it’s empty
- Hugo will have logged something like
eq: true but intersect:[] Page(/posts/post-3) Page(/posts/post-3)