diff --git a/kernel/model/import.go b/kernel/model/import.go index ac67b8ce0..ad1c4234d 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 27c9b2bf1..1f8ffeb12 100644 --- a/kernel/treenode/tree.go +++ b/kernel/treenode/tree.go @@ -69,16 +69,13 @@ 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)) - ret := &parse.Tree{Root: root} - ret.Box = boxID - ret.Path = p - ret.HPath = hp + ret := &parse.Tree{Root: root, ID: id, Box: boxID, Path: p, 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)