Fix IsMenuCurrent for SectionPagesMenu

Pretty sure it has worked at some point, but that PR probably has been rebased to pieces.

This refactors the fix by @dannys42 into a method, as this URL fix is applied several places.

Fixes #1114
This commit is contained in:
bep
2015-05-09 20:54:11 +02:00
parent bef0f281d1
commit be325a3088
3 changed files with 63 additions and 24 deletions

View File

@@ -724,16 +724,7 @@ func (s *Site) getMenusFromConfig() Menus {
}
menuEntry.MarshallMap(ime)
if strings.HasPrefix(menuEntry.URL, "/") {
// make it match the nodes
menuEntryURL := menuEntry.URL
menuEntryURL = helpers.URLizeAndPrep(menuEntryURL)
if !s.Info.canonifyURLs {
menuEntryURL = helpers.AddContextRoot(string(s.Info.BaseURL), menuEntryURL)
}
menuEntry.URL = menuEntryURL
}
menuEntry.URL = s.Info.createNodeMenuEntryURL(menuEntry.URL)
if ret[name] == nil {
ret[name] = &Menu{}
@@ -747,6 +738,20 @@ func (s *Site) getMenusFromConfig() Menus {
return ret
}
func (s *SiteInfo) createNodeMenuEntryURL(in string) string {
if !strings.HasPrefix(in, "/") {
return in
}
// make it match the nodes
menuEntryURL := in
menuEntryURL = helpers.URLizeAndPrep(menuEntryURL)
if !s.canonifyURLs {
menuEntryURL = helpers.AddContextRoot(string(s.BaseURL), menuEntryURL)
}
return menuEntryURL
}
func (s *Site) assembleMenus() {
type twoD struct {
@@ -770,7 +775,7 @@ func (s *Site) assembleMenus() {
if sectionPagesMenu != "" {
if _, ok := sectionPagesMenus[p.Section()]; !ok {
if p.Section() != "" {
me := MenuEntry{Identifier: p.Section(), Name: helpers.MakeTitle(p.Section()), URL: s.permalinkStr(p.Section())}
me := MenuEntry{Identifier: p.Section(), Name: helpers.MakeTitle(p.Section()), URL: s.Info.createNodeMenuEntryURL("/" + p.Section())}
if _, ok := flat[twoD{sectionPagesMenu, me.KeyName()}]; ok {
// menu with same id defined in config, let that one win
continue