Skip to content

hugolib: Don't warn when user-defined front matter param overrides cascaded value #13806

Closed
@jmooring

Description

@jmooring

I ran into this while working on the docs site.

hugo.toml

[[cascade]]
  [cascade.params]
    searchable = true
  [cascade.target]
    kind = 'page'

content/something.md

---
title: Something
params:
  searchable: false
---

With the above, Hugo emits this suppressible warning:

WARN Hugo front matter key "searchable" is overridden in params section.

I think this warning was only meant to apply to user-defined page parameters that have the same key as the predefined page parameters (e.g., title, weight, etc.). The warning is currently emitted if you override a cascaded user-defined parameter too.

Yes, the warning is suppressible, but I found the behavior surprising.

hugo/hugolib/page__meta.go

Lines 649 to 654 in b6c8dfa

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
}

In the code above, user-defined parameters are stored in the top level of the params variable, so we don't know which ones are user-defined vs. predefined.

Maybe create a map of predefined keys, and perform the lookup against it...

var predefinedFrontMatterKeys = map[string]bool{
	"aliases":        true,
	"date":           true,
	"description":    true,
	...
	"url":            true,
	"weight":         true,
}

for k, v := range userParams {
	if _, found := predefinedFrontMatterKeys[k]; found {
		p.s.Log.Warnidf(constants.WarnFrontMatterParamsOverrides, "Hugo front matter key %q is overridden in params section.", k)
	}
	params[strings.ToLower(k)] = v
}

Downside: the predefinedFrontMatterKeys map has to be updated if/when new predefined front matter fields are created.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions