aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/cascade_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-10-05 20:01:52 +0200
committerBjørn Erik Pedersen <[email protected]>2020-10-06 14:06:10 +0200
commitc63db7f1f6774a2d661af1d8197c6fe377e3ad25 (patch)
treebbeccc7dd4f41acdcc1cfd584ea351e6284869d5 /hugolib/cascade_test.go
parent5e2a547cb594b31ecb0f089b08db2e15c6dc381a (diff)
downloadhugo-c63db7f1f6774a2d661af1d8197c6fe377e3ad25.tar.gz
hugo-c63db7f1f6774a2d661af1d8197c6fe377e3ad25.zip
Allow cascade to be a slice with a _target discriminator
Fixes #7782
Diffstat (limited to 'hugolib/cascade_test.go')
-rw-r--r--hugolib/cascade_test.go70
1 files changed, 69 insertions, 1 deletions
diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go
index 33fc7ceec..336acdcf3 100644
--- a/hugolib/cascade_test.go
+++ b/hugolib/cascade_test.go
@@ -229,7 +229,7 @@ Banner: post.jpg`,
counters := &testCounters{}
b.Build(BuildCfg{testCounters: counters})
- // As we only changed the content, not the cascade front matter, make
+ // As we only changed the content, not the cascade front matter,
// only the home page is re-rendered.
b.Assert(int(counters.contentRenderCounter), qt.Equals, 1)
@@ -392,3 +392,71 @@ defaultContentLanguageInSubDir = false
return b
}
+
+func TestCascadeTarget(t *testing.T) {
+ t.Parallel()
+
+ c := qt.New(t)
+
+ newBuilder := func(c *qt.C) *sitesBuilder {
+ b := newTestSitesBuilder(c)
+
+ b.WithTemplates("index.html", `
+{{ $p1 := site.GetPage "s1/p1" }}
+{{ $s1 := site.GetPage "s1" }}
+
+P1|p1:{{ $p1.Params.p1 }}|p2:{{ $p1.Params.p2 }}|
+S1|p1:{{ $s1.Params.p1 }}|p2:{{ $s1.Params.p2 }}|
+`)
+ b.WithContent("s1/_index.md", "---\ntitle: s1 section\n---")
+ b.WithContent("s1/p1/index.md", "---\ntitle: p1\n---")
+ b.WithContent("s1/p2/index.md", "---\ntitle: p2\n---")
+ b.WithContent("s2/p1/index.md", "---\ntitle: p1_2\n---")
+
+ return b
+
+ }
+
+ c.Run("slice", func(c *qt.C) {
+ b := newBuilder(c)
+ b.WithContent("_index.md", `+++
+title = "Home"
+[[cascade]]
+p1 = "p1"
+[[cascade]]
+p2 = "p2"
++++
+`)
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html", "P1|p1:p1|p2:p2")
+
+ })
+
+ c.Run("slice with _target", func(c *qt.C) {
+ b := newBuilder(c)
+
+ b.WithContent("_index.md", `+++
+title = "Home"
+[[cascade]]
+p1 = "p1"
+[cascade._target]
+path="**p1**"
+[[cascade]]
+p2 = "p2"
+[cascade._target]
+kind="section"
++++
+`)
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html", `
+P1|p1:p1|p2:|
+S1|p1:|p2:p2|
+`)
+
+ })
+
+}