Skip to content

Commit

Permalink
Don't auto-create empty sections for nested taxonomies
Browse files Browse the repository at this point in the history
Fixes #12188
  • Loading branch information
bep committed Mar 7, 2024
1 parent a4b1747 commit 7afac3f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hugolib/content_map_page.go
Expand Up @@ -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] {
Expand Down
34 changes: 34 additions & 0 deletions hugolib/taxonomy_test.go
Expand Up @@ -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)
}

0 comments on commit 7afac3f

Please sign in to comment.