Support site menu per language
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Sep 2016 18:41:52 +0000 (20:41 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Sep 2016 18:59:03 +0000 (20:59 +0200)
Fixes #2434

hugolib/hugo_sites_test.go
hugolib/site.go

index bae7c1e08a713ba1ecc57aabbdb4a5573cb713c3..41535fdf80863b24bb17b06cd1e136be0117ff94 100644 (file)
@@ -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": {
index d222e0c10f2e31f2e0cf2e7f5dff044daddae386..c46604422abb045fb6e6aea1c96b5dc9b1dedb0b 100644 (file)
@@ -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 {