mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	@@ -189,6 +189,9 @@ kind
 | 
			
		||||
lang
 | 
			
		||||
: A Glob pattern matching the Page's language, e.g. "{en,sv}".
 | 
			
		||||
 | 
			
		||||
environment
 | 
			
		||||
: A Glob pattern matching the build environment, e.g. "{production,development}"
 | 
			
		||||
 | 
			
		||||
Any of the above can be omitted. 
 | 
			
		||||
 | 
			
		||||
### Example
 | 
			
		||||
 
 | 
			
		||||
@@ -550,6 +550,32 @@ S1|p1:|p2:p2|
 | 
			
		||||
`)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	c.Run("slice with environment _target", func(c *qt.C) {
 | 
			
		||||
		b := newBuilder(c)
 | 
			
		||||
 | 
			
		||||
		b.WithContent("_index.md", `+++
 | 
			
		||||
title = "Home"
 | 
			
		||||
[[cascade]]
 | 
			
		||||
p1 = "p1"
 | 
			
		||||
[cascade._target]
 | 
			
		||||
path="**p1**"
 | 
			
		||||
environment="testing"
 | 
			
		||||
[[cascade]]
 | 
			
		||||
p2 = "p2"
 | 
			
		||||
[cascade._target]
 | 
			
		||||
kind="section"
 | 
			
		||||
environment="production"
 | 
			
		||||
+++
 | 
			
		||||
`)
 | 
			
		||||
 | 
			
		||||
		b.Build(BuildCfg{})
 | 
			
		||||
 | 
			
		||||
		b.AssertFileContent("public/index.html", `
 | 
			
		||||
P1|p1:|p2:|
 | 
			
		||||
S1|p1:|p2:p2|
 | 
			
		||||
`)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	c.Run("slice with yaml _target", func(c *qt.C) {
 | 
			
		||||
		b := newBuilder(c)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -37,6 +37,9 @@ type PageMatcher struct {
 | 
			
		||||
 | 
			
		||||
	// A Glob pattern matching the Page's language, e.g. "{en,sv}".
 | 
			
		||||
	Lang string
 | 
			
		||||
 | 
			
		||||
	// A Glob pattern matching the Page's Environment, e.g. "{production,development}".
 | 
			
		||||
	Environment string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Matches returns whether p matches this matcher.
 | 
			
		||||
@@ -67,6 +70,13 @@ func (m PageMatcher) Matches(p Page) bool {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if m.Environment != "" {
 | 
			
		||||
		g, err := glob.GetGlob(m.Environment)
 | 
			
		||||
		if err == nil && !g.Match(p.Site().Hugo().Environment) {
 | 
			
		||||
			return false
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@
 | 
			
		||||
package page
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/gohugoio/hugo/common/hugo"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
@@ -22,8 +23,13 @@ import (
 | 
			
		||||
 | 
			
		||||
func TestPageMatcher(t *testing.T) {
 | 
			
		||||
	c := qt.New(t)
 | 
			
		||||
	developmentTestSite := testSite{h: hugo.NewInfo("development", nil)}
 | 
			
		||||
	productionTestSite := testSite{h: hugo.NewInfo("production", nil)}
 | 
			
		||||
 | 
			
		||||
	p1, p2, p3 := &testPage{path: "/p1", kind: "section", lang: "en"}, &testPage{path: "p2", kind: "page", lang: "no"}, &testPage{path: "p3", kind: "page", lang: "en"}
 | 
			
		||||
	p1, p2, p3 :=
 | 
			
		||||
		&testPage{path: "/p1", kind: "section", lang: "en", site: developmentTestSite},
 | 
			
		||||
		&testPage{path: "p2", kind: "page", lang: "no", site: productionTestSite},
 | 
			
		||||
		&testPage{path: "p3", kind: "page", lang: "en"}
 | 
			
		||||
 | 
			
		||||
	c.Run("Matches", func(c *qt.C) {
 | 
			
		||||
		m := PageMatcher{Kind: "section"}
 | 
			
		||||
@@ -50,6 +56,16 @@ func TestPageMatcher(t *testing.T) {
 | 
			
		||||
		c.Assert(m.Matches(p1), qt.Equals, true)
 | 
			
		||||
		c.Assert(m.Matches(p2), qt.Equals, false)
 | 
			
		||||
		c.Assert(m.Matches(p3), qt.Equals, true)
 | 
			
		||||
 | 
			
		||||
		m = PageMatcher{Environment: "development"}
 | 
			
		||||
		c.Assert(m.Matches(p1), qt.Equals, true)
 | 
			
		||||
		c.Assert(m.Matches(p2), qt.Equals, false)
 | 
			
		||||
		c.Assert(m.Matches(p3), qt.Equals, false)
 | 
			
		||||
 | 
			
		||||
		m = PageMatcher{Environment: "production"}
 | 
			
		||||
		c.Assert(m.Matches(p1), qt.Equals, false)
 | 
			
		||||
		c.Assert(m.Matches(p2), qt.Equals, true)
 | 
			
		||||
		c.Assert(m.Matches(p3), qt.Equals, false)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	c.Run("Decode", func(c *qt.C) {
 | 
			
		||||
 
 | 
			
		||||
@@ -94,6 +94,7 @@ type testPage struct {
 | 
			
		||||
	linkTitle   string
 | 
			
		||||
	lang        string
 | 
			
		||||
	section     string
 | 
			
		||||
	site        testSite
 | 
			
		||||
 | 
			
		||||
	content string
 | 
			
		||||
 | 
			
		||||
@@ -532,7 +533,7 @@ func (p *testPage) SectionsPath() string {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *testPage) Site() Site {
 | 
			
		||||
	panic("not implemented")
 | 
			
		||||
	return p.site
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *testPage) Sites() Sites {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user