From 3ccb3979028aafb3e6cc16d47daa77a1fdea11fa Mon Sep 17 00:00:00 2001 From: bep Date: Wed, 10 Dec 2014 19:37:49 +0100 Subject: [PATCH] Make Urls in menus respect CanonifyUrls Fixes #519 --- hugolib/menu_test.go | 2 +- hugolib/node.go | 5 ++--- hugolib/page.go | 2 +- hugolib/site.go | 6 ++++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index 2336169a2..8a3fd04d3 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -182,7 +182,7 @@ func TestHomeNodeMenu(t *testing.T) { defer resetMenuTestState(ts) 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 { menu string diff --git a/hugolib/node.go b/hugolib/node.go index be4786390..1f50e85e3 100644 --- a/hugolib/node.go +++ b/hugolib/node.go @@ -38,7 +38,7 @@ func (n *Node) Now() time.Time { func (n *Node) HasMenuCurrent(menuId string, inme *MenuEntry) bool { 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 { 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 { - me := MenuEntry{Name: n.Title, Url: string(n.Permalink)} - + me := MenuEntry{Name: n.Title, Url: n.Url} if !me.IsSameResource(inme) { return false } diff --git a/hugolib/page.go b/hugolib/page.go index 67a6842c1..6e4c887a1 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -473,7 +473,7 @@ func (page *Page) Menus() PageMenus { ret := PageMenus{} if ms, ok := page.Params["menu"]; ok { - link, _ := page.Permalink() + link, _ := page.RelPermalink() me := MenuEntry{Name: page.LinkTitle(), Weight: page.Weight, Url: link} diff --git a/hugolib/site.go b/hugolib/site.go index b17a19280..d5385081b 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -532,10 +532,12 @@ func (s *Site) getMenusFromConfig() Menus { } menuEntry.MarshallMap(ime) + if strings.HasPrefix(menuEntry.Url, "/") { - // make it absolute so it matches the nodes - menuEntry.Url = s.permalinkStr(menuEntry.Url) + // make it match the nodes + menuEntry.Url = s.prepUrl(menuEntry.Url) } + if ret[name] == nil { ret[name] = &Menu{} }