Skip to content

Commit

Permalink
Fix Params case handling for menu items defined in site config
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jul 20, 2021
1 parent c19f65f commit 9988279
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
60 changes: 31 additions & 29 deletions hugolib/menu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,49 +351,51 @@ menu:
}

func TestMenuParams(t *testing.T) {
b := newTestSitesBuilder(t).WithSimpleConfigFile()
b := newTestSitesBuilder(t).WithConfigFile("toml", `
[[menus.main]]
identifier = "contact"
title = "Contact Us"
url = "mailto:[email protected]"
weight = 300
[menus.main.params]
foo = "foo_config"
key2 = "key2_config"
camelCase = "camelCase_config"
`)

b.WithTemplatesAdded("index.html", `
Main: {{ len .Site.Menus.main }}
{{ range .Site.Menus.main }}
* Main|{{ .Name }}: {{ .URL }}|{{ .Params }}
foo: {{ .Params.foo }}
key2: {{ .Params.KEy2 }}
camelCase: {{ .Params.camelcase }}
{{ end }}
`)

b.WithContent("blog/page1.md", `
---
title: "P1"
menu: main
---
`)

b.WithContent("blog/page2.md", `
---
title: "P2"
menu: main
---
`)

b.WithContent("blog/page3.md", `
b.WithContent("_index.md", `
---
title: "P3"
title: "Home"
menu:
main:
weight: 30
weight: 10
params:
foo: "bar"
key2: "value2"
foo: "foo_content"
key2: "key2_content"
camelCase: "camelCase_content"
---
`)

b.Build(BuildCfg{})

b.AssertFileContent("public/index.html",
"Main: 3",
"Main|P3: /blog/page3/|map[foo:bar key2:value2]",
"Main|P1: /blog/page1/|map[]",
"Main|P2: /blog/page2/|map[]",
)
b.AssertFileContent("public/index.html", `
Main: 2
foo: foo_content
key2: key2_content
camelCase: camelCase_content
foo: foo_config
key2: key2_config
camelCase: camelCase_config
`)
}
3 changes: 2 additions & 1 deletion navigation/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func (m *MenuEntry) MarshallMap(ime map[string]interface{}) {
case "parent":
m.Parent = cast.ToString(v)
case "params":
m.Params = maps.ToStringMap(v)
m.Params = maps.MustToParamsAndPrepare(v)

}
}
}
Expand Down

0 comments on commit 9988279

Please sign in to comment.