An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049
Daniel776b4fd6ee66
diff --git a/kernel/av/av.go b/kernel/av/av.goindex 204b341e15..095492b809 100644--- a/kernel/av/av.go+++ b/kernel/av/av.go@@ -606,8 +606,9 @@ var ()const (- NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id- NodeAttrView = "custom-sy-av-view" // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443+ NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id+ NodeAttrView = "custom-sy-av-view" // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443+ NodeAttrViewStaticText = "custom-sy-av-s-text" // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049NodeAttrViewNames = "av-names" // 用于临时标记块所属的属性视图名称,空格分隔)diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex cb829e53ce..9899d58fbb 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -560,6 +560,13 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {// 先处理关联列、汇总列、创建时间列和更新时间列for _, kv := range keyValues {switch kv.Key.Type {+ case av.KeyTypeBlock: // 对于主键可能需要填充静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049+ if nil != kv.Values[0].Block {+ ial := sql.GetBlockAttrs(blockID)+ if v := ial[av.NodeAttrViewStaticText+"-"+attrView.ID]; "" != v {+ kv.Values[0].Block.Content = v+ }+ }case av.KeyTypeRollup:if nil == kv.Key.Rollup {break@@ -3099,8 +3106,13 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID string, valueDaunbindBlockAv(tx, avID, oldBoundBlockID)bindBlockAv(tx, avID, val.BlockID)} else { // 之前绑定的块和现在绑定的块一样- // 直接返回,因为锚文本不允许更改- return+ // 设置静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049+ node, tree, getErr := getNodeByBlockID(tx, val.BlockID)+ if nil != getErr || nil == node {+ return+ }++ updateBlockValueStaticText(node, tree, avID, strings.TrimSpace(val.Block.Content))}}}@@ -3269,6 +3281,21 @@ func bindBlockAv0(tx *Transaction, avID string, node *ast.Node, tree *parse.Treereturn}+func updateBlockValueStaticText(node *ast.Node, tree *parse.Tree, avID, text string) {+ attrs := parse.IAL2Map(node.KramdownIAL)+ attrs[av.NodeAttrViewStaticText+"-"+avID] = text+ var err error+ if nil != tree {+ err = setNodeAttrsWithTx(nil, node, tree, attrs)+ } else {+ err = setNodeAttrs(node, nil, attrs)+ }+ if err != nil {+ logging.LogWarnf("set node [%s] attrs failed: %s", node.ID, err)+ return+ }+}+func getNodeByBlockID(tx *Transaction, blockID string) (node *ast.Node, tree *parse.Tree, err error) {if nil != tx {tree, err = tx.loadTree(blockID)diff --git a/kernel/sql/av.go b/kernel/sql/av.goindex 16f1846fc1..97adf803f4 100644--- a/kernel/sql/av.go+++ b/kernel/sql/av.go@@ -195,6 +195,15 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query sfor _, row := range ret.Rows {for _, cell := range row.Cells {switch cell.ValueType {+ case av.KeyTypeBlock: // 对于主键可能需要填充静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049+ if nil != cell.Value.Block {+ for k, v := range ials[row.ID] {+ if k == av.NodeAttrViewStaticText+"-"+attrView.ID {+ cell.Value.Block.Content = v+ break+ }+ }+ }case av.KeyTypeRollup: // 渲染汇总列rollupKey, _ := attrView.GetKey(cell.Value.KeyID)if nil == rollupKey || nil == rollupKey.Rollup {