mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Emit a warning that can be turned off when overwriting built-in .Params values
Fixes #11941
This commit is contained in:
parent
4e84f57efb
commit
afee781f03
3 changed files with 29 additions and 1 deletions
|
@ -13,12 +13,14 @@
|
||||||
|
|
||||||
package constants
|
package constants
|
||||||
|
|
||||||
// Error IDs.
|
// Error/Warning IDs.
|
||||||
// Do not change these values.
|
// Do not change these values.
|
||||||
const (
|
const (
|
||||||
// IDs for remote errors in tpl/data.
|
// IDs for remote errors in tpl/data.
|
||||||
ErrRemoteGetJSON = "error-remote-getjson"
|
ErrRemoteGetJSON = "error-remote-getjson"
|
||||||
ErrRemoteGetCSV = "error-remote-getcsv"
|
ErrRemoteGetCSV = "error-remote-getcsv"
|
||||||
|
|
||||||
|
WarnFrontMatterParamsOverrides = "warning-frontmatter-params-overrides"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Field/method names with special meaning.
|
// Field/method names with special meaning.
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/source"
|
"github.com/gohugoio/hugo/source"
|
||||||
|
|
||||||
|
"github.com/gohugoio/hugo/common/constants"
|
||||||
"github.com/gohugoio/hugo/common/hugo"
|
"github.com/gohugoio/hugo/common/hugo"
|
||||||
"github.com/gohugoio/hugo/common/maps"
|
"github.com/gohugoio/hugo/common/maps"
|
||||||
"github.com/gohugoio/hugo/common/paths"
|
"github.com/gohugoio/hugo/common/paths"
|
||||||
|
@ -621,6 +622,9 @@ func (p *pageState) setMetaPostParams() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range userParams {
|
for k, v := range userParams {
|
||||||
|
if _, found := params[k]; found {
|
||||||
|
p.s.Log.Warnidf(constants.WarnFrontMatterParamsOverrides, "Hugo front matter key %q is overridden in params section.", k)
|
||||||
|
}
|
||||||
params[strings.ToLower(k)] = v
|
params[strings.ToLower(k)] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,28 @@ RegularPages: {{ range site.RegularPages }}{{ .Path }}|{{ .RelPermalink }}|{{ .T
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFrontMatterTitleOverrideWarn(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
baseURL = "https://example.org/"
|
||||||
|
disableKinds = ["taxonomy", "term"]
|
||||||
|
-- content/p1.md --
|
||||||
|
---
|
||||||
|
title: "My title"
|
||||||
|
params:
|
||||||
|
title: "My title from params"
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
b := Test(t, files, TestOptWarn())
|
||||||
|
|
||||||
|
b.AssertLogContains("ARN Hugo front matter key \"title\" is overridden in params section", "You can suppress this warning")
|
||||||
|
}
|
||||||
|
|
||||||
func TestFrontMatterParamsLangNoCascade(t *testing.T) {
|
func TestFrontMatterParamsLangNoCascade(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue