Fix for page in multiple menus

Fixes #1934
This commit is contained in:
Bjørn Erik Pedersen 2016-03-10 10:31:12 +01:00
parent 973393c99e
commit 924028a9be
2 changed files with 40 additions and 7 deletions

View file

@ -344,6 +344,38 @@ func TestMenuURL(t *testing.T) {
} }
// Issue #1934
func TestYAMLMenuWithMultipleEntries(t *testing.T) {
viper.Reset()
defer viper.Reset()
ps1 := []byte(`---
title: "Yaml 1"
weight: 5
menu: ["p_one", "p_two"]
---
Yaml Front Matter with Menu Pages`)
ps2 := []byte(`---
title: "Yaml 2"
weight: 5
menu:
p_three:
p_four:
---
Yaml Front Matter with Menu Pages`)
s := setupMenuTests(t, []source.ByteSource{
{filepath.FromSlash("sect/yaml1.md"), ps1},
{filepath.FromSlash("sect/yaml2.md"), ps2}})
p1 := s.Pages[0]
assert.Len(t, p1.Menus(), 2, "List YAML")
p2 := s.Pages[1]
assert.Len(t, p2.Menus(), 2, "Map YAML")
}
// issue #719 // issue #719
func TestMenuWithUnicodeURLs(t *testing.T) { func TestMenuWithUnicodeURLs(t *testing.T) {

View file

@ -759,8 +759,8 @@ func (p *Page) Menus() PageMenus {
for _, mname := range mnames { for _, mname := range mnames {
me.Menu = mname me.Menu = mname
p.pageMenus[mname] = &me p.pageMenus[mname] = &me
return
} }
return
} }
// Could be a structured menu entry // Could be a structured menu entry
@ -772,14 +772,15 @@ func (p *Page) Menus() PageMenus {
for name, menu := range menus { for name, menu := range menus {
menuEntry := MenuEntry{Name: p.LinkTitle(), URL: link, Weight: p.Weight, Menu: name} menuEntry := MenuEntry{Name: p.LinkTitle(), URL: link, Weight: p.Weight, Menu: name}
if menu != nil {
jww.DEBUG.Printf("found menu: %q, in %q\n", name, p.Title) jww.DEBUG.Printf("found menu: %q, in %q\n", name, p.Title)
ime, err := cast.ToStringMapE(menu) ime, err := cast.ToStringMapE(menu)
if err != nil { if err != nil {
jww.ERROR.Printf("unable to process menus for %q\n", p.Title) jww.ERROR.Printf("unable to process menus for %q: %s", p.Title, err)
} }
menuEntry.MarshallMap(ime) menuEntry.MarshallMap(ime)
}
p.pageMenus[name] = &menuEntry p.pageMenus[name] = &menuEntry
} }
} }