mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +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
|
|
@ -265,10 +265,6 @@
|
|||
"vLayout": "Vertical layout",
|
||||
"hLayout": "Horizontal layout",
|
||||
"merge": "Merge",
|
||||
"docWordCount": "Document words",
|
||||
"blockWordCount": "Block words",
|
||||
"docRuneCount": "Document characters",
|
||||
"blockRuneCount": "Block characters",
|
||||
"wordCount": "Words",
|
||||
"runeCount": "Characters",
|
||||
"kbd": "Keyboard",
|
||||
|
|
@ -733,6 +729,8 @@
|
|||
"italic": "Italic",
|
||||
"line": "Divider",
|
||||
"link": "Link",
|
||||
"image": "Image",
|
||||
"ref": "Ref",
|
||||
"list": "List",
|
||||
"more": "More",
|
||||
"nameEmpty": "Name is empty",
|
||||
|
|
|
|||
|
|
@ -265,10 +265,6 @@
|
|||
"vLayout": "Diseño vertical",
|
||||
"hLayout": "Diseño horizontal",
|
||||
"merge": "Fusionar",
|
||||
"docWordCount": "Palabras del documento",
|
||||
"blockWordCount": "Palabras del bloque",
|
||||
"docRuneCount": "Caracteres del documento",
|
||||
"blockRuneCount": "Caracteres del bloque",
|
||||
"wordCount": "Palabras",
|
||||
"runeCount": "Caracteres",
|
||||
"kbd": "Teclado",
|
||||
|
|
@ -733,6 +729,8 @@
|
|||
"italic": "Cursiva",
|
||||
"line": "Divisor",
|
||||
"link": "Enlace",
|
||||
"imagen": "Imagen",
|
||||
"ref": "Ref",
|
||||
"list": "Lista",
|
||||
"more": "Más",
|
||||
"nameEmpty": "El nombre está vacío",
|
||||
|
|
|
|||
|
|
@ -265,10 +265,6 @@
|
|||
"vLayout": "Disposition verticale",
|
||||
"hLayout": "Horizontal horizontale",
|
||||
"merge": "Merge",
|
||||
"docWordCount": "Document words",
|
||||
"blockWordCount": "Mots de bloc",
|
||||
"docRuneCount": "Caractères des documents",
|
||||
"blockRuneCount": "Caractères de bloc",
|
||||
"wordCount": "Mots",
|
||||
"runeCount": "Caractères",
|
||||
"kbd": "Clavier",
|
||||
|
|
@ -733,6 +729,8 @@
|
|||
"italic": "Italique",
|
||||
"line": "Diviseur",
|
||||
"link": "Lien",
|
||||
"image": "Image",
|
||||
"ref": "Réf",
|
||||
"list": "Liste",
|
||||
"more": "Plus",
|
||||
"nameEmpty": "Nom est vide",
|
||||
|
|
|
|||
|
|
@ -265,10 +265,6 @@
|
|||
"vLayout": "垂直佈局",
|
||||
"hLayout": "水平佈局",
|
||||
"merge": "合併",
|
||||
"docWordCount": "文檔詞數",
|
||||
"blockWordCount": " 塊詞數",
|
||||
"docRuneCount": "文檔字數",
|
||||
"blockRuneCount": " 塊字數",
|
||||
"wordCount": "詞數",
|
||||
"runeCount": "字數",
|
||||
"kbd": "鍵盤",
|
||||
|
|
@ -733,6 +729,8 @@
|
|||
"italic": "斜體",
|
||||
"line": "分隔線",
|
||||
"link": "連結",
|
||||
"image": "圖片",
|
||||
"ref": "引用",
|
||||
"list": "無序列表",
|
||||
"more": "更多",
|
||||
"nameEmpty": "檔案名不能為空",
|
||||
|
|
|
|||
|
|
@ -265,10 +265,6 @@
|
|||
"vLayout": "垂直布局",
|
||||
"hLayout": "水平布局",
|
||||
"merge": "合并",
|
||||
"docWordCount": "文档词数",
|
||||
"blockWordCount": " 块词数",
|
||||
"docRuneCount": "文档字数",
|
||||
"blockRuneCount": " 块字数",
|
||||
"wordCount": "词数",
|
||||
"runeCount": "字数",
|
||||
"kbd": "键盘",
|
||||
|
|
@ -733,6 +729,8 @@
|
|||
"italic": "斜体",
|
||||
"line": "分隔线",
|
||||
"link": "链接",
|
||||
"image": "图片",
|
||||
"ref": "引用",
|
||||
"list": "无序列表",
|
||||
"more": "更多",
|
||||
"nameEmpty": "文件名不能为空",
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ export const progressStatus = (data: IWebSocketData) => {
|
|||
};
|
||||
|
||||
export const handleStatusbarCounter = (data: IWebSocketData) => {
|
||||
renderStatusbarCounter(data.data.runeCount, data.data.wordCount);
|
||||
renderStatusbarCounter(data.data);
|
||||
};
|
||||
|
||||
export const progressLoading = (data: IWebSocketData) => {
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ export const countSelectWord = (range: Range) => {
|
|||
const selectText = range.toString();
|
||||
if (selectText) {
|
||||
fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
|
||||
renderStatusbarCounter(response.data.runeCount, response.data.wordCount);
|
||||
renderStatusbarCounter(response.data);
|
||||
});
|
||||
} else {
|
||||
document.querySelector("#status .status__counter").innerHTML = "";
|
||||
|
|
@ -152,7 +152,7 @@ export const countBlockWord = (ids: string[]) => {
|
|||
}
|
||||
if (ids.length > 0) {
|
||||
fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
|
||||
renderStatusbarCounter(response.data.runeCount, response.data.wordCount);
|
||||
renderStatusbarCounter(response.data);
|
||||
});
|
||||
} else {
|
||||
document.querySelector("#status .status__counter").innerHTML = "";
|
||||
|
|
@ -160,10 +160,17 @@ export const countBlockWord = (ids: string[]) => {
|
|||
/// #endif
|
||||
};
|
||||
|
||||
export const renderStatusbarCounter = (runeCount: number, wordCount: number) => {
|
||||
document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>
|
||||
${runeCount}
|
||||
<span class="fn__space"></span>
|
||||
<span class="ft__on-surface">${window.siyuan.languages.wordCount}</span>
|
||||
${wordCount}<span class="fn__space"></span>`;
|
||||
export const renderStatusbarCounter = (stat: { runeCount: number, wordCount: number, linkCount: number, imageCount: number, refCount: number }) => {
|
||||
let html = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span> ${stat.runeCount}<span class="fn__space"></span>
|
||||
<span class="ft__on-surface">${window.siyuan.languages.wordCount}</span> ${stat.wordCount}<span class="fn__space"></span>`
|
||||
if (0 < stat.linkCount) {
|
||||
html += `<span class="ft__on-surface">${window.siyuan.languages.link}</span> ${stat.linkCount}<span class="fn__space"></span>`
|
||||
}
|
||||
if (0 < stat.imageCount) {
|
||||
html += `<span class="ft__on-surface">${window.siyuan.languages.image}</span> ${stat.imageCount}<span class="fn__space"></span>`
|
||||
}
|
||||
if (0 < stat.refCount) {
|
||||
html += `<span class="ft__on-surface">${window.siyuan.languages.ref}</span> ${stat.refCount}<span class="fn__space"></span>`
|
||||
}
|
||||
document.querySelector("#status .status__counter").innerHTML = html;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ export class Breadcrumb {
|
|||
if (cursorNodeElement) {
|
||||
id = cursorNodeElement.getAttribute("data-node-id");
|
||||
}
|
||||
fetchPost("/api/block/getBlockWordCount", {id: id || protyle.block.id}, (response) => {
|
||||
fetchPost("/api/block/getTreeStat", {id: id || protyle.block.id}, (response) => {
|
||||
window.siyuan.menus.menu.remove();
|
||||
|
||||
if (!protyle.contentElement.classList.contains("fn__none")) {
|
||||
|
|
@ -327,10 +327,11 @@ export class Breadcrumb {
|
|||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
type: "readonly",
|
||||
label: `<div class="fn__flex">${window.siyuan.languages.docRuneCount}<span class="fn__space fn__flex-1"></span>${response.data.rootBlockRuneCount}</div>
|
||||
<div class="fn__flex">${window.siyuan.languages.docWordCount}<span class="fn__space fn__flex-1"></span>${response.data.rootBlockWordCount}</div>
|
||||
<div class="fn__flex">${window.siyuan.languages.blockRuneCount}<span class="fn__space fn__flex-1"></span>${response.data.blockRuneCount}</div>
|
||||
<div class="fn__flex">${window.siyuan.languages.blockWordCount}<span class="fn__space fn__flex-1"></span>${response.data.blockWordCount}</div>`,
|
||||
label: `<div class="fn__flex">${window.siyuan.languages.runeCount}<span class="fn__space fn__flex-1"></span>${response.data.runeCount}</div>
|
||||
<div class="fn__flex">${window.siyuan.languages.wordCount}<span class="fn__space fn__flex-1"></span>${response.data.wordCount}</div>
|
||||
<div class="fn__flex">${window.siyuan.languages.link}<span class="fn__space fn__flex-1"></span>${response.data.linkCount}</div>
|
||||
<div class="fn__flex">${window.siyuan.languages.image}<span class="fn__space fn__flex-1"></span>${response.data.imageCount}</div>
|
||||
<div class="fn__flex">${window.siyuan.languages.ref}<span class="fn__space fn__flex-1"></span>${response.data.refCount}</div>`,
|
||||
}).element);
|
||||
window.siyuan.menus.menu.popup(position);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -157,11 +157,7 @@ func getContentWordCount(c *gin.Context) {
|
|||
}
|
||||
|
||||
content := arg["content"].(string)
|
||||
runeCount, wordCount := model.ContentWordCount(content)
|
||||
ret.Data = map[string]interface{}{
|
||||
"runeCount": runeCount,
|
||||
"wordCount": wordCount,
|
||||
}
|
||||
ret.Data = model.ContentStat(content)
|
||||
}
|
||||
|
||||
func getBlocksWordCount(c *gin.Context) {
|
||||
|
|
@ -178,14 +174,10 @@ func getBlocksWordCount(c *gin.Context) {
|
|||
for _, id := range idsArg {
|
||||
ids = append(ids, id.(string))
|
||||
}
|
||||
runeCount, wordCount := model.BlocksWordCount(ids)
|
||||
ret.Data = map[string]interface{}{
|
||||
"runeCount": runeCount,
|
||||
"wordCount": wordCount,
|
||||
}
|
||||
ret.Data = model.BlocksWordCount(ids)
|
||||
}
|
||||
|
||||
func getBlockWordCount(c *gin.Context) {
|
||||
func getTreeStat(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
|
|
@ -195,13 +187,7 @@ func getBlockWordCount(c *gin.Context) {
|
|||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
blockRuneCount, blockWordCount, rootBlockRuneCount, rootBlockWordCount := model.BlockWordCount(id)
|
||||
ret.Data = map[string]interface{}{
|
||||
"blockRuneCount": blockRuneCount,
|
||||
"blockWordCount": blockWordCount,
|
||||
"rootBlockRuneCount": rootBlockRuneCount,
|
||||
"rootBlockWordCount": rootBlockWordCount,
|
||||
}
|
||||
ret.Data = model.StatTree(id)
|
||||
}
|
||||
|
||||
func getRefText(c *gin.Context) {
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/block/getRefIDsByFileAnnotationID", model.CheckAuth, getRefIDsByFileAnnotationID)
|
||||
ginServer.Handle("POST", "/api/block/getBlockDefIDsByRefText", model.CheckAuth, getBlockDefIDsByRefText)
|
||||
ginServer.Handle("POST", "/api/block/getRefText", model.CheckAuth, getRefText)
|
||||
ginServer.Handle("POST", "/api/block/getBlockWordCount", model.CheckAuth, getBlockWordCount)
|
||||
ginServer.Handle("POST", "/api/block/getTreeStat", model.CheckAuth, getTreeStat)
|
||||
ginServer.Handle("POST", "/api/block/getBlocksWordCount", model.CheckAuth, getBlocksWordCount)
|
||||
ginServer.Handle("POST", "/api/block/getContentWordCount", model.CheckAuth, getContentWordCount)
|
||||
ginServer.Handle("POST", "/api/block/getRecentUpdatedBlocks", model.CheckAuth, getRecentUpdatedBlocks)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ require (
|
|||
github.com/88250/clipboard v0.1.5
|
||||
github.com/88250/css v0.1.2
|
||||
github.com/88250/gulu v1.2.3-0.20220929123404-da1dc91c9343
|
||||
github.com/88250/lute v1.7.5-0.20220928025238-bda91cbd4072
|
||||
github.com/88250/lute v1.7.5-0.20221001045738-06a8c2407d65
|
||||
github.com/88250/pdfcpu v0.3.13
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ConradIrwin/font v0.0.0-20210318200717-ce8d41cc0732
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ github.com/88250/gulu v1.2.3-0.20220929123404-da1dc91c9343 h1:GJxJRZmA8GkAiU3Gsw
|
|||
github.com/88250/gulu v1.2.3-0.20220929123404-da1dc91c9343/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
|
||||
github.com/88250/lute v1.7.5-0.20220928025238-bda91cbd4072 h1:0d7YXGtw2ybeGs6oClIFiKvTqySfJCu5SUdJJWil6MA=
|
||||
github.com/88250/lute v1.7.5-0.20220928025238-bda91cbd4072/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
|
||||
github.com/88250/lute v1.7.5-0.20221001045738-06a8c2407d65 h1:EyxFJkB2DXZrAzSaMPZhSs72NzEdsn4YNh/zmqat8IY=
|
||||
github.com/88250/lute v1.7.5-0.20221001045738-06a8c2407d65/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
|
||||
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
|
||||
github.com/88250/pdfcpu v0.3.13/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -31,9 +31,15 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func TreeStat(tree *parse.Tree) (runeCount, wordCount int) {
|
||||
runeCount, wordCount = tree.Root.ContentLen()
|
||||
return
|
||||
func StatTree(tree *parse.Tree) (ret *util.BlockStatResult) {
|
||||
runeCnt, wordCnt, linkCnt, imgCnt, refCnt := tree.Root.Stat()
|
||||
return &util.BlockStatResult{
|
||||
RuneCount: runeCnt,
|
||||
WordCount: wordCnt,
|
||||
LinkCount: linkCnt,
|
||||
ImageCount: imgCnt,
|
||||
RefCount: refCnt,
|
||||
}
|
||||
}
|
||||
|
||||
func NodeHash(node *ast.Node, tree *parse.Tree, luteEngine *lute.Lute) string {
|
||||
|
|
|
|||
|
|
@ -151,11 +151,16 @@ func PushStatusBar(msg string) {
|
|||
BroadcastByType("main", "statusbar", 0, msg, nil)
|
||||
}
|
||||
|
||||
func PushStatusBarCounter(runeCount, wordCount int) {
|
||||
BroadcastByType("main", "statusbarCounter", 0, "", map[string]interface{}{
|
||||
"runeCount": runeCount,
|
||||
"wordCount": wordCount},
|
||||
)
|
||||
type BlockStatResult struct {
|
||||
RuneCount int `json:"runeCount"`
|
||||
WordCount int `json:"wordCount"`
|
||||
LinkCount int `json:"linkCount"`
|
||||
ImageCount int `json:"imageCount"`
|
||||
RefCount int `json:"refCount"`
|
||||
}
|
||||
|
||||
func PushStatusBarCounter(stat *BlockStatResult) {
|
||||
BroadcastByType("main", "statusbarCounter", 0, "", stat)
|
||||
}
|
||||
|
||||
func ContextPushMsg(context map[string]interface{}, msg string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue