Procházet zdrojové kódy

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

Liang Ding před 2 roky
rodič
revize
7074aacacc
2 změnil soubory, kde provedl 6 přidání a 4 odebrání
  1. 4 2
      kernel/model/import.go
  2. 2 2
      kernel/treenode/tree.go

+ 4 - 2
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 {

+ 2 - 2
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)