Skip to content

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

:art: Export the binding block docs when exporting the doc where the database is located https://github.com/siyuan-note/siyuan/issues/11486 https://github.com/siyuan-note/siyuan/issues/11486

Danield84baabc332f
diff --git a/kernel/model/export.go b/kernel/model/export.go
index d5635a9428..00a008fd79 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -2527,9 +2527,65 @@ type refAsFootnotes struct {
func exportRefTrees(tree *parse.Tree) (ret map[string]*parse.Tree) {
ret = map[string]*parse.Tree{}
exportRefTrees0(tree, &ret)
+
+ attrViewDefTrees := map[string]*parse.Tree{}
+ exportAttributeViewRefTrees0(tree, &attrViewDefTrees)
+ for _, t := range attrViewDefTrees {
+ if nil == ret[t.ID] {
+ ret[t.ID] = t
+ }
+ }
return
}
+func exportAttributeViewRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree) {
+ // 导出数据库所在文档时一并导出绑定块所在文档
+ // Export the binding block docs when exporting the doc where the database is located https://github.com/siyuan-note/siyuan/issues/11486
+
+ if nil != (*retTrees)[tree.ID] {
+ return
+ }
+ (*retTrees)[tree.ID] = tree
+
+ ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
+ if !entering {
+ return ast.WalkContinue
+ }
+
+ if ast.NodeAttributeView == n.Type {
+ avID := n.AttributeViewID
+ if "" == avID {
+ return ast.WalkContinue
+ }
+
+ attrView, _ := av.ParseAttributeView(avID)
+ if nil == attrView {
+ return ast.WalkContinue
+ }
+
+ blockKeyValues := attrView.GetBlockKeyValues()
+ if nil == blockKeyValues {
+ return ast.WalkContinue
+ }
+
+ for _, val := range blockKeyValues.Values {
+ defBlock := treenode.GetBlockTree(val.BlockID)
+ if nil == defBlock {
+ continue
+ }
+
+ defTree, _ := LoadTreeByBlockID(defBlock.RootID)
+ if nil == defTree {
+ continue
+ }
+
+ exportAttributeViewRefTrees0(defTree, retTrees)
+ }
+ }
+ return ast.WalkContinue
+ })
+}
+
func exportRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree) {
if nil != (*retTrees)[tree.ID] {
return