mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Fix .Parent when there are overlapping regular pages inbetween
Fixes #12263
This commit is contained in:
parent
558f74f009
commit
f1d755965f
2 changed files with 32 additions and 4 deletions
|
@ -124,11 +124,16 @@ func (pt pageTree) Parent() page.Page {
|
||||||
return pt.p.s.home
|
return pt.p.s.home
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
_, n := pt.p.s.pageMap.treePages.LongestPrefix(dir, true, nil)
|
_, n := pt.p.s.pageMap.treePages.LongestPrefix(dir, true, nil)
|
||||||
if n != nil {
|
if n == nil {
|
||||||
|
return pt.p.s.home
|
||||||
|
}
|
||||||
|
if pt.p.m.bundled || n.isContentNodeBranch() {
|
||||||
return n.(page.Page)
|
return n.(page.Page)
|
||||||
}
|
}
|
||||||
return nil
|
dir = paths.Dir(dir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt pageTree) Ancestors() page.Pages {
|
func (pt pageTree) Ancestors() page.Pages {
|
||||||
|
|
|
@ -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/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")
|
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/|")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue