Skip to content

Commit 251f1c9

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

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

scripts/helpers/wordcount.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ const getWordCount = (post) => {
1010
const content = stripHTML(post.origin || post.content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '');
1111

1212
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-
}
13+
const zhCount = (content.match(/[\u4E00-\u9FA5]/g) || []).length;
14+
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;
15+
post.wordcount = zhCount + enCount
1816
}
1917
return post.wordcount;
2018
};

0 commit comments

Comments
 (0)