mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
949a57d42e
4 changed files with 46 additions and 5 deletions
|
|
@ -148,11 +148,11 @@ func ListNotebooks() (ret []*Box, err error) {
|
|||
switch Conf.FileTree.Sort {
|
||||
case util.SortModeNameASC:
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return util.PinYinCompare(ret[i].Name, ret[j].Name)
|
||||
return util.PinYinCompare4FileTree(ret[i].Name, ret[j].Name)
|
||||
})
|
||||
case util.SortModeNameDESC:
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return util.PinYinCompare(ret[j].Name, ret[i].Name)
|
||||
return util.PinYinCompare4FileTree(ret[j].Name, ret[i].Name)
|
||||
})
|
||||
case util.SortModeAlphanumASC:
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
|
|
|
|||
|
|
@ -372,11 +372,11 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
|
|||
switch sortMode {
|
||||
case util.SortModeNameASC:
|
||||
sort.Slice(docs, func(i, j int) bool {
|
||||
return util.PinYinCompare(docs[i].Name, docs[j].Name)
|
||||
return util.PinYinCompare4FileTree(docs[i].Name, docs[j].Name)
|
||||
})
|
||||
case util.SortModeNameDESC:
|
||||
sort.Slice(docs, func(i, j int) bool {
|
||||
return util.PinYinCompare(docs[j].Name, docs[i].Name)
|
||||
return util.PinYinCompare4FileTree(docs[j].Name, docs[i].Name)
|
||||
})
|
||||
case util.SortModeUpdatedASC:
|
||||
sort.Slice(docs, func(i, j int) bool { return docs[i].Mtime < docs[j].Mtime })
|
||||
|
|
|
|||
|
|
@ -60,5 +60,12 @@ func GetRhyResult(force bool) (map[string]interface{}, error) {
|
|||
}
|
||||
|
||||
func RefreshRhyResultJob() {
|
||||
GetRhyResult(true)
|
||||
_, err := GetRhyResult(true)
|
||||
if nil != err {
|
||||
// 系统唤醒后可能还没有网络连接,这里等待后再重试
|
||||
go func() {
|
||||
time.Sleep(7 * time.Second)
|
||||
GetRhyResult(true)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,40 @@ func PinYinCompare(str1, str2 string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func PinYinCompare4FileTree(str1, str2 string) bool {
|
||||
// 文档树字母排序不复用 PinYinCompare 而是单独实现
|
||||
// Improve doc tree Name Alphabet sorting https://github.com/siyuan-note/siyuan/issues/14773
|
||||
|
||||
str1 = RemoveEmojiInvisible(str1)
|
||||
str1 = strings.TrimSuffix(str1, ".sy")
|
||||
str2 = RemoveEmojiInvisible(str2)
|
||||
str2 = strings.TrimSuffix(str2, ".sy")
|
||||
|
||||
// Doc tree, backlinks, tags and templates ignores case when sorting alphabetically by name https://github.com/siyuan-note/siyuan/issues/8360
|
||||
str1 = strings.ToLower(str1)
|
||||
str2 = strings.ToLower(str2)
|
||||
|
||||
a, _ := UTF82GBK(str1)
|
||||
b, _ := UTF82GBK(str2)
|
||||
|
||||
// 长度相等的情况下,直接比较字节数组
|
||||
if len(a) == len(b) {
|
||||
return bytes.Compare(a, b) < 0
|
||||
}
|
||||
|
||||
// 长度不相等的情况下,比较前面相等的部分
|
||||
if len(a) < len(b) {
|
||||
if 0 == bytes.Compare(a, b[:len(a)]) { // 前面相等的情况下,比较长度
|
||||
return len(a) > len(b[:len(a)])
|
||||
}
|
||||
return bytes.Compare(a, b[:len(a)]) < 0
|
||||
}
|
||||
if 0 == bytes.Compare(a[:len(b)], b) {
|
||||
return len(a[:len(b)]) > len(b)
|
||||
}
|
||||
return bytes.Compare(a[:len(b)], b) < 0
|
||||
}
|
||||
|
||||
// UTF82GBK transform UTF8 rune into GBK byte array.
|
||||
func UTF82GBK(src string) ([]byte, error) {
|
||||
GB18030 := simplifiedchinese.All[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue