From 917199a94ea4d67eb911d3e7e26cd7c828fae323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 2 Jun 2024 12:54:14 +0200 Subject: [PATCH] content adapter: Fix site.GetPage using the base part of the path Fixes #12561 --- hugolib/content_map_page.go | 4 ++-- hugolib/pagecollections_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index 66baea3d1f9..a8f5b5fd745 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -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 }, diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index be81c3a6637..96f1afe3d19 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -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 + ) +}