From 91a068ff52ae9fc3512a7ab9cca44bcb3daefff8 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 5 Aug 2024 23:21:55 +0800 Subject: [PATCH] :art: Improve sort when importing markdown files https://github.com/siyuan-note/siyuan/issues/11390 --- kernel/model/import.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kernel/model/import.go b/kernel/model/import.go index 332d707df8a..a845070a018 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -680,7 +680,10 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) { } boxLocalPath = filepath.Join(util.DataDir, boxID) - if gulu.File.IsDir(localPath) { + hPathsIDs := map[string]string{} + idPaths := map[string]string{} + + if gulu.File.IsDir(localPath) { // 导入文件夹 // 收集所有资源文件 assets := map[string]string{} filelock.Walk(localPath, func(currentPath string, info os.FileInfo, walkErr error) error { @@ -843,6 +846,9 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) { reassignIDUpdated(tree) importTrees = append(importTrees, tree) + + hPathsIDs[tree.HPath] = tree.ID + idPaths[tree.ID] = tree.Path return nil }) } else { // 导入单个文件 @@ -953,6 +959,17 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) { importTrees = []*parse.Tree{} searchLinks = map[string]string{} + + // 按照路径排序 Improve sort when importing markdown files https://github.com/siyuan-note/siyuan/issues/11390 + var paths, hPaths []string + for hPath := range hPathsIDs { + hPaths = append(hPaths, hPath) + } + sort.Strings(hPaths) + for _, hPath := range hPaths { + paths = append(paths, idPaths[hPathsIDs[hPath]]) + } + ChangeFileTreeSort(boxID, paths) } IncSync()