diff --git a/kernel/model/blockial.go b/kernel/model/blockial.go index 9b78068e3..6a8e315fd 100644 --- a/kernel/model/blockial.go +++ b/kernel/model/blockial.go @@ -66,7 +66,7 @@ func SetBlockReminder(id string, timed string) (err error) { if ast.NodeDocument != node.Type && node.IsContainerBlock() { node = treenode.FirstLeafBlock(node) } - content := treenode.NodeStaticContent(node, nil, false, false) + content := treenode.NodeStaticContent(node, nil, false, false, false) content = gulu.Str.SubStr(content, 128) err = SetCloudBlockReminder(id, content, timedMills) if nil != err { diff --git a/kernel/model/render.go b/kernel/model/render.go index aeb3c4460..e63788643 100644 --- a/kernel/model/render.go +++ b/kernel/model/render.go @@ -93,7 +93,7 @@ func renderOutline(heading *ast.Node, luteEngine *lute.Lute) (ret string) { } func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) { - ret = treenode.NodeStaticContent(node, excludeTypes, false, false) + ret = treenode.NodeStaticContent(node, excludeTypes, false, false, false) ret = strings.TrimSpace(ret) ret = strings.ReplaceAll(ret, "\n", "") ret = util.EscapeHTML(ret) @@ -156,7 +156,7 @@ func renderBlockContentByNodes(nodes []*ast.Node) string { buf := bytes.Buffer{} for _, n := range subNodes { - buf.WriteString(treenode.NodeStaticContent(n, nil, false, false)) + buf.WriteString(treenode.NodeStaticContent(n, nil, false, false, false)) } return buf.String() } diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go index 34c9c23c5..72a0f2b2b 100644 --- a/kernel/model/virutalref.go +++ b/kernel/model/virutalref.go @@ -51,7 +51,7 @@ func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) { return ast.WalkContinue } - content := treenode.NodeStaticContent(n, nil, false, false) + content := treenode.NodeStaticContent(n, nil, false, false, false) buf.WriteString(content) return ast.WalkContinue }) diff --git a/kernel/sql/block.go b/kernel/sql/block.go index 6f44549cc..0ea18a54c 100644 --- a/kernel/sql/block.go +++ b/kernel/sql/block.go @@ -109,7 +109,7 @@ func indexNode(tx *sql.Tx, id string) (err error) { return } - content := treenode.NodeStaticContent(node, nil, true, indexAssetPath) + content := treenode.NodeStaticContent(node, nil, true, indexAssetPath, true) stmt := "UPDATE blocks SET content = ? WHERE id = ?" if err = execStmtTx(tx, stmt, content, id); nil != err { tx.Rollback() diff --git a/kernel/sql/database.go b/kernel/sql/database.go index 0880506e0..34ce78f07 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -801,13 +801,13 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes if !treenode.IsNodeOCRed(n) { util.PushNodeOCRQueue(n) } - content = treenode.NodeStaticContent(n, nil, true, indexAssetPath) + content = treenode.NodeStaticContent(n, nil, true, indexAssetPath, true) fc := treenode.FirstLeafBlock(n) if !treenode.IsNodeOCRed(fc) { util.PushNodeOCRQueue(fc) } - fcontent = treenode.NodeStaticContent(fc, nil, true, false) + fcontent = treenode.NodeStaticContent(fc, nil, true, false, true) parentID = n.Parent.ID // 将标题块作为父节点 @@ -820,7 +820,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes if !treenode.IsNodeOCRed(n) { util.PushNodeOCRQueue(n) } - content = treenode.NodeStaticContent(n, nil, true, indexAssetPath) + content = treenode.NodeStaticContent(n, nil, true, indexAssetPath, true) parentID = n.Parent.ID // 将标题块作为父节点 diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go index ee906e6f2..338fe2112 100644 --- a/kernel/treenode/node.go +++ b/kernel/treenode/node.go @@ -168,7 +168,7 @@ func IsNodeOCRed(node *ast.Node) (ret bool) { return } -func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath bool) string { +func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath, fullAttrView bool) string { if nil == node { return "" } @@ -178,7 +178,11 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi } if ast.NodeAttributeView == node.Type { - return getAttributeViewContent(node.AttributeViewID) + if fullAttrView { + return getAttributeViewContent(node.AttributeViewID) + } + + return getAttributeViewName(node.AttributeViewID) } buf := bytes.Buffer{} @@ -528,6 +532,28 @@ func GetAttributeViewName(avID string) (name string) { return } +func getAttributeViewName(avID string) (name string) { + if "" == avID { + return + } + + attrView, err := av.ParseAttributeView(avID) + if nil != err { + logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err) + return + } + + buf := bytes.Buffer{} + buf.WriteString(attrView.Name) + buf.WriteByte(' ') + for _, v := range attrView.Views { + buf.WriteString(v.Name) + buf.WriteByte(' ') + } + name = strings.TrimSpace(buf.String()) + return +} + func getAttributeViewContent(avID string) (content string) { if "" == avID { return