mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-17 04:28:07 +01:00
🎨 文档信息统计增加超链接数、图片数、引用数和大小 https://github.com/siyuan-note/siyuan/issues/6037
This commit is contained in:
parent
a772b47287
commit
5e09d72fab
16 changed files with 86 additions and 86 deletions
|
|
@ -387,14 +387,21 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|||
return
|
||||
}
|
||||
|
||||
func ContentWordCount(content string) (runeCount, wordCount int) {
|
||||
func ContentStat(content string) (ret *util.BlockStatResult) {
|
||||
luteEngine := NewLute()
|
||||
tree := luteEngine.BlockDOM2Tree(content)
|
||||
runeCount, wordCount = tree.Root.ContentLen()
|
||||
return
|
||||
runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat()
|
||||
return &util.BlockStatResult{
|
||||
RuneCount: runeCnt,
|
||||
WordCount: wordCnt,
|
||||
LinkCount: linkCnt,
|
||||
ImageCount: imgCnt,
|
||||
RefCount: refCnt,
|
||||
}
|
||||
}
|
||||
|
||||
func BlocksWordCount(ids []string) (runeCount, wordCount int) {
|
||||
func BlocksWordCount(ids []string) (ret *util.BlockStatResult) {
|
||||
ret = &util.BlockStatResult{}
|
||||
trees := map[string]*parse.Tree{} // 缓存
|
||||
for _, id := range ids {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
|
|
@ -413,34 +420,30 @@ func BlocksWordCount(ids []string) (runeCount, wordCount int) {
|
|||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
blockRuneCount, blockWordCount := node.ContentLen()
|
||||
runeCount += blockRuneCount
|
||||
wordCount += blockWordCount
|
||||
runeCnt, wordCnt, linkCnt, imgCnt, refCnt := node.Stat()
|
||||
ret.RuneCount += runeCnt
|
||||
ret.WordCount += wordCnt
|
||||
ret.LinkCount += linkCnt
|
||||
ret.ImageCount += imgCnt
|
||||
ret.RefCount += refCnt
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func BlockWordCount(id string) (blockRuneCount, blockWordCount, rootBlockRuneCount, rootBlockWordCount int) {
|
||||
func StatTree(id string) (ret *util.BlockStatResult) {
|
||||
tree, _ := loadTreeByBlockID(id)
|
||||
if nil == tree {
|
||||
return
|
||||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
blockRuneCount, blockWordCount = node.ContentLen()
|
||||
if ast.NodeHeading == node.Type {
|
||||
level := node.HeadingLevel
|
||||
for n := node.Next; nil != n; n = n.Next {
|
||||
if ast.NodeHeading == n.Type && n.HeadingLevel <= level {
|
||||
break
|
||||
}
|
||||
rc, wc := n.ContentLen()
|
||||
blockRuneCount += rc
|
||||
blockWordCount += wc
|
||||
}
|
||||
runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat()
|
||||
return &util.BlockStatResult{
|
||||
RuneCount: runeCnt,
|
||||
WordCount: wordCnt,
|
||||
LinkCount: linkCnt,
|
||||
ImageCount: imgCnt,
|
||||
RefCount: refCnt,
|
||||
}
|
||||
rootBlockRuneCount, rootBlockWordCount = tree.Root.ContentLen()
|
||||
return
|
||||
}
|
||||
|
||||
func GetDoc(startID, endID, id string, index int, keyword string, mode int, size int) (blockCount, childBlockCount int, dom, parentID, parent2ID, rootID, typ string, eof bool, boxID, docPath string, err error) {
|
||||
|
|
|
|||
|
|
@ -1010,8 +1010,8 @@ func (tx *Transaction) commit() (err error) {
|
|||
}
|
||||
|
||||
func pushTreeStat(tree *parse.Tree) {
|
||||
runeCount, wordCount := treenode.TreeStat(tree)
|
||||
util.PushStatusBarCounter(runeCount, wordCount)
|
||||
stat := treenode.StatTree(tree)
|
||||
util.PushStatusBarCounter(stat)
|
||||
}
|
||||
|
||||
func (tx *Transaction) rollback() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue