Pārlūkot izejas kodu

:art: Add statistics on selected blocks and total blocks https://github.com/siyuan-note/siyuan/issues/13235

Daniel 7 mēneši atpakaļ
vecāks
revīzija
14bb85017f

+ 1 - 0
app/appearance/langs/de_DE.json

@@ -805,6 +805,7 @@
   "linkCount": "Links",
   "imgCount": "Bilder",
   "refCount": "Referenzen",
+  "blockCount": "Blöcke",
   "kbd": "Tastatur",
   "errorStyle": "Fehlerstil",
   "successStyle": "Erfolg-Stil",

+ 1 - 0
app/appearance/langs/en_US.json

@@ -805,6 +805,7 @@
   "linkCount": "Links",
   "imgCount": "Images",
   "refCount": "Refs",
+  "blockCount": "Blocks",
   "kbd": "Keyboard",
   "errorStyle": "Error Style",
   "successStyle": "Success Style",

+ 1 - 0
app/appearance/langs/es_ES.json

@@ -805,6 +805,7 @@
   "linkCount": "Enlaces",
   "imgCount": "Imágenes",
   "refCount": "Referencias",
+  "blockCount": "Bloques",
   "kbd": "Teclado",
   "errorStyle": "Estilo de error",
   "successStyle": "Estilo de éxito",

+ 1 - 0
app/appearance/langs/fr_FR.json

@@ -805,6 +805,7 @@
   "linkCount": "Liens",
   "imgCount": "Images",
   "refCount": "Réfs",
+  "blockCount": "Blocs",
   "kbd": "Clavier",
   "errorStyle": "Style d'Erreur",
   "successStyle": "Style de Réussite",

+ 1 - 0
app/appearance/langs/he_IL.json

@@ -805,6 +805,7 @@
   "linkCount": "קישורים",
   "imgCount": "תמונות",
   "refCount": "יחוסים",
+  "blockCount": "בלוקים",
   "kbd": "מקלדת",
   "errorStyle": "סגנון שגיאה",
   "successStyle": "סגנון הצלחה",

+ 1 - 0
app/appearance/langs/it_IT.json

@@ -805,6 +805,7 @@
   "linkCount": "Link",
   "imgCount": "Immagini",
   "refCount": "Riferimenti",
+  "blockCount": "Blocchi",
   "kbd": "Tastiera",
   "errorStyle": "Stile Errore",
   "successStyle": "Stile Successo",

+ 1 - 0
app/appearance/langs/ja_JP.json

@@ -805,6 +805,7 @@
   "linkCount": "リンク数",
   "imgCount": "画像数",
   "refCount": "参照数",
+  "blockCount": "ブロック",
   "kbd": "キーボード",
   "errorStyle": "エラースタイル",
   "successStyle": "成功スタイル",

+ 1 - 0
app/appearance/langs/pl_PL.json

@@ -805,6 +805,7 @@
   "linkCount": "Linki",
   "imgCount": "Obrazy",
   "refCount": "Refs",
+  "blockCount": "bloki",
   "kbd": "Klawiatura",
   "errorStyle": "Styl błędu",
   "successStyle": "Styl sukcesu",

+ 1 - 0
app/appearance/langs/ru_RU.json

@@ -805,6 +805,7 @@
   "linkCount": "Ссылки",
   "imgCount": "Изображения",
   "refCount": "Ссылки",
+  "blockCount": "блоки",
   "kbd": "Клавиатура",
   "errorStyle": "Стиль ошибки",
   "successStyle": "Стиль успеха",

+ 3 - 2
app/appearance/langs/zh_CHT.json

@@ -800,11 +800,12 @@
   "vLayout": "垂直佈局",
   "hLayout": "水平佈局",
   "merge": "合併",
-  "wordCount": "字",
-  "runeCount": "字符",
+  "wordCount": "字",
+  "runeCount": "字符",
   "linkCount": "連結",
   "imgCount": "圖片",
   "refCount": "引用",
+  "blockCount": "塊",
   "kbd": "鍵盤",
   "errorStyle": "錯誤樣式",
   "successStyle": "成功樣式",

+ 3 - 2
app/appearance/langs/zh_CN.json

