hugolib: Set .Parent in bundled pages to its owner
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 6 Apr 2018 08:41:28 +0000 (10:41 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 6 Apr 2018 08:41:28 +0000 (10:41 +0200)
Fixes #4582

hugolib/page_bundler_handlers.go
hugolib/page_bundler_test.go

index 477f336fcc4e36599b15eeaddec7f03ca220f97c..c22b719d193a181d9ee73bdb9b77d951158033f1 100644 (file)
@@ -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)
                                }
index 34e4ef6e42df476ac7a8f042fff7ef0adf710adf..becf8c6223512858187804d3e57ecb36a7c21fb7 100644 (file)
@@ -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"))