diff --git a/commands/hugo.go b/commands/hugo.go index f93e81982..0ad49bbe5 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -104,7 +104,7 @@ func init() { // This message will be shown to Windows users if Hugo is opened from explorer.exe cobra.MousetrapHelpText = ` - + Hugo is a command line tool You need to open cmd.exe and run it from there.` @@ -153,6 +153,7 @@ func InitializeConfig() { viper.SetDefault("PaginatePath", "page") viper.SetDefault("Blackfriday", helpers.NewBlackfriday()) viper.SetDefault("RSSUri", "index.xml") + viper.SetDefault("SectionPagesMenu", "") if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed { viper.Set("BuildDrafts", Draft) diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index d4d425d50..73aeb07dd 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/hugo/source" "github.com/spf13/viper" "github.com/stretchr/testify/assert" + "path/filepath" ) const ( @@ -90,9 +91,15 @@ weight = 3 Front Matter with Menu Pages`) var MENU_PAGE_SOURCES = []source.ByteSource{ - {"sect/doc1.md", MENU_PAGE_1}, - {"sect/doc2.md", MENU_PAGE_2}, - {"sect/doc3.md", MENU_PAGE_3}, + {filepath.FromSlash("sect/doc1.md"), MENU_PAGE_1}, + {filepath.FromSlash("sect/doc2.md"), MENU_PAGE_2}, + {filepath.FromSlash("sect/doc3.md"), MENU_PAGE_3}, +} + +var MENU_PAGE_SECTIONS_SOURCES = []source.ByteSource{ + {filepath.FromSlash("first/doc1.md"), MENU_PAGE_1}, + {filepath.FromSlash("first/doc2.md"), MENU_PAGE_2}, + {filepath.FromSlash("second-section/doc3.md"), MENU_PAGE_3}, } func tstCreateMenuPageWithNameTOML(title, menu, name string) []byte { diff --git a/hugolib/page.go b/hugolib/page.go index e53781b64..3ed12af6b 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -556,6 +556,12 @@ func (p *Page) GetParam(key string) interface{} { func (p *Page) HasMenuCurrent(menu string, me *MenuEntry) bool { menus := p.Menus() + sectionPagesMenu := viper.GetString("SectionPagesMenu") + + // page is labeled as "shadow-member" of the menu with the same identifier as the section + if sectionPagesMenu != "" && p.Section() != "" && sectionPagesMenu == menu && p.Section() == me.Identifier { + return true + } if m, ok := menus[menu]; ok { if me.HasChildren() { diff --git a/hugolib/site.go b/hugolib/site.go index 32d74dff9..c52c89e6d 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -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())