diff --git a/README_CN.md b/README_CN.md index 365aef0..7b6597f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -513,6 +513,14 @@ const notes = await api.runOnBackend(async () => { --- +# 0.58 升级到 0.59 之后版本的问题 + +## 字数统计组件报错 + +由于API变化,字数统计组件的代码需要修改,请将字数统计组件的代码替换为最新的 [word count 字数统计组件.js](https://github.com/Nriver/trilium-translation/blob/main/demo-cn/示例笔记%20-%20请不要删除/Trilium%20扩展/Trilium%20组件%20widget/word%20count%20字数统计组件.js) + +--- + # 关于本项目使用的字体 本项目使用的字体文件为免费字体. diff --git a/demo-cn.zip b/demo-cn.zip index c07fc67..a4817c5 100755 Binary files a/demo-cn.zip and b/demo-cn.zip differ diff --git "a/demo-cn/\347\244\272\344\276\213\347\254\224\350\256\260 - \350\257\267\344\270\215\350\246\201\345\210\240\351\231\244/Trilium \346\211\251\345\261\225/Trilium \347\273\204\344\273\266 widget/word count \345\255\227\346\225\260\347\273\237\350\256\241\347\273\204\344\273\266.js" "b/demo-cn/\347\244\272\344\276\213\347\254\224\350\256\260 - \350\257\267\344\270\215\350\246\201\345\210\240\351\231\244/Trilium \346\211\251\345\261\225/Trilium \347\273\204\344\273\266 widget/word count \345\255\227\346\225\260\347\273\237\350\256\241\347\273\204\344\273\266.js" index 8586d45..636e3cf 100644 --- "a/demo-cn/\347\244\272\344\276\213\347\254\224\350\256\260 - \350\257\267\344\270\215\350\246\201\345\210\240\351\231\244/Trilium \346\211\251\345\261\225/Trilium \347\273\204\344\273\266 widget/word count \345\255\227\346\225\260\347\273\237\350\256\241\347\273\204\344\273\266.js" +++ "b/demo-cn/\347\244\272\344\276\213\347\254\224\350\256\260 - \350\257\267\344\270\215\350\246\201\345\210\240\351\231\244/Trilium \346\211\251\345\261\225/Trilium \347\273\204\344\273\266 widget/word count \345\255\227\346\225\260\347\273\237\350\256\241\347\273\204\344\273\266.js" @@ -12,59 +12,57 @@ const TPL = `
-`; -class WordCountWidget extends api.TabAwareWidget { +class WordCountWidget extends api.NoteContextAwareWidget { get position() { return 100; } // higher value means position towards the bottom/right - + get parentWidget() { return 'center-pane'; } - + + isEnabled() { + // 只在有 "字数统计" 这个标签的笔记里才显示组件 + return super.isEnabled() + && this.note.type === 'text' + && this.note.hasLabel('字数统计'); + } + doRender() { this.$widget = $(TPL); this.$wordCount = this.$widget.find('.word-count'); this.$characterCount = this.$widget.find('.character-count'); return this.$widget; } - + async refreshWithNote(note) { - if (note.type !== 'text' || !note.hasLabel('字数统计')) { - // 只在有 "字数统计" 这个标签的笔记里才显示组件 - this.toggleInt(false); // 隐藏 - - return; - } - - this.toggleInt(true); // 显示 - const {content} = await note.getNoteComplement(); - + const text = $(content).text(); // get plain text only - + const counts = this.getCounts(text); this.$wordCount.text(counts.words); this.$characterCount.text(counts.characters); } - + getCounts(text) { const chunks = text .split(/[\s-+:,/\\]+/) .filter(chunk => chunk !== ''); - + let words; - + if (chunks.length === 1 && chunks[0] === '') { words = 0; } else { words = chunks.length; } - + const characters = chunks.join('').length; - + return {words, characters}; } - + async entitiesReloadedEvent({loadResults}) { if (loadResults.isNoteContentReloaded(this.noteId)) { this.refresh();