Add environment as a new filter to _cascade.target

Fixes #9612
This commit is contained in:
Cathrine Paulsen
2022-04-05 07:41:24 +00:00
committed by GitHub
parent ed9aa374dd
commit da00e7714e
5 changed files with 58 additions and 2 deletions

View File

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