mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
Section menu for the lazy blogger
The current menu system works great, but is too much work if all you want is a simple menu with the sections as menu items, and having these menu items connected to the pages in a way that enables setting the correct menu item as active for both the section lists and the pages itself. This commit adds a new option `SectionPagesMenu' which, if set, will create a new menu with that name with all the sections as menu items. The pages in the sections will behave as "shadow members" of these section items as `blogpage.HasMenuCurrent "sectionmenu" $sectionmenuitem` will return true. If a menu item with the same `identifier` is defined in site config, *that* item will take precedence.
This commit is contained in:
@@ -762,8 +762,25 @@ func (s *Site) assembleMenus() {
|
||||
}
|
||||
}
|
||||
|
||||
sectionPagesMenu := viper.GetString("SectionPagesMenu")
|
||||
sectionPagesMenus := make(map[string]interface{})
|
||||
//creating flat hash
|
||||
for _, p := range s.Pages {
|
||||
|
||||
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())}
|
||||
if _, ok := flat[twoD{sectionPagesMenu, me.KeyName()}]; ok {
|
||||
// menu with same id defined in config, let that one win
|
||||
continue
|
||||
}
|
||||
flat[twoD{sectionPagesMenu, me.KeyName()}] = &me
|
||||
sectionPagesMenus[p.Section()] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name, me := range p.Menus() {
|
||||
if _, ok := flat[twoD{name, me.KeyName()}]; ok {
|
||||
jww.ERROR.Printf("Two or more menu items have the same name/identifier in %q Menu. Identified as %q.\n Rename or set a unique identifier. \n", name, me.KeyName())
|
||||
|
Reference in New Issue
Block a user