mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user