hugolib: Cast taxonomy weight parameters to int

Fixes #4628
This commit is contained in:
Cameron Moore 2018-10-02 20:54:36 -05:00 committed by Bjørn Erik Pedersen
parent 498d629958
commit 1fd30d462e
2 changed files with 9 additions and 6 deletions

View file

@ -1469,14 +1469,17 @@ func (s *Site) assembleTaxonomies() {
for _, p := range s.Pages { for _, p := range s.Pages {
vals := p.getParam(plural, !s.Info.preserveTaxonomyNames) vals := p.getParam(plural, !s.Info.preserveTaxonomyNames)
weight := p.getParamToLower(plural + "_weight")
if weight == nil { weight, err := cast.ToIntE(p.getParamToLower(plural + "_weight"))
weight = 0 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 vals != nil {
if v, ok := vals.([]string); ok { if v, ok := vals.([]string); ok {
for _, idx := range v { for _, idx := range v {
x := WeightedPage{weight.(int), p} x := WeightedPage{weight, p}
s.Taxonomies[plural].add(s.getTaxonomyKey(idx), x) s.Taxonomies[plural].add(s.getTaxonomyKey(idx), x)
if s.Info.preserveTaxonomyNames { if s.Info.preserveTaxonomyNames {
// Need to track the original // Need to track the original
@ -1484,7 +1487,7 @@ func (s *Site) assembleTaxonomies() {
} }
} }
} else if v, ok := vals.(string); ok { } else if v, ok := vals.(string); ok {
x := WeightedPage{weight.(int), p} x := WeightedPage{weight, p}
s.Taxonomies[plural].add(s.getTaxonomyKey(v), x) s.Taxonomies[plural].add(s.getTaxonomyKey(v), x)
if s.Info.preserveTaxonomyNames { if s.Info.preserveTaxonomyNames {
// Need to track the original // Need to track the original

View file

@ -823,7 +823,7 @@ tags = "a"
tags_weight = 33 tags_weight = 33
title = "bar" title = "bar"
categories = [ "d", "e" ] categories = [ "d", "e" ]
categories_weight = 11 categories_weight = 11.0
alias = "spf13" alias = "spf13"
date = 1979-05-27T07:32:00Z date = 1979-05-27T07:32:00Z
+++ +++