Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f361a8

Browse files
authored
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
1 parent 81d7762 commit 2f361a8

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

hugolib/page__meta.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ params:
655655
loki := strings.ToLower(k)
656656

657657
if loki == "params" {
658-
vv, err := hmaps.ToStringMapE(v)
658+
vv, err := hmaps.ToParamsAndPrepare(v)
659659
if err != nil {
660-
return err
660+
return fmt.Errorf("front matter field %q must be a map: %w", k, err)
661661
}
662662
userParams = vv
663663
delete(pcfg.Params, k)

hugolib/rebuild_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,35 @@ func TestRebuilErrorRecovery(t *testing.T) {
398398
b.EditFileReplaceAll("content/mysection/mysectionbundle/index.md", "{{< foo }}", "{{< foo >}}").Build()
399399
}
400400

401+
func TestRebuildEmptyParamsIssue14886(t *testing.T) {
402+
t.Parallel()
403+
404+
files := `
405+
-- hugo.toml --
406+
baseURL = "https://example.com"
407+
disableKinds = ["term", "taxonomy", "sitemap", "robotstxt", "404", "rss"]
408+
disableLiveReload = true
409+
-- content/news/_index.md --
410+
---
411+
title: News
412+
params:
413+
featuredImage: featured.png
414+
---
415+
News.
416+
-- layouts/list.html --
417+
List: {{ .Title }}|{{ .Params.featuredimage }}|
418+
`
419+
420+
b := TestRunning(t, files)
421+
b.AssertFileContent("public/news/index.html", "List: News|featured.png|")
422+
423+
b.EditFileReplaceAll("content/news/_index.md", " featuredImage", "featuredImage").Build()
424+
b.AssertFileContent("public/news/index.html", "List: News|featured.png|")
425+
426+
b.EditFileReplaceAll("content/news/_index.md", "featuredImage", " featuredImage").Build()
427+
b.AssertFileContent("public/news/index.html", "List: News|featured.png|")
428+
}
429+
401430
// Issue 14573
402431
func TestRebuildAddContentWithMultipleDirCreations(t *testing.T) {
403432
t.Parallel()

0 commit comments

Comments
 (0)