mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-24 07:54:07 +01:00
🧑💻 siyuan-note#12718 (#12723)
This commit is contained in:
parent
f965d6b91b
commit
7afea33d36
4 changed files with 157 additions and 15 deletions
|
|
@ -17,6 +17,7 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
|
@ -123,6 +124,85 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetDocsInfo(blockIDs []string, queryRefCount bool, queryAv bool) (rets []*BlockInfo) {
|
||||
WaitForWritingFiles()
|
||||
|
||||
trees := filesys.LoadTrees(blockIDs)
|
||||
for _, blockID := range blockIDs {
|
||||
tree := trees[blockID]
|
||||
if nil == tree {
|
||||
continue
|
||||
}
|
||||
title := tree.Root.IALAttr("title")
|
||||
ret := &BlockInfo{ID: blockID, RootID: tree.Root.ID, Name: title}
|
||||
ret.IAL = parse.IAL2Map(tree.Root.KramdownIAL)
|
||||
scrollData := ret.IAL["scroll"]
|
||||
if 0 < len(scrollData) {
|
||||
scroll := map[string]interface{}{}
|
||||
if parseErr := gulu.JSON.UnmarshalJSON([]byte(scrollData), &scroll); nil != parseErr {
|
||||
logging.LogWarnf("parse scroll data [%s] failed: %s", scrollData, parseErr)
|
||||
delete(ret.IAL, "scroll")
|
||||
} else {
|
||||
if zoomInId := scroll["zoomInId"]; nil != zoomInId {
|
||||
if !treenode.ExistBlockTree(zoomInId.(string)) {
|
||||
delete(ret.IAL, "scroll")
|
||||
}
|
||||
} else {
|
||||
if startId := scroll["startId"]; nil != startId {
|
||||
if !treenode.ExistBlockTree(startId.(string)) {
|
||||
delete(ret.IAL, "scroll")
|
||||
}
|
||||
}
|
||||
if endId := scroll["endId"]; nil != endId {
|
||||
if !treenode.ExistBlockTree(endId.(string)) {
|
||||
delete(ret.IAL, "scroll")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if queryRefCount {
|
||||
ret.RefIDs, _ = sql.QueryRefIDsByDefID(blockID, false)
|
||||
ret.RefCount = len(ret.RefIDs) // 填充块引计数
|
||||
}
|
||||
|
||||
if queryAv {
|
||||
// 填充属性视图角标 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545
|
||||
avIDs := strings.Split(ret.IAL[av.NodeAttrNameAvs], ",")
|
||||
for _, avID := range avIDs {
|
||||
avName, getErr := av.GetAttributeViewName(avID)
|
||||
if nil != getErr {
|
||||
continue
|
||||
}
|
||||
|
||||
if "" == avName {
|
||||
avName = Conf.language(105)
|
||||
}
|
||||
|
||||
attrView := &AttrView{ID: avID, Name: avName}
|
||||
ret.AttrViews = append(ret.AttrViews, attrView)
|
||||
}
|
||||
}
|
||||
|
||||
var subFileCount int
|
||||
boxLocalPath := filepath.Join(util.DataDir, tree.Box)
|
||||
subFiles, err := os.ReadDir(filepath.Join(boxLocalPath, strings.TrimSuffix(tree.Path, ".sy")))
|
||||
if err == nil {
|
||||
for _, subFile := range subFiles {
|
||||
if strings.HasSuffix(subFile.Name(), ".sy") {
|
||||
subFileCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
ret.SubFileCount = subFileCount
|
||||
ret.Icon = tree.Root.IALAttr("icon")
|
||||
|
||||
rets = append(rets, ret)
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetBlockRefText(id string) string {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue