Skip to content

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

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

Daniel9681fe6d80f5
diff --git a/kernel/model/import.go b/kernel/model/import.go
index 2c2aa9c438..58956edcfd 100644
--- a/kernel/model/import.go
+++ b/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