diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index 6d26c5ffd..8ca377b1c 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -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) diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go index b3f36d442..f72bfaa31 100644 --- a/hugolib/rebuild_test.go +++ b/hugolib/rebuild_test.go @@ -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()