mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 06:52:11 -05:00
hugolib: Fix PrevInSection/NextInSection for nested sections
This was broken in Hugo 0.55.0. Fixes #5883
This commit is contained in:
parent
009076e5ee
commit
bcbed4ebda
2 changed files with 46 additions and 1 deletions
|
@ -220,7 +220,7 @@ func (s *Site) prepareInits() {
|
||||||
if p1.IsPage() && p1.Section() == "" {
|
if p1.IsPage() && p1.Section() == "" {
|
||||||
rootSection = append(rootSection, i)
|
rootSection = append(rootSection, i)
|
||||||
}
|
}
|
||||||
if p1.IsSection() && len(p1.SectionsEntries()) <= 1 {
|
if p1.IsSection() {
|
||||||
sectionPages := p1.Pages()
|
sectionPages := p1.Pages()
|
||||||
for i, p2 := range sectionPages {
|
for i, p2 := range sectionPages {
|
||||||
p2s := p2.(*pageState)
|
p2s := p2.(*pageState)
|
||||||
|
|
|
@ -330,3 +330,48 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||||
th.assertFileContent("public/l1/l2/page/2/index.html", "L1/l2-IsActive: true", "PAG|T2_3|true")
|
th.assertFileContent("public/l1/l2/page/2/index.html", "L1/l2-IsActive: true", "PAG|T2_3|true")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNextInSectionNested(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
pageContent := `---
|
||||||
|
title: "The Page"
|
||||||
|
weight: %d
|
||||||
|
---
|
||||||
|
Some content.
|
||||||
|
`
|
||||||
|
createPageContent := func(weight int) string {
|
||||||
|
return fmt.Sprintf(pageContent, weight)
|
||||||
|
}
|
||||||
|
|
||||||
|
b := newTestSitesBuilder(t)
|
||||||
|
b.WithSimpleConfigFile()
|
||||||
|
b.WithTemplates("_default/single.html", `
|
||||||
|
Prev: {{ with .PrevInSection }}{{ .RelPermalink }}{{ end }}|
|
||||||
|
Next: {{ with .NextInSection }}{{ .RelPermalink }}{{ end }}|
|
||||||
|
`)
|
||||||
|
|
||||||
|
b.WithContent("blog/page1.md", createPageContent(1))
|
||||||
|
b.WithContent("blog/page2.md", createPageContent(2))
|
||||||
|
b.WithContent("blog/cool/_index.md", createPageContent(1))
|
||||||
|
b.WithContent("blog/cool/cool1.md", createPageContent(1))
|
||||||
|
b.WithContent("blog/cool/cool2.md", createPageContent(2))
|
||||||
|
b.WithContent("root1.md", createPageContent(1))
|
||||||
|
b.WithContent("root2.md", createPageContent(2))
|
||||||
|
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
b.AssertFileContent("public/root1/index.html",
|
||||||
|
"Prev: /root2/|", "Next: |")
|
||||||
|
b.AssertFileContent("public/root2/index.html",
|
||||||
|
"Prev: |", "Next: /root1/|")
|
||||||
|
b.AssertFileContent("public/blog/page1/index.html",
|
||||||
|
"Prev: /blog/page2/|", "Next: |")
|
||||||
|
b.AssertFileContent("public/blog/page2/index.html",
|
||||||
|
"Prev: |", "Next: /blog/page1/|")
|
||||||
|
b.AssertFileContent("public/blog/cool/cool1/index.html",
|
||||||
|
"Prev: /blog/cool/cool2/|", "Next: |")
|
||||||
|
b.AssertFileContent("public/blog/cool/cool2/index.html",
|
||||||
|
"Prev: |", "Next: /blog/cool/cool1/|")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue