gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.39k stars 7.49k forks source link

Non-section pages added to main menu when using sectionPagesMenu #12399

Closed MTecknology closed 6 months ago

MTecknology commented 6 months ago

What version of Hugo are you using (hugo version)?

First found in hugo_0.123.0_linux-amd64.tar.gz

Does this issue reproduce with the latest release?

Yes.

Starting in v0.123.0, some warnings were printed:

WARN  "aamod/exampleSite/content/contact.md:1:1": duplicate menu entry with identifier "Sample Content" in menu "main"
WARN  "aamod/exampleSite/content/features.md:1:1": duplicate menu entry with identifier "Other Features" in menu "main"

Both pages are rendered using their respective titles/names/paths/weights, however there is an additional entry created at the end of the menu which duplicates the contact.md page. In the most recent release, this warning is removed, but the duplicate entry is still created.

The source I am working on is https://github.com/recoverysource/aamod/

jmooring commented 6 months ago

The erroneous "duplicate menu entry with identifier" warning in v0.123.0 was triggered by sectionPagesMenu = 'main' in the site configuration. The erroneous warning was removed with https://github.com/gohugoio/hugo/pull/12349 in v0.125.0.

The remaining problem (either resulting from or exposed by #12349) is that sectionPagesMenu = 'main' is adding non-section pages (e.g., content/contact.md) to the menu.

git clone --single-branch -b hugo-github-issue-12399 https://github.com/jmooring/hugo-testing hugo-github-issue-12399
cd hugo-github-issue-12399
hugo server

Failing test case:

func TestFoo(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 }}<a href="{{ .URL }}">{{ .Name }}</a>{{ end }}
-- layouts/_default/single.html --
{{ .Title }}
`

    b := hugolib.Test(t, files)

    b.AssertFileExists("public/index.html", true)
    b.AssertFileContent("public/index.html", `<a href="/p2/">p2</a><a href="/s1/">s1</a>`)
}
github-actions[bot] commented 5 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.