From 39cf906bc0eb59cfc81be0ccd8985a28567e7599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 15 May 2024 11:59:03 +0200 Subject: [PATCH] Fix mixed case Page params handling in content adapters Fixes #12497 --- .../pagesfromgotmpl_integration_test.go | 24 +++++++++++++++++++ resources/page/pagemeta/page_frontmatter.go | 5 ++++ 2 files changed, 29 insertions(+) diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go index f09fa3dc1..75283a122 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go @@ -494,3 +494,27 @@ disableKinds = ['home','section','rss','sitemap','taxonomy','term'] b.AssertFileExists("public/s-1.2.3/p-4.5.6/index.html", true) } + +func TestPagesFromGoParamsIssue12497(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','section','rss','sitemap','taxonomy','term'] +-- content/_content.gotmpl -- +{{ .AddPage (dict "path" "p1" "title" "p1" "params" (dict "paraM1" "param1v" )) }} +{{ .AddResource (dict "path" "p1/data1.yaml" "content" (dict "value" "data1" ) "params" (dict "paraM1" "param1v" )) }} +-- layouts/_default/single.html -- +{{ .Title }}|{{ .Params.paraM1 }} +{{ range .Resources }} +{{ .Name }}|{{ .Params.paraM1 }} +{{ end }} +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/p1/index.html", + "p1|param1v", + "data1.yaml|param1v", + ) +} diff --git a/resources/page/pagemeta/page_frontmatter.go b/resources/page/pagemeta/page_frontmatter.go index d5ed1e401..10ba2a991 100644 --- a/resources/page/pagemeta/page_frontmatter.go +++ b/resources/page/pagemeta/page_frontmatter.go @@ -151,6 +151,11 @@ func (p *PageConfig) Compile(basePath string, pagesFromData bool, ext string, lo p.Path = path.Join(basePath, p.Path) } + if p.Params == nil { + p.Params = make(maps.Params) + } + maps.PrepareParams(p.Params) + if p.Content.Markup == "" && p.Content.MediaType == "" { if ext == "" { ext = "md"