mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Database gallery view https://github.com/siyuan-note/siyuan/issues/10414
This commit is contained in:
parent
ecd8dd66b9
commit
5c95e9870a
2 changed files with 32 additions and 3 deletions
|
|
@ -72,7 +72,8 @@ type GalleryCard struct {
|
|||
ID string `json:"id"` // 卡片 ID
|
||||
Values []*GalleryFieldValue `json:"values"` // 卡片字段值
|
||||
|
||||
CoverURL string `json:"coverURL"` // 卡片封面超链接
|
||||
CoverURL string `json:"coverURL"` // 卡片封面超链接
|
||||
CoverContent string `json:"coverContent"` // 卡片封面文本内容
|
||||
}
|
||||
|
||||
// GalleryField 描述了画廊实例卡片字段的结构。
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/88250/lute/render"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -153,7 +156,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
|||
galleryCard.Values = append(galleryCard.Values, fieldValue)
|
||||
}
|
||||
|
||||
fillGalleryCardCover(attrView, view, cardValues, galleryCard, cardID)
|
||||
fillGalleryCardCover(attrView, view, cardValues, galleryCard, cardID, luteEngine)
|
||||
ret.Cards = append(ret.Cards, &galleryCard)
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +394,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
|||
return
|
||||
}
|
||||
|
||||
func fillGalleryCardCover(attrView *av.AttributeView, view *av.View, cardValues []*av.KeyValues, galleryCard av.GalleryCard, cardID string) {
|
||||
func fillGalleryCardCover(attrView *av.AttributeView, view *av.View, cardValues []*av.KeyValues, galleryCard av.GalleryCard, cardID string, luteEngine *lute.Lute) {
|
||||
switch view.Gallery.CoverFrom {
|
||||
case av.CoverFromNone:
|
||||
case av.CoverFromContentImage:
|
||||
|
|
@ -429,6 +432,16 @@ func fillGalleryCardCover(attrView *av.AttributeView, view *av.View, cardValues
|
|||
galleryCard.CoverURL = dest.TokensStr()
|
||||
return ast.WalkStop
|
||||
})
|
||||
|
||||
if "" == galleryCard.CoverURL {
|
||||
if ast.NodeDocument == node.Type {
|
||||
galleryCard.CoverContent = node.IALAttr("title")
|
||||
return
|
||||
}
|
||||
|
||||
galleryCard.CoverContent = renderBlockDOMByNode(node, luteEngine)
|
||||
return
|
||||
}
|
||||
}
|
||||
case av.CoverFromAssetField:
|
||||
if "" == view.Gallery.CoverFromAssetKeyID {
|
||||
|
|
@ -441,5 +454,20 @@ func fillGalleryCardCover(attrView *av.AttributeView, view *av.View, cardValues
|
|||
}
|
||||
|
||||
galleryCard.CoverURL = assetValue.MAsset[0].Content
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func renderBlockDOMByNode(node *ast.Node, luteEngine *lute.Lute) string {
|
||||
tree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}, Context: &parse.Context{ParseOption: luteEngine.ParseOptions}}
|
||||
blockRenderer := render.NewProtyleRenderer(tree, luteEngine.RenderOptions)
|
||||
ast.Walk(node, func(node *ast.Node, entering bool) ast.WalkStatus {
|
||||
rendererFunc := blockRenderer.RendererFuncs[node.Type]
|
||||
return rendererFunc(node, entering)
|
||||
})
|
||||
h := strings.TrimSpace(blockRenderer.Writer.String())
|
||||
if strings.HasPrefix(h, "<li") {
|
||||
h = "<ul>" + h + "</ul>"
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue