Skip to content

Commit

Permalink
⚡ 修改文字计数逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zkqiang committed Aug 29, 2022
1 parent 105eb5b commit 9d35ff3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions scripts/helpers/wordcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
const { stripHTML } = require('hexo-util');

const getWordCount = (post) => {
if (!post.wordcount) {
post.wordcount = stripHTML(post.content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '').length;
}
return post.wordcount;
};

Expand Down Expand Up @@ -32,10 +35,3 @@ hexo.extend.helper.register('wordtotal', (site) => {
});
return symbolsCount(count);
});

hexo.extend.filter.register('after_post_render', (page) => {
const meta = hexo.theme.config.post.meta;
if (meta.wordcount.enable || meta.min2read.enable) {
page.wordcount = stripHTML(page.content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '').length;
}
}, 0);

0 comments on commit 9d35ff3

Please sign in to comment.