aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-02-23 09:37:05 +0100
committerBjørn Erik Pedersen <[email protected]>2024-02-23 14:40:29 +0100
commitf521336c8147d00e9caa0b4ba4ab64bc43c69101 (patch)
tree126a4193ebb139348834147cb6bfe49f0ff7b2c1
parentc4fe45ff4cb9080ee968ecc4e80e09df6c366608 (diff)
downloadhugo-f521336c8147d00e9caa0b4ba4ab64bc43c69101.tar.gz
hugo-f521336c8147d00e9caa0b4ba4ab64bc43c69101.zip
hugolib: Fix a .Page.GetPage from bundle case
Fixes #12120
-rw-r--r--hugolib/pagecollections.go9
-rw-r--r--hugolib/pagecollections_test.go27
2 files changed, 29 insertions, 7 deletions
diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go
index 3783dadab..fe7c2f1e7 100644
--- a/hugolib/pagecollections.go
+++ b/hugolib/pagecollections.go
@@ -166,19 +166,14 @@ func (c *pageFinder) getContentNodeForRef(context page.Page, isReflink, hadExten
// Given the above, for regular pages we use the containing folder.
var baseDir string
if pi := context.PathInfo(); pi != nil {
- if pi.IsBranchBundle() || (hadExtension) {
+ if pi.IsBranchBundle() || (hadExtension && strings.HasPrefix(ref, "../")) {
baseDir = pi.Dir()
} else {
baseDir = pi.ContainerDir()
}
}
- rel := path.Join(baseDir, inRef)
-
- if !hadExtension && !paths.HasExt(rel) {
- // See comment above.
- rel += defaultContentExt
- }
+ rel := path.Join(baseDir, ref)
relPath := contentPathParser.Parse(files.ComponentFolderContent, rel)
diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go
index eaa80a109..1cb1cbd70 100644
--- a/hugolib/pagecollections_test.go
+++ b/hugolib/pagecollections_test.go
@@ -386,6 +386,33 @@ Home. {{ with .Page.GetPage "p1.xyz" }}{{ else }}OK 1{{ end }} {{ with .Site.Get
b.AssertFileContent("public/index.html", "Home. OK 1 OK 2")
}
+func TestGetPageIssue12120(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['home','rss','section','sitemap','taxonomy','term']
+-- content/s1/p1/index.md --
+---
+title: p1
+layout: p1
+---
+-- content/s1/p2.md --
+---
+title: p2
+layout: p2
+---
+-- layouts/_default/p1.html --
+{{ (.GetPage "p2.md").Title }}|
+-- layouts/_default/p2.html --
+{{ (.GetPage "p1").Title }}|
+`
+
+ b := Test(t, files)
+ b.AssertFileContent("public/s1/p1/index.html", "p2") // failing test
+ b.AssertFileContent("public/s1/p2/index.html", "p1")
+}
+
func TestGetPageBundleToRegular(t *testing.T) {
files := `
-- hugo.toml --