Skip to content

Commit

Permalink
Fix site.Taxonomies for taxonomies with space in name
Browse files Browse the repository at this point in the history
Fixes #12001
  • Loading branch information
bep committed Feb 6, 2024
1 parent bd0200d commit 146aedd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 2 additions & 3 deletions hugolib/content_map_page.go
Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions hugolib/taxonomy_test.go
Expand Up @@ -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")
}

0 comments on commit 146aedd

Please sign in to comment.