summaryrefslogtreecommitdiffstats
path: root/hugolib/taxonomy.go
diff options
context:
space:
mode:
authorRobert Basic <robertbasic.com@gmail.com>2016-04-01 20:17:16 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-04-02 22:59:10 +0200
commit7d5c9fbf44ad9f2fd5baed405f79f2b132dd9178 (patch)
tree7f7c3b26d26beb5b196dc7f8b6fed733b90e3ef7 /hugolib/taxonomy.go
parentc6c2c689d602cf9d0a9bdf016e3a51a54030b072 (diff)
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
Diffstat (limited to 'hugolib/taxonomy.go')
-rw-r--r--hugolib/taxonomy.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/hugolib/taxonomy.go b/hugolib/taxonomy.go
index 1ba8f6d05..ffe586ffc 100644
--- a/hugolib/taxonomy.go
+++ b/hugolib/taxonomy.go
@@ -96,9 +96,16 @@ func (i Taxonomy) Alphabetical() OrderedTaxonomy {
}
// ByCount returns an ordered taxonomy sorted by # of pages per key.
+// If taxonomies have the same # of pages, sort them alphabetical
func (i Taxonomy) ByCount() OrderedTaxonomy {
count := func(i1, i2 *OrderedTaxonomyEntry) bool {
- return len(i1.WeightedPages) > len(i2.WeightedPages)
+ li1 := len(i1.WeightedPages)
+ li2 := len(i2.WeightedPages)
+
+ if li1 == li2 {
+ return i1.Name < i2.Name
+ }
+ return li1 > li2
}
ia := i.TaxonomyArray()