From 06d248910c4bc64ddb4c6773157d311f8ea6f600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 20 Apr 2024 16:51:56 +0200 Subject: [PATCH] Only add root sections to the section pages menu Fixes #12399 --- hugolib/menu_test.go | 34 ++++++++++++++++++++++++++++++++++ hugolib/site.go | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index 816ffb676..9e73a8dc3 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -676,3 +676,37 @@ menu: main b.AssertFileContent("public/fr/index.html", `p1`) b.AssertLogNotContains("WARN") } + +func TestSectionPagesIssue12399(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['rss','sitemap','taxonomy','term'] +capitalizeListTitles = false +pluralizeListTitles = false +sectionPagesMenu = 'main' +-- content/p1.md -- +--- +title: p1 +--- +-- content/s1/p2.md -- +--- +title: p2 +menus: main +--- +-- content/s1/p3.md -- +--- +title: p3 +--- +-- layouts/_default/list.html -- +{{ range site.Menus.main }}{{ .Name }}{{ end }} +-- layouts/_default/single.html -- +{{ .Title }} +` + + b := Test(t, files) + + b.AssertFileExists("public/index.html", true) + b.AssertFileContent("public/index.html", `p2s1`) +} diff --git a/hugolib/site.go b/hugolib/site.go index b66a1284b..280387838 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -659,7 +659,7 @@ func (s *Site) assembleMenus() error { if sectionPagesMenu != "" { if err := s.pageMap.forEachPage(pagePredicates.ShouldListGlobal, func(p *pageState) (bool, error) { - if p.IsHome() || !p.m.shouldBeCheckedForMenuDefinitions() { + if p.Kind() != kinds.KindSection || !p.m.shouldBeCheckedForMenuDefinitions() { return false, nil }