mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 01:20:12 +01:00
🎨 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:
parent
e82fb3a3cf
commit
cdc631da7f
2 changed files with 33 additions and 13 deletions
|
|
@ -77,6 +77,7 @@ const (
|
|||
CoverFromNone CoverFrom = iota // 无封面
|
||||
CoverFromContentImage // 内容图
|
||||
CoverFromAssetField // 资源字段
|
||||
CoverFromContentBlock // 内容块
|
||||
)
|
||||
|
||||
// ViewGalleryCardField 描述了画廊卡片字段的结构。
|
||||
|
|
|
|||
|
|
@ -195,19 +195,7 @@ func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View
|
|||
})
|
||||
|
||||
if "" == galleryCard.CoverURL {
|
||||
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
|
||||
}
|
||||
}
|
||||
galleryCard.CoverContent = buf.String()
|
||||
galleryCard.CoverContent = renderCoverContentBlock(node, luteEngine)
|
||||
return
|
||||
}
|
||||
case av.CoverFromAssetField:
|
||||
|
|
@ -222,7 +210,38 @@ func fillAttributeViewGalleryCardCover(attrView *av.AttributeView, view *av.View
|
|||
|
||||
galleryCard.CoverURL = assetValue.MAsset[0].Content
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue