mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
🎨 Database gallery view https://github.com/siyuan-note/siyuan/issues/10414
This commit is contained in:
parent
e1c1c806d6
commit
0440d94f71
1 changed files with 49 additions and 42 deletions
|
|
@ -341,55 +341,62 @@ func fillGalleryCardCover(attrView *av.AttributeView, view *av.View, cardValues
|
||||||
case av.CoverFromNone:
|
case av.CoverFromNone:
|
||||||
case av.CoverFromContentImage:
|
case av.CoverFromContentImage:
|
||||||
blockValue := getBlockValue(cardValues)
|
blockValue := getBlockValue(cardValues)
|
||||||
if !blockValue.IsDetached {
|
if blockValue.IsDetached {
|
||||||
tree := loadTreeByBlockID(blockValue.BlockID)
|
break
|
||||||
if nil == tree {
|
}
|
||||||
break
|
|
||||||
}
|
tree := loadTreeByBlockID(blockValue.BlockID)
|
||||||
node := treenode.GetNodeInTree(tree, blockValue.BlockID)
|
if nil == tree {
|
||||||
if nil == node {
|
break
|
||||||
|
}
|
||||||
|
node := treenode.GetNodeInTree(tree, blockValue.BlockID)
|
||||||
|
if nil == node {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if ast.NodeDocument == node.Type {
|
||||||
|
if titleImg := treenode.GetDocTitleImgPath(node); "" != titleImg {
|
||||||
|
galleryCard.CoverURL = titleImg
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if titleImgCss := node.IALAttr("title-img"); strings.HasPrefix(titleImgCss, "background:") {
|
||||||
|
galleryCard.CoverURL = titleImgCss
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if !entering {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
if ast.NodeImage != n.Type {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
dest := n.ChildByType(ast.NodeLinkDest)
|
||||||
|
if nil == dest {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
galleryCard.CoverURL = dest.TokensStr()
|
||||||
|
return ast.WalkStop
|
||||||
|
})
|
||||||
|
|
||||||
|
if "" == galleryCard.CoverURL {
|
||||||
if ast.NodeDocument == node.Type {
|
if ast.NodeDocument == node.Type {
|
||||||
if titleImg := treenode.GetDocTitleImgPath(node); "" != titleImg {
|
node = node.FirstChild
|
||||||
galleryCard.CoverURL = titleImg
|
}
|
||||||
|
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
for c := node; nil != c; c = c.Next {
|
||||||
|
buf.WriteString(renderBlockDOMByNode(c, luteEngine))
|
||||||
|
if 1024*4 < buf.Len() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
galleryCard.CoverContent = buf.String()
|
||||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
return
|
||||||
if !entering {
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ast.NodeImage != n.Type {
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
dest := n.ChildByType(ast.NodeLinkDest)
|
|
||||||
if nil == dest {
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
galleryCard.CoverURL = dest.TokensStr()
|
|
||||||
return ast.WalkStop
|
|
||||||
})
|
|
||||||
|
|
||||||
if "" == galleryCard.CoverURL {
|
|
||||||
if ast.NodeDocument == node.Type {
|
|
||||||
node = node.FirstChild
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := bytes.Buffer{}
|
|
||||||
for c := node; nil != c; c = c.Next {
|
|
||||||
buf.WriteString(renderBlockDOMByNode(c, luteEngine))
|
|
||||||
if 1024*4 < buf.Len() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
galleryCard.CoverContent = buf.String()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case av.CoverFromAssetField:
|
case av.CoverFromAssetField:
|
||||||
if "" == view.Gallery.CoverFromAssetKeyID {
|
if "" == view.Gallery.CoverFromAssetKeyID {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue