Skip to content

Commit

Permalink
Fix .Parent when there are overlapping regular pages inbetween
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Mar 15, 2024
1 parent d4d49e0 commit 45aed4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 9 additions & 4 deletions hugolib/page__tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 nil
}
if pt.p.m.bundled || n.isContentNodeBranch() {
return n.(page.Page)
}
dir = paths.Dir(dir)
}
return nil
}

func (pt pageTree) Ancestors() page.Pages {
Expand Down
18 changes: 18 additions & 0 deletions hugolib/site_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,21 @@ 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/single.html --
{{ .RelPermalink }}|{{ .Parent.RelPermalink }}|
`
b := Test(t, files)

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/|")
}

0 comments on commit 45aed4b

Please sign in to comment.