]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix site.Taxonomies for taxonomies with space in name
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 6 Feb 2024 15:24:45 +0000 (16:24 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 6 Feb 2024 17:17:30 +0000 (18:17 +0100)
Fixes #12001

hugolib/content_map_page.go
hugolib/taxonomy_test.go

index 570e45bd4ae0d2bfc554767ee3cf2df729228492..75863acbd8a9f0d05f759eda92d50d603c755976 100644 (file)
@@ -1859,13 +1859,12 @@ func (m *pageMap) CreateSiteTaxonomies(ctx context.Context) error {
                        LockType: doctree.LockTypeRead,
                        Handle: func(s string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
                                p := n.(*pageState)
-                               plural := p.Section()
 
                                switch p.Kind() {
                                case kinds.KindTerm:
-                                       taxonomy := m.s.taxonomies[plural]
+                                       taxonomy := m.s.taxonomies[viewName.plural]
                                        if taxonomy == nil {
-                                               return true, fmt.Errorf("missing taxonomy: %s", plural)
+                                               return true, fmt.Errorf("missing taxonomy: %s", viewName.plural)
                                        }
                                        k := strings.ToLower(p.m.term)
                                        err := m.treeTaxonomyEntries.WalkPrefix(
index 0db3e9c3910c5ed6db80c9eed50e0eb730f234bc..913f4c21daf656c6b53b710ede878747abc3e215 100644 (file)
@@ -753,3 +753,26 @@ Single.
 `
        Test(t, files)
 }
+
+func TestTaxonomiesSpaceInName(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+[taxonomies]
+authors = 'book authors'
+-- content/p1.md --
+---
+title: Good Omens
+book authors:
+  - Neil Gaiman
+  - Terry Pratchett
+---
+-- layouts/index.html --
+{{- $taxonomy := "book authors" }}
+Len Book Authors: {{ len (index .Site.Taxonomies $taxonomy) }}
+`
+       b := Test(t, files)
+
+       b.AssertFileContent("public/index.html", "Len Book Authors: 2")
+}