]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
hugolib: Fix term title when taxonomy name contains spaces
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 14 Feb 2026 17:01:30 +0000 (18:01 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 14 Feb 2026 18:14:40 +0000 (19:14 +0100)
The pluralTreeKey is normalized (spaces become hyphens), but the
unnormalized path preserves spaces. Use the plural name directly
for prefix trimming on the unnormalized path.

Fixes #13422

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
hugolib/page__meta.go
hugolib/taxonomy_test.go

index 35dcee90909236ac3d9fe395f155e09e6972840c..92569e010366bdd893a06cb7439a68b4d914f5a8 100644 (file)
@@ -308,7 +308,7 @@ func (m *pageMeta) initLate(s *Site) error {
                m.singular = tc.singular
 
                if m.pageConfigSource.Kind == kinds.KindTerm {
-                       m.term = paths.TrimLeading(strings.TrimPrefix(m.pathInfo.Unnormalized().Base(), tc.pluralTreeKey))
+                       m.term = paths.TrimLeading(strings.TrimPrefix(m.pathInfo.Unnormalized().Base(), "/"+tc.plural))
                }
        }
 
index fb769a89e8f0e63adee7b0c9a7e253dea1b6c7b7..72beb587e2f3d9c610f8d03d15983c5d4a965bfa 100644 (file)
@@ -619,21 +619,32 @@ func TestTaxonomiesSpaceInName(t *testing.T) {
        files := `
 -- hugo.toml --
 [taxonomies]
-authors = 'book authors'
--- content/p1.md --
+"book author" = "book authors"
+-- content/posts/post1.md --
+---
+title: Post 1
+book authors: ["Author One"]
+---
+-- content/posts/post2.md --
 ---
-title: Good Omens
-book authors:
-  - Neil Gaiman
-  - Terry Pratchett
+title: Post 2
+book authors: ["Author One", "Author Two"]
 ---
 -- layouts/home.html --
 {{- $taxonomy := "book authors" }}
 Len Book Authors: {{ len (index .Site.Taxonomies $taxonomy) }}
+-- layouts/_default/taxonomy.html --
+{{ range .Data.Terms.ByCount }}
+Term: {{ .Term }}|Count: {{ .Count }}|Name: {{ .Name }}|Page title: {{ .Page.Title }}|
+{{ end }}
 `
        b := Test(t, files)
 
        b.AssertFileContent("public/index.html", "Len Book Authors: 2")
+       b.AssertFileContent("public/book-authors/index.html",
+               "Term: author one|Count: 2|Name: author one|Page title: Author One|",
+               "Term: author two|Count: 1|Name: author two|Page title: Author Two|",
+       )
 }
 
 func TestTaxonomiesListTermsHome(t *testing.T) {