fix bug wordcount (#654)
This commit is contained in:
parent
e1cffe7827
commit
eb2d49bfe4
|
@ -57,6 +57,9 @@ module.exports = function (hexo) {
|
||||||
* Get the word count of a paragraph.
|
* Get the word count of a paragraph.
|
||||||
*/
|
*/
|
||||||
hexo.extend.helper.register('word_count', function (content) {
|
hexo.extend.helper.register('word_count', function (content) {
|
||||||
|
if (typeof(content) == "undefined") {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
content = content.replace(/<\/?[a-z][^>]*>/gi, '');
|
content = content.replace(/<\/?[a-z][^>]*>/gi, '');
|
||||||
content = content.trim();
|
content = content.trim();
|
||||||
return content ? (content.match(/[\u00ff-\uffff]|[a-zA-Z]+/g) || []).length : 0;
|
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) {
|
hexo.extend.helper.register('hexo_version', function (data) {
|
||||||
return hexo.version;
|
return hexo.version;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue