Skip to content

Commit

Permalink
⚡ 简化字数统计
Browse files Browse the repository at this point in the history
  • Loading branch information
zkqiang committed Sep 25, 2024
1 parent 713700c commit 568cbf8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions scripts/helpers/wordcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
const { stripHTML } = require('hexo-util');

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

if (!post.wordcount) {
const zhCount = (content.match(/[\u4E00-\u9FA5]/g) || []).length;
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;
post.wordcount = zhCount + enCount
// post.origin is the original post content of hexo-blog-encrypt
const content = stripHTML(post.origin || post.content).replace(/[\s\r\n]/g, '');
post.wordcount = content.length;
}
return post.wordcount;
};
Expand Down

0 comments on commit 568cbf8

Please sign in to comment.