diff options
-rw-r--r-- | hugolib/cascade_test.go | 27 | ||||
-rw-r--r-- | hugolib/page__meta.go | 4 | ||||
-rw-r--r-- | hugolib/params_test.go | 22 | ||||
-rw-r--r-- | resources/page/page_matcher.go | 6 | ||||
-rw-r--r-- | resources/page/page_matcher_test.go | 4 |
5 files changed, 33 insertions, 30 deletions
diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index fb9dffd15..3e3e471b7 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -938,3 +938,30 @@ path = '/p1' b.AssertFileContent("public/p1/index.html", "p1|bar") // actual content is "p1|" } + +func TestCascadeWarnOverrideIssue13806(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] +[[cascade]] +[cascade.params] +searchable = true +[cascade.target] +kind = 'page' +-- content/something.md -- +--- +title: Something +params: + searchable: false +--- +-- layouts/all.html -- +All. + +` + + b := Test(t, files, TestOptWarn()) + + b.AssertLogContains("! WARN") +} diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index 0d6d22e9a..1af489f18 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -29,7 +29,6 @@ import ( "github.com/gohugoio/hugo/source" - "github.com/gohugoio/hugo/common/constants" "github.com/gohugoio/hugo/common/hashing" "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/common/loggers" @@ -647,9 +646,6 @@ params: } 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 94b832b3e..7f7566024 100644 --- a/hugolib/params_test.go +++ b/hugolib/params_test.go @@ -94,28 +94,6 @@ a/b pages: {{ range $ab.RegularPages }}{{ .Path }}|{{ .RelPermalink }}|{{ end }} ) } -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() diff --git a/resources/page/page_matcher.go b/resources/page/page_matcher.go index 306c2d03c..858def5ef 100644 --- a/resources/page/page_matcher.go +++ b/resources/page/page_matcher.go @@ -174,6 +174,9 @@ func DecodeCascade(logger loggers.Logger, handleLegacyFormat bool, in any) (*map func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, error) { var pcfg PageMatcherParamsConfig + if pcfg.Fields == nil { + pcfg.Fields = make(maps.Params) + } for k, v := range m { switch strings.ToLower(k) { case "_target", "target": @@ -193,9 +196,6 @@ func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, er } } default: - if pcfg.Fields == nil { - pcfg.Fields = make(maps.Params) - } pcfg.Fields[k] = v } diff --git a/resources/page/page_matcher_test.go b/resources/page/page_matcher_test.go index ad35da43c..7f441d3ab 100644 --- a/resources/page/page_matcher_test.go +++ b/resources/page/page_matcher_test.go @@ -99,6 +99,7 @@ func TestPageMatcher(t *testing.T) { Params: maps.Params{ "foo": "bar", }, + Fields: maps.Params{}, Target: PageMatcher{Path: "", Kind: "page", Lang: "", Environment: ""}, }) }) @@ -136,9 +137,10 @@ func TestDecodeCascadeConfig(t *testing.T) { c.Assert(got.SourceStructure, qt.DeepEquals, []PageMatcherParamsConfig{ { Params: maps.Params{"a": string("av")}, + Fields: maps.Params{}, Target: PageMatcher{Kind: "page", Environment: "production"}, }, - {Params: maps.Params{"b": string("bv")}, Target: PageMatcher{Kind: "page"}}, + {Params: maps.Params{"b": string("bv")}, Fields: maps.Params{}, Target: PageMatcher{Kind: "page"}}, }) got, err = DecodeCascadeConfig(loggers.NewDefault(), true, nil) |