summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-30 10:07:28 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-30 20:12:03 +0100
commitafee781f03df4305698bf4b6991cd10e996515c5 (patch)
tree032a56da49d959991f9d0c8e6321a0adac0a21ce /hugolib
parent4e84f57efb57f5c8a850e4c1d562a0bcc7bd1700 (diff)
Emit a warning that can be turned off when overwriting built-in .Params values
Fixes #11941
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page__meta.go4
-rw-r--r--hugolib/params_test.go22
2 files changed, 26 insertions, 0 deletions
diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go
index 179622d9b..e4cb2b83b 100644
--- a/hugolib/page__meta.go
+++ b/hugolib/page__meta.go
@@ -31,6 +31,7 @@ import (
"github.com/gohugoio/hugo/source"
+ "github.com/gohugoio/hugo/common/constants"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/paths"
@@ -621,6 +622,9 @@ func (p *pageState) setMetaPostParams() error {
}
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
}
diff --git a/hugolib/params_test.go b/hugolib/params_test.go
index f80f14035..6f890b43b 100644
--- a/hugolib/params_test.go
+++ b/hugolib/params_test.go
@@ -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) {
t.Parallel()