main
xuma 2 years ago
parent cf6b7a2932
commit 74d6dcbabb
  1. 2
      _config.butterfly.yml
  2. 5
      node_modules/.package-lock.json
  3. 111
      node_modules/hexo-wordcount/README.md
  4. 36
      node_modules/hexo-wordcount/index.js
  5. 22
      node_modules/hexo-wordcount/package.json
  6. 13
      package-lock.json
  7. 3
      package.json

@ -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 (字數統計)

5
node_modules/.package-lock.json generated vendored

@ -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",

@ -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
<span class="post-count">{{ wordcount(post.content) }}</span>
```
Post Minutes to Read:
```swig
<span class="post-count">{{ min2read(post.content) }}</span>
```
Total Count:
```swig
<span class="post-count">{{ totalcount(site) }}</span>
```
### Ejs
Post Count:
```ejs
<span class="post-count"><%= wordcount(post.content) %></span>
```
Post Minutes to Read:
```ejs
<span class="post-count"><%= min2read(post.content) %></span>
```
Total Count:
```ejs
<span class="post-count"><%= totalcount(site) %></span>
```
### 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)

@ -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';
});

@ -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"
}

13
package-lock.json generated

@ -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",

@ -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"
}
}

Loading…
Cancel
Save