Ver Fonte

:art: Improve importing Markdown https://github.com/siyuan-note/siyuan/issues/13149

Daniel há 7 meses atrás
pai
commit
9681fe6d80
1 ficheiros alterados com 12 adições e 1 exclusões
  1. 12 1
      kernel/model/import.go

+ 12 - 1
kernel/model/import.go

@@ -752,7 +752,12 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
 
 			targetPath = strings.ReplaceAll(targetPath, ".sy/", "/")
 			targetPath += ".sy"
-			targetPaths[curRelPath] = targetPath
+			if _, ok := targetPaths[curRelPath]; !ok {
+				targetPaths[curRelPath] = targetPath
+			} else {
+				targetPath = targetPaths[curRelPath]
+				id = strings.TrimSuffix(path.Base(targetPath), ".sy")
+			}
 
 			if info.IsDir() {
 				if subMdFiles := util.GetFilePathsByExts(currentPath, []string{".md", ".markdown"}); 1 > len(subMdFiles) {
@@ -760,6 +765,12 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
 					return nil
 				}
 
+				// 如果当前文件夹路径下包含同名的 Markdown 文件,则不创建空文档 https://github.com/siyuan-note/siyuan/issues/13149
+				if gulu.File.IsExist(currentPath+".md") || gulu.File.IsExist(currentPath+".markdown") {
+					targetPaths[curRelPath+".md"] = targetPath
+					return nil
+				}
+
 				tree = treenode.NewTree(boxID, targetPath, hPath, title)
 				importTrees = append(importTrees, tree)
 				return nil