Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to intersect two term page collections #12254

Closed
jmooring opened this issue Mar 14, 2024 · 4 comments · Fixed by #12260
Closed

Unable to intersect two term page collections #12254

jmooring opened this issue Mar 14, 2024 · 4 comments · Fixed by #12260

Comments

@jmooring
Copy link
Member

Reference: https://discourse.gohugo.io/t/intersect-2-term-lists-broken-in-0-123-0-onwards/48765/

I'd give this a low priority because (a) the use case is uncommon, and (b) there's a cleaner construct (see this comment) that works fine with v0.123.0 and later.

The test case below fails with v0.123.0 and later.

func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
capitalizeListTitles = false
disableKinds = ['rss','sitemap']
-- content/p1.md --
---
title: p1
categories: [cat-a]
tags: ['tag-b','tag-a','tag-c']
---
-- content/p2.md --
---
title: p2
categories: [cat-a]
tags: ['tag-b','tag-a']
---
-- content/p3.md --
---
title: p3
categories: [cat-a]
tags: ['tag-b']
---
-- layouts/_default/term.html --
{{ $s := slice }}
{{ range site.Taxonomies.tags.ByCount }}
  {{ if intersect $.Pages .Pages }}
    {{ $s = $s | append . }}
  {{ end }}
{{ end }}
{{ $s = uniq $s }}

<ul>
  {{ range $s }}
    <li><a href="{{ .Page.RelPermalink }}">{{ .Page.Title }}</a> ({{ .Count }})</li>
  {{ end }}
</ul>
`
	b := Test(t, files)

	b.AssertFileContent("public/categories/cat-a/index.html",
		`<li><a href="/tags/tag-b/">tag-b</a> (3)</li>`,
		`<li><a href="/tags/tag-a/">tag-a</a> (2)</li>`,
		`<li><a href="/tags/tag-c/">tag-c</a> (1)</li>`,
	)
}
@bep bep removed the NeedsTriage label Mar 14, 2024
@bep bep added this to the v0.123.9 milestone Mar 14, 2024
@bep bep changed the title Unable to intersect two page collections Unable to intersect two term page collections Mar 14, 2024
@bep
Copy link
Member

bep commented Mar 14, 2024

I would be surprised if this was a general "page collections" issue. I see what's happening on the technical side here (we create these terms on demand now so you end up with different objects). This is fixable, of course.

@jmooring
Copy link
Member Author

Yeah, I wasn't quite sure how to zero-in on the description in 15 words or less.

@bep bep self-assigned this Mar 14, 2024
@josineto
Copy link

Thank you, @jmooring and @bep !

Copy link

github-actions bot commented Apr 6, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants