fix bug wordcount (#654)

This commit is contained in:
nihaoa 2020-03-27 21:44:30 +08:00 committed by GitHub
parent e1cffe7827
commit eb2d49bfe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -57,6 +57,9 @@ module.exports = function (hexo) {
* Get the word count of a paragraph.
*/
hexo.extend.helper.register('word_count', function (content) {
if (typeof(content) == "undefined") {
return 0
}
content = content.replace(/<\/?[a-z][^>]*>/gi, '');
content = content.trim();
return content ? (content.match(/[\u00ff-\uffff]|[a-zA-Z]+/g) || []).length : 0;
@ -103,4 +106,4 @@ module.exports = function (hexo) {
hexo.extend.helper.register('hexo_version', function (data) {
return hexo.version;
});
}
}