From 6792d86ad028571c684a776c5f00e0107838c955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= <bjorn.erik.pedersen@gmail.com> Date: Fri, 6 Apr 2018 10:41:28 +0200 Subject: [PATCH] hugolib: Set .Parent in bundled pages to its owner Fixes #4582 --- hugolib/page_bundler_handlers.go | 1 + hugolib/page_bundler_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/hugolib/page_bundler_handlers.go b/hugolib/page_bundler_handlers.go index 477f336fcc4..c22b719d193 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 34e4ef6e42d..becf8c62235 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"))