mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🐛 The save path is incorrect when creating a sub-doc by ref in a doc with the same name Fix https://github.com/siyuan-note/siyuan/issues/8138
This commit is contained in:
parent
c7875757c0
commit
f3dd8e5315
4 changed files with 60 additions and 5 deletions
|
|
@ -32,13 +32,30 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func createDocsByHPath(boxID, hPath, content string) (id string, existed bool, err error) {
|
||||
func createDocsByHPath(boxID, hPath, content, parentID string) (id string, existed bool, err error) {
|
||||
hPath = strings.TrimSuffix(hPath, ".sy")
|
||||
pathBuilder := bytes.Buffer{}
|
||||
pathBuilder.WriteString("/")
|
||||
hPathBuilder := bytes.Buffer{}
|
||||
hPathBuilder.WriteString("/")
|
||||
|
||||
if "" != parentID {
|
||||
// The save path is incorrect when creating a sub-doc by ref in a doc with the same name https://github.com/siyuan-note/siyuan/issues/8138
|
||||
|
||||
// 在指定父文档 ID 的情况下优先查找父文档
|
||||
parentHPath, name := path.Split(hPath)
|
||||
parentHPath = strings.TrimSuffix(parentHPath, "/")
|
||||
preferredParent := treenode.GetBlockTreeRootByHPathPreferredParentID(boxID, parentHPath, parentID)
|
||||
if nil != preferredParent && preferredParent.ID == parentID {
|
||||
// 如果父文档存在且 ID 一致,则直接在父文档下创建
|
||||
id = ast.NewNodeID()
|
||||
p := strings.TrimSuffix(preferredParent.Path, ".sy") + "/" + id + ".sy"
|
||||
if _, err = createDoc(boxID, p, name, content); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parts := strings.Split(hPath, "/")[1:]
|
||||
for i, part := range parts {
|
||||
hPathBuilder.WriteString(part)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue