Skip to content

Commit

Permalink
hugolib: Set .Parent in bundled pages to its owner
Browse files Browse the repository at this point in the history
Fixes #4582
  • Loading branch information
bep committed Apr 6, 2018
1 parent e7d87e2 commit 6792d86
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions hugolib/page_bundler_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions hugolib/page_bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 6792d86

Please sign in to comment.