├── .idea ├── .gitignore ├── misc.xml ├── vcs.xml ├── modules.xml ├── docsify-count.iml └── $PRODUCT_WORKSPACE_FILE$ ├── package.json ├── dist ├── countable.min.js └── countable.js └── README.MD /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/docsify-count.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/$PRODUCT_WORKSPACE_FILE$: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1.8 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docsify-count", 3 | "version": "1.2.0", 4 | "description": "a countable plugin for markdown", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build": "uglifyjs ./dist/countable.js -c -m -o ./dist/countable.min.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/827652549/docsify-count.git" 13 | }, 14 | "keywords": [ 15 | "countable", 16 | "words", 17 | "docsify", 18 | "plugin" 19 | ], 20 | "bugs": { 21 | "url": "https://github.com/mrpotatoes/docsify-count/issues" 22 | }, 23 | "homepage": "https://github.com/mrpotatoes/docsify-count", 24 | "author": "Junking", 25 | "license": "MIT" 26 | } 27 | -------------------------------------------------------------------------------- /dist/countable.min.js: -------------------------------------------------------------------------------- 1 | var defaultOptions={countable:!0,position:"top",margin:"10px",float:"right",fontsize:"0.9em",color:"rgb(90,90,90)",language:"english",localization:{words:"",minute:""},isExpected:!0};function plugin(t,n){if(!defaultOptions.countable)return;let o;t.beforeEach(function(t){return o=t.match(/([\u0800-\u4e00]+?|[\u4e00-\u9fa5]+?|[a-zA-Z0-9]+)/g).length,t}),t.afterEach(function(t,n){let i=o+" words",e=Math.ceil(o/400)+" min";"chinese"===defaultOptions.language?(i=o+" 字",e=Math.ceil(o/400)+" 分钟"):0!==defaultOptions.localization.words.length&&0!==defaultOptions.localization.minute.length&&(i=o+defaultOptions.localization.words,e=Math.ceil(o/400)+defaultOptions.localization.minute),n(`\n ${"bottom"===defaultOptions.position?t:""}\n
\n \n ${i}\n ${defaultOptions.isExpected?`  |  ${e}`:""}\n \n
\n
\n ${"bottom"!==defaultOptions.position?t:""}\n `)})}window.$docsify.count=Object.assign(defaultOptions,window.$docsify.count),window.$docsify.plugins=[].concat(plugin,window.$docsify.plugins); -------------------------------------------------------------------------------- /dist/countable.js: -------------------------------------------------------------------------------- 1 | //default values 2 | var defaultOptions = { 3 | countable: true, 4 | position: "top", 5 | margin: "10px", 6 | float: "right", 7 | fontsize: "0.9em", 8 | color: "rgb(90,90,90)", 9 | language: "english", 10 | localization: { 11 | words: "", 12 | minute: "", 13 | }, 14 | isExpected: true, 15 | } 16 | 17 | // Docsify plugin functions 18 | function plugin(hook, vm) { 19 | if (!defaultOptions.countable) { 20 | return 21 | } 22 | let wordsCount 23 | hook.beforeEach(function (content) { 24 | // Match regex every time you start parsing .md 25 | wordsCount = content.match( 26 | /([\u0800-\u4e00]+?|[\u4e00-\u9fa5]+?|[a-zA-Z0-9]+)/g 27 | ).length 28 | return content 29 | }) 30 | hook.afterEach(function (html, next) { 31 | // Support localization 32 | let str = wordsCount + " words" 33 | let readTime = Math.ceil(wordsCount / 400) + " min" 34 | if (defaultOptions.language === "chinese") { 35 | str = wordsCount + " 字" 36 | readTime = Math.ceil(wordsCount / 400) + " 分钟" 37 | } else if ( 38 | defaultOptions.localization.words.length !== 0 && 39 | defaultOptions.localization.minute.length !== 0 40 | ) { 41 | str = wordsCount + defaultOptions.localization.words 42 | readTime = 43 | Math.ceil(wordsCount / 400) + defaultOptions.localization.minute 44 | } 45 | 46 | //add html string 47 | next( 48 | ` 49 | ${defaultOptions.position === "bottom" ? html : ""} 50 |
53 | 57 | ${str} 58 | ${defaultOptions.isExpected ? `  |  ${readTime}` : ""} 59 | 60 |
61 |
62 | ${defaultOptions.position !== "bottom" ? html : ""} 63 | ` 64 | ) 65 | }) 66 | } 67 | 68 | // Docsify plugin options 69 | window.$docsify["count"] = Object.assign( 70 | defaultOptions, 71 | window.$docsify["count"] 72 | ) 73 | window.$docsify.plugins = [].concat(plugin, window.$docsify.plugins) 74 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # docsify-count 2 | 3 |

4 | 5 |
6 | docsify-count 7 |

8 | 9 | [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/docsify-count/badge)](https://www.jsdelivr.com/package/npm/docsify-count) 10 | 11 | This is a plugin to add word count for markdown files of docsify. 12 | 13 | > *这是一款为docsify提供文字统计的插件* 14 | 15 | It only counts Chinese characters and English words excludes special characters like `*`、`-`、…… in markdown file. 16 | 17 | > *它提供了统计中文汉字和英文单词的功能,并且排除了一些markdown语法的特殊字符例如`*`、`-`等* 18 | 19 | show count.english 20 | 21 | And you can set count.language 'chinese'/'english' 22 | 23 | show count.chinese 24 | 25 | ## To use 26 | 27 | Add JS 28 | 29 | ```html 30 | 31 | 32 | or 33 | 34 | 35 | ``` 36 | 37 | Add settings 38 | 39 | ```js 40 | window.$docsify = { 41 | count:{ 42 | countable: true, 43 | position: 'top', 44 | margin: '10px', 45 | float: 'right', 46 | fontsize:'0.9em', 47 | color:'rgb(90,90,90)', 48 | language:'chinese', 49 | localization: { 50 | words: "", 51 | minute: "" 52 | }, 53 | isExpected: true 54 | } 55 | } 56 | ``` 57 | 58 | | 属性名Attribute | 类型Type | 解释Description | 可选值Value | 59 | | --- | --- | --- | --- | 60 | | countable | boolean | 设置字符统计展示与否 Set display this plugin or not | true(默认值Default) / false | 61 | | position | string | 设置展示位置 Set display position | 'top'(默认值Default) / 'bottom' | 62 | | margin | string | 设置与邻近DOM的距离 Set margin to the near DOM element | '10px' | 63 | | float | string | 设置元素对齐 Set alignment | 'right'(默认值Default) / 'top' | 64 | | fontsize | string | 设置字体大小 Set font size | '0.9em' | 65 | | color | string | 设置颜色 Set color | 'rgb(90,90,90)' | 66 | | language | string | 设置语言 Set language | 'english'(默认值Default) / 'chinese' | 67 | | localization | Object | 支持本土化 Support localization | `words: ""`, `minute: ""` | 68 | | isExpected | boolean | 是否显示预计阅读时长 Display the reading time or not | true(默认值Default) / false | 69 | 70 | > `localization`的优先级高于`language`,如果`localization`的`words`和`minute`属性值不为空,则会取代`language`的作用。The priority of `localization` is higher than `language`'s. Thus, if the length of the value of `localization`'s attributes(`words`, `minutes`) were not equal with `0`, the function of `language` would be replaced. 71 | --------------------------------------------------------------------------------