hugolib: Cast taxonomy weight parameters to int
authorCameron Moore <moorereason@gmail.com>
Wed, 3 Oct 2018 01:54:36 +0000 (20:54 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 3 Oct 2018 06:34:45 +0000 (09:34 +0300)
Fixes #4628

hugolib/site.go
hugolib/site_test.go

index 054656f7a1f4bebb845b42a0abb1956c5199028d..f7f84b47dec1360ee7fa9525549f2201c46f68be 100644 (file)
@@ -1469,14 +1469,17 @@ func (s *Site) assembleTaxonomies() {
 
                for _, p := range s.Pages {
                        vals := p.getParam(plural, !s.Info.preserveTaxonomyNames)
-                       weight := p.getParamToLower(plural + "_weight")
-                       if weight == nil {
-                               weight = 0
+
+                       weight, err := cast.ToIntE(p.getParamToLower(plural + "_weight"))
+                       if err != nil {
+                               s.Log.ERROR.Print("unable to convert taxonomy weight to int")
+                               // weight will equal zero, so let the flow continue
                        }
+
                        if vals != nil {
                                if v, ok := vals.([]string); ok {
                                        for _, idx := range v {
-                                               x := WeightedPage{weight.(int), p}
+                                               x := WeightedPage{weight, p}
                                                s.Taxonomies[plural].add(s.getTaxonomyKey(idx), x)
                                                if s.Info.preserveTaxonomyNames {
                                                        // Need to track the original
@@ -1484,7 +1487,7 @@ func (s *Site) assembleTaxonomies() {
                                                }
                                        }
                                } else if v, ok := vals.(string); ok {
-                                       x := WeightedPage{weight.(int), p}
+                                       x := WeightedPage{weight, p}
                                        s.Taxonomies[plural].add(s.getTaxonomyKey(v), x)
                                        if s.Info.preserveTaxonomyNames {
                                                // Need to track the original
index 2315af20919199b47f30fc1471e61d020984e3da..f775b0e79715b38686f99eee8f88ad60e6632543 100644 (file)
@@ -823,7 +823,7 @@ tags = "a"
 tags_weight = 33
 title = "bar"
 categories = [ "d", "e" ]
-categories_weight = 11
+categories_weight = 11.0
 alias = "spf13"
 date = 1979-05-27T07:32:00Z
 +++