Fix taxonomy term with backing file regression

Fixes #12020
This commit is contained in:
Bjørn Erik Pedersen 2024-02-09 15:18:13 +02:00
parent f4575e5f29
commit caba6ba6e7
3 changed files with 47 additions and 1 deletions

View file

@ -1511,6 +1511,8 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
} }
pages.InsertIntoValuesDimension(pi.Base(), n) pages.InsertIntoValuesDimension(pi.Base(), n)
term = pages.Get(pi.Base()) term = pages.Get(pi.Base())
} else if term.(*pageState).m.term != v {
term.(*pageState).m.term = v
} }
if s == "" { if s == "" {
@ -1882,11 +1884,15 @@ func (m *pageMap) CreateSiteTaxonomies(ctx context.Context) error {
if taxonomy == nil { if taxonomy == nil {
return true, fmt.Errorf("missing taxonomy: %s", viewName.plural) return true, fmt.Errorf("missing taxonomy: %s", viewName.plural)
} }
if p.m.term == "" {
panic("term is empty")
}
k := strings.ToLower(p.m.term) k := strings.ToLower(p.m.term)
err := m.treeTaxonomyEntries.WalkPrefix( err := m.treeTaxonomyEntries.WalkPrefix(
doctree.LockTypeRead, doctree.LockTypeRead,
paths.AddTrailingSlash(s), paths.AddTrailingSlash(s),
func(s string, wn *weightedContentNode) (bool, error) { func(ss string, wn *weightedContentNode) (bool, error) {
taxonomy[k] = append(taxonomy[k], page.NewWeightedPage(wn.weight, wn.n.(page.Page), wn.term.Page())) taxonomy[k] = append(taxonomy[k], page.NewWeightedPage(wn.weight, wn.n.(page.Page), wn.term.Page()))
return false, nil return false, nil
}, },

View file

@ -148,6 +148,7 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
m.pageConfig.Kind = kinds.KindTaxonomy m.pageConfig.Kind = kinds.KindTaxonomy
} else { } else {
m.pageConfig.Kind = kinds.KindTerm m.pageConfig.Kind = kinds.KindTerm
m.term = m.pathInfo.Unnormalized().BaseNameNoIdentifier()
} }
} }
} else if m.f != nil { } else if m.f != nil {

View file

@ -776,3 +776,42 @@ Len Book Authors: {{ len (index .Site.Taxonomies $taxonomy) }}
b.AssertFileContent("public/index.html", "Len Book Authors: 2") b.AssertFileContent("public/index.html", "Len Book Authors: 2")
} }
func TestTaxonomiesListTermsHome(t *testing.T) {
files := `
-- hugo.toml --
baseURL = "https://example.com"
[taxonomies]
tag = "tags"
-- content/_index.md --
---
title: "Home"
tags: ["a", "b", "c", "hello world"]
---
-- content/tags/a/_index.md --
---
title: "A"
---
-- content/tags/b/_index.md --
---
title: "B"
---
-- content/tags/c/_index.md --
---
title: "C"
---
-- content/tags/d/_index.md --
---
title: "D"
---
-- content/tags/hello-world/_index.md --
---
title: "Hello World!"
---
-- layouts/home.html --
Terms: {{ range site.Taxonomies.tags }}{{ .Page.Title }}: {{ .Count }}|{{ end }}$
`
b := Test(t, files)
b.AssertFileContent("public/index.html", "Terms: A: 1|B: 1|C: 1|Hello World!: 1|$")
}