From 488b21d15b51f19f790922311ec13b16d784e1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 5 Apr 2024 12:00:38 +0200 Subject: Fix sectionPagesMenu for pages in root level Fixes #12306 --- hugolib/menu_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ hugolib/site.go | 7 +++++++ 2 files changed, 47 insertions(+) diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index 8ff74304b..816ffb676 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -636,3 +636,43 @@ Menu Item: {{ $i }}|{{ .URL }}| Menu Item: 0|/foo/posts| `) } + +func TestSectionPagesMenuMultilingualWarningIssue12306(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['section','rss','sitemap','taxonomy','term'] +defaultContentLanguageInSubdir = true +sectionPagesMenu = "main" +[languages.en] +[languages.fr] +-- layouts/_default/home.html -- +{{- range site.Menus.main -}} + {{ .Name }} +{{- end -}} +-- layouts/_default/single.html -- +{{ .Title }} +-- content/p1.en.md -- +--- +title: p1 +menu: main +--- +-- content/p1.fr.md -- +--- +title: p1 +menu: main +--- +-- content/p2.en.md -- +--- +title: p2 +menu: main +--- +` + + b := Test(t, files, TestOptWarn()) + + b.AssertFileContent("public/en/index.html", `p1p2`) + b.AssertFileContent("public/fr/index.html", `p1`) + b.AssertLogNotContains("WARN") +} diff --git a/hugolib/site.go b/hugolib/site.go index 6d2d6c852..9ab361722 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -658,8 +658,13 @@ func (s *Site) assembleMenus() error { if p.IsHome() || !p.m.shouldBeCheckedForMenuDefinitions() { return false, nil } + // The section pages menus are attached to the top level section. id := p.Section() + if id == "" { + id = "/" + } + if _, ok := flat[twoD{sectionPagesMenu, id}]; ok { return false, nil } @@ -671,6 +676,7 @@ func (s *Site) assembleMenus() error { }, Page: p, } + navigation.SetPageValues(&me, p) flat[twoD{sectionPagesMenu, me.KeyName()}] = &me return false, nil @@ -678,6 +684,7 @@ func (s *Site) assembleMenus() error { return err } } + // Add menu entries provided by pages if err := s.pageMap.forEachPage(pagePredicates.ShouldListGlobal, func(p *pageState) (bool, error) { for name, me := range p.pageMenus.menus() { -- cgit v1.2.3