Allow cascade to be a slice with a _target discriminator

Fixes #7782
This commit is contained in:
Bjørn Erik Pedersen
2020-10-05 20:01:52 +02:00
parent 5e2a547cb5
commit c63db7f1f6
11 changed files with 375 additions and 29 deletions

View File

@@ -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|
`)
})
}