From eb2d49bfe4e4f360a4c2f2b893fd064bb08e27e6 Mon Sep 17 00:00:00 2001 From: nihaoa <32973375+yuanjh6@users.noreply.github.com> Date: Fri, 27 Mar 2020 21:44:30 +0800 Subject: [PATCH] fix bug wordcount (#654) --- includes/helpers/site.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/helpers/site.js b/includes/helpers/site.js index c29c187..1470f00 100644 --- a/includes/helpers/site.js +++ b/includes/helpers/site.js @@ -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; }); -} \ No newline at end of file +}