shithub: hugo

Download patch

ref: 1fd30d462ee7f67fde6f29d170af1d225258322b
parent: 498d6299581bead0f582431b8133d8b5f8760618
author: Cameron Moore <[email protected]>
date: Tue Oct 2 16:54:36 EDT 2018

hugolib: Cast taxonomy weight parameters to int

Fixes #4628

--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1469,14 +1469,17 @@
 
 		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 @@
 						}
 					}
 				} 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
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -823,7 +823,7 @@
 tags_weight = 33
 title = "bar"
 categories = [ "d", "e" ]
-categories_weight = 11
+categories_weight = 11.0
 alias = "spf13"
 date = 1979-05-27T07:32:00Z
 +++