mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Make sorting lists by name/title case-insensitive (#2993)
* Make sort by order_* fields case-insensitive. * Sort internet radios by name case-insensitive
This commit is contained in:
parent
6408dda948
commit
c4b05dac28
9 changed files with 52 additions and 28 deletions
|
@ -3,6 +3,7 @@ package utils
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/deluan/sanitize"
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
)
|
||||
|
||||
|
@ -32,3 +33,13 @@ func LongestCommonPrefix(list []string) string {
|
|||
}
|
||||
return list[0]
|
||||
}
|
||||
|
||||
func SanitizeFieldForSorting(originalValue string) string {
|
||||
v := strings.TrimSpace(sanitize.Accents(originalValue))
|
||||
return strings.ToLower(v)
|
||||
}
|
||||
|
||||
func SanitizeFieldForSortingNoArticle(originalValue string) string {
|
||||
v := strings.TrimSpace(sanitize.Accents(originalValue))
|
||||
return strings.ToLower(NoArticle(v))
|
||||
}
|
||||
|
|
|
@ -35,6 +35,35 @@ var _ = Describe("Strings", func() {
|
|||
})
|
||||
})
|
||||
|
||||
Describe("sanitizeFieldForSorting", func() {
|
||||
BeforeEach(func() {
|
||||
conf.Server.IgnoredArticles = "The O"
|
||||
})
|
||||
It("sanitize accents", func() {
|
||||
Expect(SanitizeFieldForSorting("Céu")).To(Equal("ceu"))
|
||||
})
|
||||
It("removes articles", func() {
|
||||
Expect(SanitizeFieldForSorting("The Beatles")).To(Equal("the beatles"))
|
||||
})
|
||||
It("removes accented articles", func() {
|
||||
Expect(SanitizeFieldForSorting("Õ Blésq Blom")).To(Equal("o blesq blom"))
|
||||
})
|
||||
})
|
||||
Describe("SanitizeFieldForSortingNoArticle", func() {
|
||||
BeforeEach(func() {
|
||||
conf.Server.IgnoredArticles = "The O"
|
||||
})
|
||||
It("sanitize accents", func() {
|
||||
Expect(SanitizeFieldForSortingNoArticle("Céu")).To(Equal("ceu"))
|
||||
})
|
||||
It("removes articles", func() {
|
||||
Expect(SanitizeFieldForSortingNoArticle("The Beatles")).To(Equal("beatles"))
|
||||
})
|
||||
It("removes accented articles", func() {
|
||||
Expect(SanitizeFieldForSortingNoArticle("Õ Blésq Blom")).To(Equal("blesq blom"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("LongestCommonPrefix", func() {
|
||||
It("finds the longest common prefix", func() {
|
||||
Expect(LongestCommonPrefix(testPaths)).To(Equal("/Music/iTunes 1/iTunes Media/Music/"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue