Fix Params case handling for menu items defined in site config

Fixes #8775
This commit is contained in:
Bjørn Erik Pedersen 2021-07-20 11:32:50 +02:00
parent c19f65f956
commit 634481ba8c
2 changed files with 33 additions and 30 deletions

View file

@ -351,49 +351,51 @@ menu:
} }
func TestMenuParams(t *testing.T) { func TestMenuParams(t *testing.T) {
b := newTestSitesBuilder(t).WithSimpleConfigFile() b := newTestSitesBuilder(t).WithConfigFile("toml", `
[[menus.main]]
identifier = "contact"
title = "Contact Us"
url = "mailto:noreply@example.com"
weight = 300
[menus.main.params]
foo = "foo_config"
key2 = "key2_config"
camelCase = "camelCase_config"
`)
b.WithTemplatesAdded("index.html", ` b.WithTemplatesAdded("index.html", `
Main: {{ len .Site.Menus.main }} Main: {{ len .Site.Menus.main }}
{{ range .Site.Menus.main }} {{ range .Site.Menus.main }}
* Main|{{ .Name }}: {{ .URL }}|{{ .Params }} foo: {{ .Params.foo }}
key2: {{ .Params.KEy2 }}
camelCase: {{ .Params.camelcase }}
{{ end }} {{ end }}
`) `)
b.WithContent("blog/page1.md", ` b.WithContent("_index.md", `
--- ---
title: "P1" title: "Home"
menu: main
---
`)
b.WithContent("blog/page2.md", `
---
title: "P2"
menu: main
---
`)
b.WithContent("blog/page3.md", `
---
title: "P3"
menu: menu:
main: main:
weight: 30 weight: 10
params: params:
foo: "bar" foo: "foo_content"
key2: "value2" key2: "key2_content"
camelCase: "camelCase_content"
--- ---
`) `)
b.Build(BuildCfg{}) b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", b.AssertFileContent("public/index.html", `
"Main: 3", Main: 2
"Main|P3: /blog/page3/|map[foo:bar key2:value2]",
"Main|P1: /blog/page1/|map[]", foo: foo_content
"Main|P2: /blog/page2/|map[]", key2: key2_content
) camelCase: camelCase_content
foo: foo_config
key2: key2_config
camelCase: camelCase_config
`)
} }

View file

@ -131,7 +131,8 @@ func (m *MenuEntry) MarshallMap(ime map[string]interface{}) {
case "parent": case "parent":
m.Parent = cast.ToString(v) m.Parent = cast.ToString(v)
case "params": case "params":
m.Params = maps.ToStringMap(v) m.Params = maps.MustToParamsAndPrepare(v)
} }
} }
} }