@@ -800,11 +800,12 @@
   "vLayout": "垂直布局",
   "hLayout": "水平布局",
   "merge": "合并",
-  "wordCount": "字",
-  "runeCount": "字符",
+  "wordCount": "字",
+  "runeCount": "字符",
   "linkCount": "链接",
   "imgCount": "图片",
   "refCount": "引用",
+  "blockCount": "块",
   "kbd": "键盘",
   "errorStyle": "错误样式",
   "successStyle": "成功样式",

+ 4 - 1
app/src/layout/status.ts

@@ -194,7 +194,8 @@ export const renderStatusbarCounter = (stat: {
     wordCount: number,
     linkCount: number,
     imageCount: number,
-    refCount: number
+    refCount: number,
+    blockCount: number,
 }) => {
     if (!stat) {
         return;
@@ -209,6 +210,8 @@ export const renderStatusbarCounter = (stat: {
     }
     if (0 < stat.refCount) {
         html += `<span class="ft__on-surface">${window.siyuan.languages.refCount}</span>&nbsp;${stat.refCount}<span class="fn__space"></span>`;
+    }if (0 < stat.blockCount) {
+        html += `<span class="ft__on-surface">${window.siyuan.languages.blockCount}</span>&nbsp;${stat.blockCount}<span class="fn__space"></span>`;
     }
     document.querySelector("#status .status__counter").innerHTML = html;
 };

+ 1 - 1
app/src/protyle/breadcrumb/index.ts

@@ -576,7 +576,7 @@ ${padHTML}
                 iconHTML: "",
                 type: "readonly",
                 // 不能换行,否则移动端间距过大
-                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.linkCount}<span class="fn__space fn__flex-1"></span>${response.data.linkCount}</div><div class="fn__flex">${window.siyuan.languages.imgCount}<span class="fn__space fn__flex-1"></span>${response.data.imageCount}</div><div class="fn__flex">${window.siyuan.languages.refCount}<span class="fn__space fn__flex-1"></span>${response.data.refCount}</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.linkCount}<span class="fn__space fn__flex-1"></span>${response.data.linkCount}</div><div class="fn__flex">${window.siyuan.languages.imgCount}<span class="fn__space fn__flex-1"></span>${response.data.imageCount}</div><div class="fn__flex">${window.siyuan.languages.refCount}<span class="fn__space fn__flex-1"></span>${response.data.refCount}</div><div class="fn__flex">${window.siyuan.languages.blockCount}<span class="fn__space fn__flex-1"></span>${response.data.blockCount}</div>`,
             }).element);
             /// #if MOBILE
             window.siyuan.menus.menu.fullscreen();

+ 12 - 1
kernel/model/file.go

@@ -480,6 +480,7 @@ func BlocksWordCount(ids []string) (ret *util.BlockStatResult) {
 		ret.ImageCount += imgCnt
 		ret.RefCount += refCnt
 	}
+	ret.BlockCount = len(ids)
 	return
 }
 
@@ -491,9 +492,18 @@ func StatTree(id string) (ret *util.BlockStatResult) {
 		return
 	}
 
+	blockCount := 0
 	var databaseBlockNodes []*ast.Node
 	ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
-		if !entering || ast.NodeAttributeView != n.Type {
+		if !entering {
+			return ast.WalkContinue
+		}
+
+		if n.IsBlock() {
+			blockCount++
+		}
+
+		if ast.NodeAttributeView != n.Type {
 			return ast.WalkContinue
 		}
 
@@ -585,6 +595,7 @@ func StatTree(id string) (ret *util.BlockStatResult) {
 		LinkCount:  linkCnt,
 		ImageCount: imgCnt,
 		RefCount:   refCnt,
+		BlockCount: blockCount,
 	}
 }
 

+ 1 - 0
kernel/util/websocket.go

@@ -188,6 +188,7 @@ type BlockStatResult struct {
 	LinkCount  int `json:"linkCount"`
 	ImageCount int `json:"imageCount"`
 	RefCount   int `json:"refCount"`
+	BlockCount int `json:"blockCount"`
 }
 
 func ContextPushMsg(context map[string]interface{}, msg string) {