diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2014-10-18 20:25:10 +0200 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-11-01 22:34:49 -0400 |
commit | d013edb7f838b739db72530e06eb47721baec7b8 (patch) | |
tree | 4e1885e661e603f264b4fa9a3067f25754d96faf /hugolib/menu.go | |
parent | 2b412d4ac7fb143addf2bf5139de7ee903525b24 (diff) |
Implement HasMenuCurrent and IsMenuCurrent for Nodes
Prior to this commit, `HasMenuCurrent` and `IsMenuCurrent` on `Node` always returned false.
This made it hard (if possible at all) to mark the currently selected menu item/group for non-Page content (home page, category pages etc.), i.e. for menus defined in the site configuration.
This commit provides an implementation of these two methods.
Notable design choices:
* These menu items have a loose coupling to the the resources they navigate to; the `Url` is the best common identificator. To facilitate a consistent matching, and to get it in line with the menu items connected to `Page`, relative Urls (Urls starting with '/') for menu items in the site configuration are converted to permaLinks using the same rules used for others’.
* `IsMenuCurrent` only looks at the children of the current node; this is in line with the implementation on `Page`.
* Due to this loose coupling, `IsMenuCurrent` have to search downards in the tree to make sure that the node is inside the current menu. This could have been made simpler if it could answer `yes` to any match of any menu item matching the current resource.
This commit also adds a set of unit tests for the menu system.
Fixes #367
Diffstat (limited to 'hugolib/menu.go')
-rw-r--r-- | hugolib/menu.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/hugolib/menu.go b/hugolib/menu.go index 4092432c8..a32cf8f9a 100644 --- a/hugolib/menu.go +++ b/hugolib/menu.go @@ -67,6 +67,10 @@ func (me *MenuEntry) IsEqual(inme *MenuEntry) bool { return me.hopefullyUniqueId() == inme.hopefullyUniqueId() && me.Parent == inme.Parent } +func (me *MenuEntry) IsSameResource(inme *MenuEntry) bool { + return me.Url != "" && inme.Url != "" && me.Url == inme.Url +} + func (me *MenuEntry) MarshallMap(ime map[string]interface{}) { for k, v := range ime { loki := strings.ToLower(k) |