Skip to content

Commit c7a2ae1

Browse files
committed
🐛 字数统计合计中英文 #1024
1 parent 78ed005 commit c7a2ae1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

scripts/helpers/wordcount.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
const { stripHTML } = require('hexo-util');
66

77
const getWordCount = (post) => {
8-
const lang = post.lang.toLowerCase();
98
// post.origin is the original post content of hexo-blog-encrypt
109
const content = stripHTML(post.origin || post.content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '');
1110

1211
if (!post.wordcount) {
13-
if (['zh-cn', 'zh-hk', 'zh-tw'].includes(lang)) {
14-
post.wordcount = (content.match(/[\u4E00-\u9FA5]/g) || []).length;
15-
} else {
16-
post.wordcount = (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;
17-
}
12+
const zhCount = (content.match(/[\u4E00-\u9FA5]/g) || []).length;
13+
const enCount = (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;
14+
post.wordcount = zhCount + enCount
1815
}
1916
return post.wordcount;
2017
};

0 commit comments

Comments
 (0)