From 7afac3f1adcdbaa7e93a7062dbd687ec5e58df9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 7 Mar 2024 09:07:12 +0100 Subject: [PATCH] Don't auto-create empty sections for nested taxonomies Fixes #12188 --- hugolib/content_map_page.go | 8 ++++++++ hugolib/taxonomy_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index f20a30abe..764078623 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -1814,6 +1814,14 @@ func (sa *sitePagesAssembler) addMissingRootSections() error { return false, nil } + switch ps.Kind() { + case kinds.KindPage, kinds.KindSection: + // OK + default: + // Skip taxonomy nodes etc. + return false, nil + } + p := ps.m.pathInfo section := p.Section() if section == "" || seen[section] { diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index e8bf54758..bfdfd8dfd 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -936,3 +936,37 @@ title: Authors Page b.AssertFileExists("public/authors/index.html", true) b.AssertFileContent("public/authors/index.html", "layouts/_default/author.terms.html") // failing test } + +func TestTaxonomyNestedEmptySectionsIssue12188(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['rss','sitemap'] +defaultContentLanguage = 'en' +defaultContentLanguageInSubdir = true +[languages.en] +weight = 1 +[languages.ja] +weight = 2 +[taxonomies] +'s1/category' = 's1/category' +-- layouts/_default/single.html -- +{{ .Title }}| +-- layouts/_default/list.html -- +{{ .Title }}| +-- content/s1/p1.en.md -- +--- +title: p1 +--- +` + + b := Test(t, files) + + b.AssertFileExists("public/en/s1/index.html", true) + b.AssertFileExists("public/en/s1/p1/index.html", true) + b.AssertFileExists("public/en/s1/category/index.html", true) + + b.AssertFileExists("public/ja/s1/index.html", false) // failing test + b.AssertFileExists("public/ja/s1/category/index.html", true) +}