diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-09 11:52:03 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-10 11:13:41 +0200 |
commit | 5cb52c23150032b3fdb211a095745c512369b463 (patch) | |
tree | 3b0c83c462e15e4e55acdf674b70c6ef140291c0 /hugolib/cascade_test.go | |
parent | 30eea3915b67f72611a3b2f4547146d4c6a96864 (diff) |
Add config.cascade
This commit adds support for using the `cascade` keyword in your configuration file(s), e.g. `config.toml`.
Note that
* Every feature of `cascade` is available, e.g. `_target` to target specific page sets.
* Pages, e.g. the home page, can overwrite the cascade defined in config.
Fixes #8741
Diffstat (limited to 'hugolib/cascade_test.go')
-rw-r--r-- | hugolib/cascade_test.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index 78409a4b1..000b641e5 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -20,6 +20,8 @@ import ( "strings" "testing" + "github.com/gohugoio/hugo/common/maps" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/parser" "github.com/gohugoio/hugo/parser/metadecoders" @@ -50,6 +52,69 @@ func BenchmarkCascade(b *testing.B) { } } +func TestCascadeConfig(t *testing.T) { + c := qt.New(t) + + // Make sure the cascade from config gets applied even if we're not + // having a content file for the home page. + for _, withHomeContent := range []bool{true, false} { + testName := "Home content file" + if !withHomeContent { + testName = "No home content file" + } + c.Run(testName, func(c *qt.C) { + b := newTestSitesBuilder(c) + + b.WithConfigFile("toml", ` +baseURL="https://example.org" + +[cascade] +img1 = "img1-config.jpg" +imgconfig = "img-config.jpg" + +`) + + if withHomeContent { + b.WithContent("_index.md", ` +--- +title: "Home" +cascade: + img1: "img1-home.jpg" + img2: "img2-home.jpg" +--- +`) + } + + b.WithContent("p1.md", ``) + + b.Build(BuildCfg{}) + + p1 := b.H.Sites[0].getPage("p1") + + if withHomeContent { + b.Assert(p1.Params(), qt.DeepEquals, maps.Params{ + "imgconfig": "img-config.jpg", + "draft": bool(false), + "iscjklanguage": bool(false), + "img1": "img1-home.jpg", + "img2": "img2-home.jpg", + }) + } else { + b.Assert(p1.Params(), qt.DeepEquals, maps.Params{ + "img1": "img1-config.jpg", + "imgconfig": "img-config.jpg", + "draft": bool(false), + "iscjklanguage": bool(false), + }) + + } + + }) + + } + +} + func TestCascade(t *testing.T) { allLangs := []string{"en", "nn", "nb", "sv"} |