]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix .Parent when there are overlapping regular pages inbetween
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 15 Mar 2024 17:07:28 +0000 (18:07 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 16 Mar 2024 13:48:04 +0000 (14:48 +0100)
Fixes #12263

hugolib/page__tree.go
hugolib/site_sections_test.go

index e54d596bc95dd8e282cab36b9009c920d205f5f5..cccfb89042ade3032dfe5b8d7e57096416ac02e3 100644 (file)
@@ -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 {
index 4d4ff965b9082562f156e3d3be01f5df9be5df22..7fa15fb668dc60d7a929ffbfcfef96e938b10206 100644 (file)
@@ -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/|")
+}