summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-06 10:41:28 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-06 10:41:28 +0200
commit6792d86ad028571c684a776c5f00e0107838c955 (patch)
tree907036925da0e1446364f139f9b6e43461b262c6 /hugolib
parente7d87e2410fce27b3519bdb360e6d2f0ccfedb0e (diff)
hugolib: Set .Parent in bundled pages to its owner
Fixes #4582
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page_bundler_handlers.go1
-rw-r--r--hugolib/page_bundler_test.go4
2 files changed, 5 insertions, 0 deletions
diff --git a/hugolib/page_bundler_handlers.go b/hugolib/page_bundler_handlers.go
index 477f336fc..c22b719d1 100644
--- a/hugolib/page_bundler_handlers.go
+++ b/hugolib/page_bundler_handlers.go
@@ -228,6 +228,7 @@ func (c *contentHandlers) parsePage(h contentHandler) contentHandler {
if res.resource != nil {
if pageResource, ok := res.resource.(*Page); ok {
pageResource.resourcePath = filepath.ToSlash(childCtx.target)
+ pageResource.parent = p
}
p.Resources = append(p.Resources, res.resource)
}
diff --git a/hugolib/page_bundler_test.go b/hugolib/page_bundler_test.go
index 34e4ef6e4..becf8c622 100644
--- a/hugolib/page_bundler_test.go
+++ b/hugolib/page_bundler_test.go
@@ -132,6 +132,10 @@ func TestPageBundlerSiteRegular(t *testing.T) {
assert.Contains(firstPage.Content, "TheContent")
assert.Equal(6, len(leafBundle1.Resources))
+ // https://github.com/gohugoio/hugo/issues/4582
+ assert.Equal(leafBundle1, firstPage.Parent())
+ assert.Equal(leafBundle1, secondPage.Parent())
+
assert.Equal(firstPage, pageResources.GetByPrefix("1"))
assert.Equal(secondPage, pageResources.GetByPrefix("2"))
assert.Nil(pageResources.GetByPrefix("doesnotexist"))