mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
Make ByCount sort consistently
When two or more taxonomies have the same number of pages, sort them by name to have consistent ByCount sorting of taxonomies. Fixes #1930
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
c6c2c689d6
commit
7d5c9fbf44
@@ -16,6 +16,8 @@ package hugolib
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func TestSitePossibleTaxonomies(t *testing.T) {
|
||||
@@ -29,3 +31,29 @@ func TestSitePossibleTaxonomies(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestByCountOrderOfTaxonomies(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
taxonomies := make(map[string]string)
|
||||
|
||||
taxonomies["tag"] = "tags"
|
||||
taxonomies["category"] = "categories"
|
||||
|
||||
viper.Set("taxonomies", taxonomies)
|
||||
|
||||
site := new(Site)
|
||||
page, _ := NewPageFrom(strings.NewReader(pageYamlWithTaxonomiesA), "path/to/page")
|
||||
site.Pages = append(site.Pages, page)
|
||||
site.assembleTaxonomies()
|
||||
|
||||
st := make([]string, 0)
|
||||
for _, t := range site.Taxonomies["tags"].ByCount() {
|
||||
st = append(st, t.Name)
|
||||
}
|
||||
|
||||
if !compareStringSlice(st, []string{"a", "b", "c"}) {
|
||||
t.Fatalf("ordered taxonomies do not match [a, b, c]. Got: %s", st)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user