Skip to content

Commit

Permalink
🎨 Improve sort when importing markdown files #11390
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Aug 5, 2024
1 parent a63c545 commit 91a068f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion kernel/model/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 { // 导入单个文件
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 91a068f

Please sign in to comment.