Skip to content

Commit

Permalink
hugolib: Cast taxonomy weight parameters to int
Browse files Browse the repository at this point in the history
Fixes #4628
  • Loading branch information
moorereason authored and bep committed Oct 3, 2018
1 parent 498d629 commit 1fd30d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,22 +1469,25 @@ 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
s.taxonomiesOrigKey[fmt.Sprintf("%s-%s", plural, s.PathSpec.MakePathSanitized(idx))] = idx
}
}
} 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
Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
+++
Expand Down

0 comments on commit 1fd30d4

Please sign in to comment.