From a7dc3c082e3c1e6ae7349f8b59f0d40da1cae664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 12 Sep 2016 20:41:52 +0200 Subject: [PATCH] Support site menu per language Fixes #2434 --- hugolib/hugo_sites_test.go | 44 ++++++++++++++++++++++++++++++++++++++ hugolib/site.go | 4 ++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/hugolib/hugo_sites_test.go b/hugolib/hugo_sites_test.go index bae7c1e08..41535fdf8 100644 --- a/hugolib/hugo_sites_test.go +++ b/hugolib/hugo_sites_test.go @@ -322,6 +322,14 @@ func doTestMultiSitesBuild(t *testing.T, configContent, configSuffix string) { // Check that the drafts etc. are not built/processed/rendered. assertShouldNotBuild(t, sites) + // en and nn have custom site menus + require.Len(t, frSite.Menus, 0, "fr: "+configSuffix) + require.Len(t, enSite.Menus, 1, "en: "+configSuffix) + require.Len(t, nnSite.Menus, 1, "nn: "+configSuffix) + + require.Equal(t, "Home", enSite.Menus["main"].ByName()[0].Name) + require.Equal(t, "Heim", nnSite.Menus["main"].ByName()[0].Name) + } func TestMultiSitesRebuild(t *testing.T) { @@ -621,6 +629,10 @@ weight = 10 title = "English" [Languages.en.blackfriday] angledQuotes = false +[[Languages.en.menu.main]] +url = "/" +name = "Home" +weight = 0 [Languages.fr] weight = 20 @@ -633,6 +645,10 @@ weight = 30 title = "Nynorsk" [Languages.nn.Taxonomies] lag = "lag" +[[Languages.nn.menu.main]] +url = "/" +name = "Heim" +weight = 1 [Languages.nb] weight = 40 @@ -666,6 +682,11 @@ Languages: title: "English" blackfriday: angledQuotes: false + menu: + main: + - url: "/" + name: "Home" + weight: 0 fr: weight: 20 title: "Français" @@ -676,6 +697,11 @@ Languages: title: "Nynorsk" Taxonomies: lag: "lag" + menu: + main: + - url: "/" + name: "Heim" + weight: 1 nb: weight: 40 title: "Bokmål" @@ -708,6 +734,15 @@ var multiSiteJSONConfig = ` "title": "English", "blackfriday": { "angledQuotes": false + }, + "menu": { + "main": [ + { + "url": "/", + "name": "Home", + "weight": 0 + } + ] } }, "fr": { @@ -722,6 +757,15 @@ var multiSiteJSONConfig = ` "title": "Nynorsk", "Taxonomies": { "lag": "lag" + }, + "menu": { + "main": [ + { + "url": "/", + "name": "Heim", + "weight": 1 + } + ] } }, "nb": { diff --git a/hugolib/site.go b/hugolib/site.go index d222e0c10..c46604422 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1349,7 +1349,7 @@ func (s *Site) getMenusFromConfig() Menus { ret := Menus{} - if menus := viper.GetStringMap("menu"); menus != nil { + if menus := s.Language.GetStringMap("menu"); menus != nil { for name, menu := range menus { m, err := cast.ToSliceE(menu) if err != nil { @@ -1411,7 +1411,7 @@ func (s *Site) assembleMenus() { } } - sectionPagesMenu := viper.GetString("SectionPagesMenu") + sectionPagesMenu := s.Language.GetString("SectionPagesMenu") sectionPagesMenus := make(map[string]interface{}) //creating flat hash for _, p := range s.Pages {