Merge pull request #6149 from bep/sort-caseinsensitive

Implement lexicographically string sorting
This commit is contained in:
Bjørn Erik Pedersen 2019-08-01 10:19:19 +02:00 committed by GitHub
parent a4f96a9d8c
commit 53077b0da5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 246 additions and 34 deletions

View file

@ -15,6 +15,7 @@ package navigation
import (
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/compare"
"html/template"
"sort"
@ -159,10 +160,11 @@ func (by menuEntryBy) Sort(menu Menu) {
var defaultMenuEntrySort = func(m1, m2 *MenuEntry) bool {
if m1.Weight == m2.Weight {
if m1.Name == m2.Name {
c := compare.Strings(m1.Name, m2.Name)
if c == 0 {
return m1.Identifier < m2.Identifier
}
return m1.Name < m2.Name
return c < 0
}
if m2.Weight == 0 {
@ -205,7 +207,7 @@ func (m Menu) ByWeight() Menu {
// ByName sorts the menu by the name defined in the menu configuration.
func (m Menu) ByName() Menu {
title := func(m1, m2 *MenuEntry) bool {
return m1.Name < m2.Name
return compare.LessStrings(m1.Name, m2.Name)
}
menuEntryBy(title).Sort(m)