瀏覽代碼

:art: Subdocuments created by the database are not displayed in the doc tree https://github.com/siyuan-note/siyuan/issues/9091

Daniel 1 年之前
父節點
當前提交
756d1ed4c0
共有 3 個文件被更改,包括 24 次插入13 次删除
  1. 7 1
      kernel/api/filetree.go
  2. 13 8
      kernel/model/file.go
  3. 4 4
      kernel/model/path.go

+ 7 - 1
kernel/api/filetree.go

@@ -481,6 +481,12 @@ func createDocWithMd(c *gin.Context) {
 		parentID = parentIDArg.(string)
 	}
 
+	showInDocTree := true
+	showInDocTreeArg := arg["showInDocTree"]
+	if nil != showInDocTreeArg {
+		showInDocTree = showInDocTreeArg.(bool)
+	}
+
 	hPath := arg["path"].(string)
 	markdown := arg["markdown"].(string)
 
@@ -496,7 +502,7 @@ func createDocWithMd(c *gin.Context) {
 		hPath = "/" + hPath
 	}
 
-	id, err := model.CreateWithMarkdown(notebook, hPath, markdown, parentID)
+	id, err := model.CreateWithMarkdown(notebook, hPath, markdown, parentID, showInDocTree)
 	if nil != err {
 		ret.Code = -1
 		ret.Msg = err.Error()

+ 13 - 8
kernel/model/file.go

@@ -285,12 +285,12 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
 			}
 
 			parentDocPath := strings.TrimSuffix(file.path, "/") + ".sy"
-			subDocFile := box.Stat(parentDocPath)
-			if nil == subDocFile {
+			parentDocFile := box.Stat(parentDocPath)
+			if nil == parentDocFile {
 				continue
 			}
 			if ial := box.docIAL(parentDocPath); nil != ial {
-				doc := box.docFromFileInfo(subDocFile, ial)
+				doc := box.docFromFileInfo(parentDocFile, ial)
 				subFiles, err := os.ReadDir(filepath.Join(boxLocalPath, file.path))
 				if nil == err {
 					for _, subFile := range subFiles {
@@ -313,6 +313,7 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
 					docs = append(docs, doc)
 				}
 			}
+
 			continue
 		}
 
@@ -992,7 +993,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree
 
 	luteEngine := util.NewLute()
 	dom := luteEngine.Md2BlockDOM(md, false)
-	tree, err = createDoc(box.ID, p, title, dom)
+	tree, err = createDoc(box.ID, p, title, dom, true)
 	if nil != err {
 		return
 	}
@@ -1001,7 +1002,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree
 	return
 }
 
-func CreateWithMarkdown(boxID, hPath, md, parentID string) (id string, err error) {
+func CreateWithMarkdown(boxID, hPath, md, parentID string, showInDocTree bool) (id string, err error) {
 	box := Conf.Box(boxID)
 	if nil == box {
 		err = errors.New(Conf.Language(0))
@@ -1011,7 +1012,7 @@ func CreateWithMarkdown(boxID, hPath, md, parentID string) (id string, err error
 	WaitForWritingFiles()
 	luteEngine := util.NewLute()
 	dom := luteEngine.Md2BlockDOM(md, false)
-	id, _, err = createDocsByHPath(box.ID, hPath, dom, parentID)
+	id, _, err = createDocsByHPath(box.ID, hPath, dom, parentID, showInDocTree)
 	return
 }
 
@@ -1414,7 +1415,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
 		return
 	}
 
-	id, existed, err := createDocsByHPath(box.ID, hPath, "", "")
+	id, existed, err := createDocsByHPath(box.ID, hPath, "", "", true)
 	if nil != err {
 		return
 	}
@@ -1459,7 +1460,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
 	return
 }
 
-func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
+func createDoc(boxID, p, title, dom string, showInDocTree bool) (tree *parse.Tree, err error) {
 	title = gulu.Str.RemoveInvisible(title)
 	if 512 < utf8.RuneCountInString(title) {
 		// 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
@@ -1531,6 +1532,10 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
 		tree.Root.AppendChild(treenode.NewParagraph())
 	}
 
+	if !showInDocTree {
+		tree.Root.SetIALAttr("custom-hidden", "true")
+	}
+
 	transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}}
 	PerformTransactions(&[]*Transaction{transaction})
 	WaitForWritingFiles()

+ 4 - 4
kernel/model/path.go

@@ -33,7 +33,7 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 
-func createDocsByHPath(boxID, hPath, content, parentID string) (id string, existed bool, err error) {
+func createDocsByHPath(boxID, hPath, content, parentID string, showInDocTree bool) (id string, existed bool, err error) {
 	hPath = strings.TrimSuffix(hPath, ".sy")
 	pathBuilder := bytes.Buffer{}
 	pathBuilder.WriteString("/")
@@ -51,7 +51,7 @@ func createDocsByHPath(boxID, hPath, content, parentID string) (id string, exist
 			// 如果父文档存在且 ID 一致,则直接在父文档下创建
 			id = ast.NewNodeID()
 			p := strings.TrimSuffix(preferredParent.Path, ".sy") + "/" + id + ".sy"
-			if _, err = createDoc(boxID, p, name, content); nil != err {
+			if _, err = createDoc(boxID, p, name, content, showInDocTree); nil != err {
 				return
 			}
 		}
@@ -68,11 +68,11 @@ func createDocsByHPath(boxID, hPath, content, parentID string) (id string, exist
 			pathBuilder.WriteString(id)
 			docP := pathBuilder.String() + ".sy"
 			if isNotLast {
-				if _, err = createDoc(boxID, docP, part, ""); nil != err {
+				if _, err = createDoc(boxID, docP, part, "", showInDocTree); nil != err {
 					return
 				}
 			} else {
-				if _, err = createDoc(boxID, docP, part, content); nil != err {
+				if _, err = createDoc(boxID, docP, part, content, showInDocTree); nil != err {
 					return
 				}
 			}