diff --git a/_config.butterfly.yml b/_config.butterfly.yml index 64a7cada..8c5c35b4 100644 --- a/_config.butterfly.yml +++ b/_config.butterfly.yml @@ -159,7 +159,7 @@ post_meta: date_type: created # created or updated or both 文章頁日期是創建日或者更新日或都顯示 date_format: date # date/relative 顯示日期還是相對日期 categories: true # true or false 文章頁是否顯示分類 - tags: true # true or false 文章頁是否顯示標籤 + tags: false # true or false 文章頁是否顯示標籤 label: true # true or false 顯示描述性文字 # wordcount (字數統計) diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 8c307075..0d0b5924 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1266,6 +1266,11 @@ "node": ">=12.4.0" } }, + "node_modules/hexo-wordcount": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/hexo-wordcount/-/hexo-wordcount-6.0.1.tgz", + "integrity": "sha512-tbo2P9xRWEKQmRf7+XuPjx9It1MnaE26nA+EEb2DN39gK1x+26W7Nm4Iyp4AugQjBWYYDx7OLn4gp1WFxQpQew==" + }, "node_modules/highlight.js": { "version": "11.6.0", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.6.0.tgz", diff --git a/node_modules/hexo-wordcount/README.md b/node_modules/hexo-wordcount/README.md new file mode 100644 index 00000000..c61a99ae --- /dev/null +++ b/node_modules/hexo-wordcount/README.md @@ -0,0 +1,111 @@ +# Hexo-WordCount + +[![npm](https://img.shields.io/npm/v/hexo-wordcount.svg?style=plastic)](https://npmjs.org/package/hexo-wordcount) [![npm](https://img.shields.io/npm/dm/hexo-wordcount.svg?style=plastic)](https://npmjs.org/package/hexo-wordcount) [![npm](https://img.shields.io/npm/dt/hexo-wordcount.svg?style=plastic)](https://npmjs.org/package/hexo-wordcount) + +## Installation + +```bash +yarn add hexo-wordcount +# or +npm i --save hexo-wordcount +``` + +## Usage + +### 字数统计 WordCount + + +```js +wordcount(post.content) +``` + +### 阅读时长预计 Min2Read + +```js +min2read(post.content) +``` + +设置阅读速度 Set Reading Speed: + +```js +min2read(post.content, {cn: 300, en: 160}) +// p.s. (v3.0.0 added) +``` + +### 总字数统计 TotalCount + +```js +totalcount(site) +``` + +## Demo + +### Swig + +Post Count: + +```swig + {{ wordcount(post.content) }} +``` + +Post Minutes to Read: + +```swig + {{ min2read(post.content) }} +``` + +Total Count: + +```swig + {{ totalcount(site) }} +``` + +### Ejs + +Post Count: + +```ejs + <%= wordcount(post.content) %> +``` + +Post Minutes to Read: + +```ejs + <%= min2read(post.content) %> +``` + +Total Count: + +```ejs + <%= totalcount(site) %> +``` + +### Jade + +Post Count: + +```jade + span.post-count= wordcount(post.content) +``` + +Post Minutes to Read: + +```jade + span.post-count= min2read(post.content) +``` + + +Total Count: + +```swig + span.post-count= totalcount(site) +``` + + +## LICENSE + +MIT + +Alipay Donation(通过支付宝捐赠): + +![qr](https://cloud.githubusercontent.com/assets/1890238/15489630/fccbb9cc-2193-11e6-9fed-b93c59d6ef37.png) diff --git a/node_modules/hexo-wordcount/index.js b/node_modules/hexo-wordcount/index.js new file mode 100644 index 00000000..9976b809 --- /dev/null +++ b/node_modules/hexo-wordcount/index.js @@ -0,0 +1,36 @@ +var util = require('hexo-util'); +var stripHTML = util.stripHTML; + +var counter = function (content) { + content = stripHTML(content); + const cn = (content.match(/[\u4E00-\u9FA5]/g) || []).length; + const en = (content.replace(/[\u4E00-\u9FA5]/g, '').match(/[a-zA-Z0-9_\u0392-\u03c9\u0400-\u04FF]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|[\u00E4\u00C4\u00E5\u00C5\u00F6\u00D6]+|\w+/g) || []).length; + return [cn, en]; +}; + +hexo.extend.helper.register('min2read', function (content, { cn = 300, en = 160 } = {}) { + var len = counter(content); + var readingTime = len[0] / cn + len[1] / en; + return readingTime < 1 ? '1' : parseInt(readingTime, 10); +}); + +hexo.extend.helper.register('wordcount', function (content) { + var len = counter(content); + var count = len[0] + len[1]; + if (count < 1000) { + return count; + } + return Math.round(count / 100) / 10 + 'k'; +}); + +hexo.extend.helper.register('totalcount', function (site) { + var count = 0; + site.posts.forEach(function (post) { + var len = counter(post.content); + count += len[0] + len[1]; + }); + if (count < 1000) { + return count; + } + return Math.round(count / 100) / 10 + 'k'; +}); diff --git a/node_modules/hexo-wordcount/package.json b/node_modules/hexo-wordcount/package.json new file mode 100644 index 00000000..2b32de5b --- /dev/null +++ b/node_modules/hexo-wordcount/package.json @@ -0,0 +1,22 @@ +{ + "name": "hexo-wordcount", + "version": "6.0.1", + "description": "Post Word Count Plugin of Hexo.", + "main": "index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/willin/hexo-wordcount.git" + }, + "homepage": "https://github.com/willin/hexo-wordcount", + "keywords": [ + "hexo", + "wordcount", + "count" + ], + "author": { + "name": "Willin Wang", + "email": "willin@willin.org", + "url": "http://willin.wang" + }, + "license": "MIT" +} diff --git a/package-lock.json b/package-lock.json index 00239041..e39bbf86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,8 @@ "hexo-renderer-pug": "^3.0.0", "hexo-renderer-stylus": "^2.1.0", "hexo-server": "^3.0.0", - "hexo-theme-landscape": "^0.0.3" + "hexo-theme-landscape": "^0.0.3", + "hexo-wordcount": "^6.0.1" } }, "node_modules/@babel/helper-string-parser": { @@ -1297,6 +1298,11 @@ "node": ">=12.4.0" } }, + "node_modules/hexo-wordcount": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/hexo-wordcount/-/hexo-wordcount-6.0.1.tgz", + "integrity": "sha512-tbo2P9xRWEKQmRf7+XuPjx9It1MnaE26nA+EEb2DN39gK1x+26W7Nm4Iyp4AugQjBWYYDx7OLn4gp1WFxQpQew==" + }, "node_modules/highlight.js": { "version": "11.6.0", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.6.0.tgz", @@ -3790,6 +3796,11 @@ "strip-indent": "^3.0.0" } }, + "hexo-wordcount": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/hexo-wordcount/-/hexo-wordcount-6.0.1.tgz", + "integrity": "sha512-tbo2P9xRWEKQmRf7+XuPjx9It1MnaE26nA+EEb2DN39gK1x+26W7Nm4Iyp4AugQjBWYYDx7OLn4gp1WFxQpQew==" + }, "highlight.js": { "version": "11.6.0", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.6.0.tgz", diff --git a/package.json b/package.json index b27a7538..92fdeff9 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "hexo-renderer-pug": "^3.0.0", "hexo-renderer-stylus": "^2.1.0", "hexo-server": "^3.0.0", - "hexo-theme-landscape": "^0.0.3" + "hexo-theme-landscape": "^0.0.3", + "hexo-wordcount": "^6.0.1" } }