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