Skip to content

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

:bug: 导入 Markdown 文件夹后无法在其中继续导入 https://github.com/siyuan-note/siyuan/issues/7512

Liang Ding7074aacaccd8
diff --git a/kernel/model/import.go b/kernel/model/import.go
index ac67b8ce07..ad1c4234d8 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -509,8 +509,11 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
curRelPath := filepath.ToSlash(strings.TrimPrefix(currentPath, localPath))
targetPath := path.Join(baseTargetPath, id)
+ hPath := path.Join(baseHPath, filepath.ToSlash(strings.TrimPrefix(currentPath, localPath)))
+ hPath = strings.TrimSuffix(hPath, ext)
if "" == curRelPath {
curRelPath = "/"
+ hPath = "/" + title
} else {
dirPath := targetPaths[path.Dir(curRelPath)]
targetPath = path.Join(dirPath, id)
@@ -519,8 +522,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
targetPath = strings.ReplaceAll(targetPath, ".sy/", "/")
targetPath += ".sy"
targetPaths[curRelPath] = targetPath
- hPath := path.Join(baseHPath, filepath.ToSlash(strings.TrimPrefix(currentPath, localPath)))
- hPath = strings.TrimSuffix(hPath, ext)
+
if info.IsDir() {
tree = treenode.NewTree(boxID, targetPath, hPath, title)
if err = indexWriteJSONQueue(tree); nil != err {
diff --git a/kernel/treenode/tree.go b/kernel/treenode/tree.go
index 27c9b2bf1b..b2d1549bcb 100644
--- a/kernel/treenode/tree.go
+++ b/kernel/treenode/tree.go
@@ -69,7 +69,7 @@ func TreeRoot(node *ast.Node) *ast.Node {
func NewTree(boxID, p, hp, title string) *parse.Tree {
id := strings.TrimSuffix(path.Base(p), ".sy")
- root := &ast.Node{Type: ast.NodeDocument, ID: id}
+ root := &ast.Node{Type: ast.NodeDocument, ID: id, Spec: "1", Box: boxID, Path: p}
root.SetIALAttr("title", title)
root.SetIALAttr("id", id)
root.SetIALAttr("updated", util.TimeFromID(id))
@@ -78,7 +78,7 @@ func NewTree(boxID, p, hp, title string) *parse.Tree {
ret.Path = p
ret.HPath = hp
ret.Root.Spec = "1"
- newPara := &ast.Node{Type: ast.NodeParagraph, ID: ast.NewNodeID()}
+ newPara := &ast.Node{Type: ast.NodeParagraph, ID: ast.NewNodeID(), Box: boxID, Path: p}
newPara.SetIALAttr("id", newPara.ID)
newPara.SetIALAttr("updated", util.TimeFromID(newPara.ID))
ret.Root.AppendChild(newPara)