Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve sort when importing markdown files https://github.com/siyuan-note/siyuan/issues/11390

Daniel91a068ff52ae
diff --git a/kernel/model/import.go b/kernel/model/import.go
index 332d707df8..a845070a01 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()