🎨 Add "Content block" option in the preview area of the database gallery view https://github.com/siyuan-note/siyuan/issues/15155

This commit is contained in:
Daniel 2025-07-04 10:33:18 +08:00
parent e82fb3a3cf
commit cdc631da7f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 33 additions and 13 deletions

View file

@ -77,6 +77,7 @@ const (
CoverFromNone CoverFrom = iota // 无封面 CoverFromNone CoverFrom = iota // 无封面
CoverFromContentImage // 内容图 CoverFromContentImage // 内容图
CoverFromAssetField // 资源字段 CoverFromAssetField // 资源字段
CoverFromContentBlock // 内容块
) )
// ViewGalleryCardField 描述了画廊卡片字段的结构。 // ViewGalleryCardField 描述了画廊卡片字段的结构。

View file

@ -195,19 +195,7 @@ func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View
}) })
if "" == galleryCard.CoverURL { if "" == galleryCard.CoverURL {
isDoc := ast.NodeDocument == node.Type galleryCard.CoverContent = renderCoverContentBlock(node, luteEngine)
if isDoc {
node = node.FirstChild
}
buf := bytes.Buffer{}
for c := node; nil != c; c = c.Next {
buf.WriteString(renderBlockDOMByNode(c, luteEngine))
if !isDoc || 1024*4 < buf.Len() {
break
}
}
galleryCard.CoverContent = buf.String()
return return
} }
case av.CoverFromAssetField: case av.CoverFromAssetField:
@ -222,7 +210,38 @@ func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View
galleryCard.CoverURL = assetValue.MAsset[0].Content galleryCard.CoverURL = assetValue.MAsset[0].Content
return return
case av.CoverFromContentBlock:
blockValue := getBlockValue(cardValues)
if blockValue.IsDetached {
break
} }
tree := trees[blockValue.BlockID]
if nil == tree {
break
}
node := treenode.GetNodeInTree(tree, blockValue.BlockID)
if nil == node {
break
}
galleryCard.CoverContent = renderCoverContentBlock(node, luteEngine)
}
}
func renderCoverContentBlock(node *ast.Node, luteEngine *lute.Lute) string {
isDoc := ast.NodeDocument == node.Type
if isDoc {
node = node.FirstChild
}
buf := bytes.Buffer{}
for c := node; nil != c; c = c.Next {
buf.WriteString(renderBlockDOMByNode(c, luteEngine))
if !isDoc || 1024*4 < buf.Len() {
break
}
}
return buf.String()
} }
func renderBlockDOMByNode(node *ast.Node, luteEngine *lute.Lute) string { func renderBlockDOMByNode(node *ast.Node, luteEngine *lute.Lute) string {