Skip to content

Commit

Permalink
content adapter: Fix site.GetPage using the base part of the path
Browse files Browse the repository at this point in the history
Fixes #12561
  • Loading branch information
bep committed Jun 2, 2024
1 parent c8dac67 commit 917199a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hugolib/content_map_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,8 @@ func newPageMap(i int, s *Site, mcache *dynacache.Cache, pageTrees *pageTrees) *
LockType: doctree.LockTypeRead,
Handle: func(s string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
p := n.(*pageState)
if p.File() != nil {
add(p.File().FileInfo().Meta().PathInfo.BaseNameNoIdentifier(), p)
if p.PathInfo() != nil {
add(p.PathInfo().BaseNameNoIdentifier(), p)
}
return false, nil
},
Expand Down
33 changes: 33 additions & 0 deletions hugolib/pagecollections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,36 @@ draft: true
b.AssertFileContent("public/s1-foo/index.html", "/s1-foo/: Pages: /s1-foo/p2/|/s1-foo/s2-foo/|/s1-foo/s2/|$")
b.AssertFileContent("public/s1-foo/s2/index.html", "/s1-foo/s2/: Pages: /s1-foo/s2/p3/|$")
}

func TestGetPageContentAdapterBaseIssue12561(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
disableKinds = ['rss','section','sitemap','taxonomy','term']
-- layouts/index.html --
Test A: {{ (site.GetPage "/s1/p1").Title }}
Test B: {{ (site.GetPage "p1").Title }}
Test C: {{ (site.GetPage "/s2/p2").Title }}
Test D: {{ (site.GetPage "p2").Title }}
-- layouts/_default/single.html --
{{ .Title }}
-- content/s1/p1.md --
---
title: p1
---
-- content/s2/_content.gotmpl --
{{ .AddPage (dict "path" "p2" "title" "p2") }}
`

b := Test(t, files)

b.AssertFileExists("public/s1/p1/index.html", true)
b.AssertFileExists("public/s2/p2/index.html", true)
b.AssertFileContent("public/index.html",
"Test A: p1",
"Test B: p1",
"Test C: p2",
"Test D: p2", // fails
)
}

0 comments on commit 917199a

Please sign in to comment.