diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-03-15 18:07:28 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-03-16 14:48:04 +0100 |
commit | f1d755965fba9a8d99a4e423c6e231cf7411b4a2 (patch) | |
tree | c38d9058e2a46a53ab8cafa0af5576b7a74d56bf | |
parent | 558f74f009d5bafd680958e511dc40f20dd0259a (diff) | |
download | hugo-f1d755965fba9a8d99a4e423c6e231cf7411b4a2.tar.gz hugo-f1d755965fba9a8d99a4e423c6e231cf7411b4a2.zip |
Fix .Parent when there are overlapping regular pages inbetween
Fixes #12263
-rw-r--r-- | hugolib/page__tree.go | 13 | ||||
-rw-r--r-- | hugolib/site_sections_test.go | 23 |
2 files changed, 32 insertions, 4 deletions
diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go index e54d596bc..cccfb8904 100644 --- a/hugolib/page__tree.go +++ b/hugolib/page__tree.go @@ -124,11 +124,16 @@ func (pt pageTree) Parent() page.Page { return pt.p.s.home } - _, n := pt.p.s.pageMap.treePages.LongestPrefix(dir, true, nil) - if n != nil { - return n.(page.Page) + for { + _, n := pt.p.s.pageMap.treePages.LongestPrefix(dir, true, nil) + if n == nil { + return pt.p.s.home + } + if pt.p.m.bundled || n.isContentNodeBranch() { + return n.(page.Page) + } + dir = paths.Dir(dir) } - return nil } func (pt pageTree) Ancestors() page.Pages { diff --git a/hugolib/site_sections_test.go b/hugolib/site_sections_test.go index 4d4ff965b..7fa15fb66 100644 --- a/hugolib/site_sections_test.go +++ b/hugolib/site_sections_test.go @@ -398,3 +398,26 @@ Kind: {{ .Kind }}|RelPermalink: {{ .RelPermalink }}|SectionsPath: {{ .SectionsPa b.AssertFileContent("public/a/b/c/mybundle/index.html", "Kind: page|RelPermalink: /a/b/c/mybundle/|SectionsPath: /a/b/c|SectionsEntries: [a b c]|Len: 3") b.AssertFileContent("public/index.html", "Kind: home|RelPermalink: /|SectionsPath: /|SectionsEntries: []|Len: 0") } + +func TestParentWithPageOverlap(t *testing.T) { + files := ` +-- hugo.toml -- +baseURL = "https://example.com/" +-- content/docs/_index.md -- +-- content/docs/logs/_index.md -- +-- content/docs/logs/sdk.md -- +-- content/docs/logs/sdk_exporters/stdout.md -- +-- layouts/_default/list.html -- +{{ .RelPermalink }}|{{ with .Parent}}{{ .RelPermalink }}{{ end }}| +-- layouts/_default/single.html -- +{{ .RelPermalink }}|{{ with .Parent}}{{ .RelPermalink }}{{ end }}| + +` + b := Test(t, files) + + b.AssertFileContent("public/index.html", "/||") + b.AssertFileContent("public/docs/index.html", "/docs/|/|") + b.AssertFileContent("public/docs/logs/index.html", "/docs/logs/|/docs/|") + b.AssertFileContent("public/docs/logs/sdk/index.html", "/docs/logs/sdk/|/docs/logs/|") + b.AssertFileContent("public/docs/logs/sdk_exporters/stdout/index.html", "/docs/logs/sdk_exporters/stdout/|/docs/logs/|") +} |