Make Urls in menus respect CanonifyUrls

Fixes #519
This commit is contained in:
bep 2014-12-10 19:37:49 +01:00
parent e6541c45ab
commit 3ccb397902
4 changed files with 8 additions and 7 deletions

View file

@ -182,7 +182,7 @@ func TestHomeNodeMenu(t *testing.T) {
defer resetMenuTestState(ts) defer resetMenuTestState(ts)
home := ts.site.newHomeNode() home := ts.site.newHomeNode()
homeMenuEntry := &MenuEntry{Name: home.Title, Url: string(home.Permalink)} homeMenuEntry := &MenuEntry{Name: home.Title, Url: home.Url}
for i, this := range []struct { for i, this := range []struct {
menu string menu string

View file

@ -38,7 +38,7 @@ func (n *Node) Now() time.Time {
func (n *Node) HasMenuCurrent(menuId string, inme *MenuEntry) bool { func (n *Node) HasMenuCurrent(menuId string, inme *MenuEntry) bool {
if inme.HasChildren() { if inme.HasChildren() {
me := MenuEntry{Name: n.Title, Url: string(n.Permalink)} me := MenuEntry{Name: n.Title, Url: n.Url}
for _, child := range inme.Children { for _, child := range inme.Children {
if me.IsSameResource(child) { if me.IsSameResource(child) {
@ -52,8 +52,7 @@ func (n *Node) HasMenuCurrent(menuId string, inme *MenuEntry) bool {
func (n *Node) IsMenuCurrent(menuId string, inme *MenuEntry) bool { func (n *Node) IsMenuCurrent(menuId string, inme *MenuEntry) bool {
me := MenuEntry{Name: n.Title, Url: string(n.Permalink)} me := MenuEntry{Name: n.Title, Url: n.Url}
if !me.IsSameResource(inme) { if !me.IsSameResource(inme) {
return false return false
} }

View file

@ -473,7 +473,7 @@ func (page *Page) Menus() PageMenus {
ret := PageMenus{} ret := PageMenus{}
if ms, ok := page.Params["menu"]; ok { if ms, ok := page.Params["menu"]; ok {
link, _ := page.Permalink() link, _ := page.RelPermalink()
me := MenuEntry{Name: page.LinkTitle(), Weight: page.Weight, Url: link} me := MenuEntry{Name: page.LinkTitle(), Weight: page.Weight, Url: link}

View file

@ -532,10 +532,12 @@ func (s *Site) getMenusFromConfig() Menus {
} }
menuEntry.MarshallMap(ime) menuEntry.MarshallMap(ime)
if strings.HasPrefix(menuEntry.Url, "/") { if strings.HasPrefix(menuEntry.Url, "/") {
// make it absolute so it matches the nodes // make it match the nodes
menuEntry.Url = s.permalinkStr(menuEntry.Url) menuEntry.Url = s.prepUrl(menuEntry.Url)
} }
if ret[name] == nil { if ret[name] == nil {
ret[name] = &Menu{} ret[name] = &Menu{}
} }