Skip to content

Commit

Permalink
hugolib: Fix cascade in server mode
Browse files Browse the repository at this point in the history
Fixes #6538
  • Loading branch information
bep committed Nov 26, 2019
1 parent da53523 commit 0176643
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
44 changes: 44 additions & 0 deletions hugolib/cascade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,50 @@ func TestCascade(t *testing.T) {

}

func TestCascadeEdit(t *testing.T) {
p1Content := `---
title: P1
---
`
b := newTestSitesBuilder(t).Running()
b.WithTemplatesAdded("_default/single.html", `Banner: {{ .Params.banner }}|Layout: {{ .Layout }}|Type: {{ .Type }}|Content: {{ .Content }}`)
b.WithContent("post/_index.md", `
---
title: Post
cascade:
banner: post.jpg
layout: postlayout
type: posttype
---
`)

b.WithContent("post/dir/_index.md", `
---
title: Dir
---
`, "post/dir/p1.md", p1Content)
b.Build(BuildCfg{})

assert := func() {
b.Helper()
b.AssertFileContent("public/post/dir/p1/index.html",
`Banner: post.jpg|`,
`Layout: postlayout`,
`Type: posttype`,
)
}

assert()

b.EditFiles("content/post/dir/p1.md", p1Content+"\ncontent edit")
b.Build(BuildCfg{})

assert()
b.AssertFileContent("public/post/dir/p1/index.html",
`content edit`,
)
}

func newCascadeTestBuilder(t testing.TB, langs []string) *sitesBuilder {
p := func(m map[string]interface{}) string {
var yamlStr string
Expand Down
14 changes: 13 additions & 1 deletion hugolib/pages_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,19 @@ func (m *pagesMap) addBucketFor(key string, p *pageState, meta map[string]interf

disabled := !m.s.isEnabled(p.Kind())

bucket := &pagesMapBucket{owner: p, view: isView, meta: meta, disabled: disabled}
var cascade map[string]interface{}
if p.bucket != nil {
cascade = p.bucket.cascade
}

bucket := &pagesMapBucket{
owner: p,
view: isView,
cascade: cascade,
meta: meta,
disabled: disabled,
}

p.bucket = bucket

m.r.Insert(key, bucket)
Expand Down

0 comments on commit 0176643

Please sign in to comment.