Repository: gohugoio/hugo (language: go)

Issue:
Non-section pages added to main menu when using sectionPagesMenu
<!--
Please do not use the issue queue for questions or troubleshooting. Unless you are certain that your issue is a software defect, use the forum:

https://discourse.gohugo.io -- I do not use discourse.
-->

<!-- Please answer these questions before submitting your issue. Thanks! -->

### 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/


Discussion / hints:
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. 

```text
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:

```go
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>`)
}
```


Fix patch:
diff --git a/hugolib/site.go b/hugolib/site.go
index b66a1284b1a..2803878388d 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
 			}
 


Test patch:
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go
index 816ffb6763a..9e73a8dc348 100644
--- a/hugolib/menu_test.go
+++ b/hugolib/menu_test.go
@@ -676,3 +676,37 @@ menu: main
 	b.AssertFileContent("public/fr/index.html", `<a href="/fr/p1/">p1</a>`)
 	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 }}<a href="{{ .URL }}">{{ .Name }}</a>{{ end }}
+-- layouts/_default/single.html --
+{{ .Title }}
+`
+
+	b := Test(t, files)
+
+	b.AssertFileExists("public/index.html", true)
+	b.AssertFileContent("public/index.html", `<a href="/s1/p2/">p2</a><a href="/s1/">s1</a>`)
+}