hugolib: Allow empty params front matter

Treat an empty front matter params key as an empty params map instead of failing while decoding page metadata.

Fixes #14886
This commit is contained in:
Alexandre Vaz
2026-05-17 14:59:44 -03:00
committed by GitHub
parent 81d77620c6
commit 2f361a8e25
2 changed files with 31 additions and 2 deletions
+2 -2
View File
@@ -655,9 +655,9 @@ params:
loki := strings.ToLower(k)
if loki == "params" {
vv, err := hmaps.ToStringMapE(v)
vv, err := hmaps.ToParamsAndPrepare(v)
if err != nil {
return err
return fmt.Errorf("front matter field %q must be a map: %w", k, err)
}
userParams = vv
delete(pcfg.Params, k)
+29
View File
@@ -398,6 +398,35 @@ func TestRebuilErrorRecovery(t *testing.T) {
b.EditFileReplaceAll("content/mysection/mysectionbundle/index.md", "{{< foo }}", "{{< foo >}}").Build()
}
func TestRebuildEmptyParamsIssue14886(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
baseURL = "https://example.com"
disableKinds = ["term", "taxonomy", "sitemap", "robotstxt", "404", "rss"]
disableLiveReload = true
-- content/news/_index.md --
---
title: News
params:
featuredImage: featured.png
---
News.
-- layouts/list.html --
List: {{ .Title }}|{{ .Params.featuredimage }}|
`
b := TestRunning(t, files)
b.AssertFileContent("public/news/index.html", "List: News|featured.png|")
b.EditFileReplaceAll("content/news/_index.md", " featuredImage", "featuredImage").Build()
b.AssertFileContent("public/news/index.html", "List: News|featured.png|")
b.EditFileReplaceAll("content/news/_index.md", "featuredImage", " featuredImage").Build()
b.AssertFileContent("public/news/index.html", "List: News|featured.png|")
}
// Issue 14573
func TestRebuildAddContentWithMultipleDirCreations(t *testing.T) {
t.Parallel()