diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index e0eccc1..fd8b4a0 100755 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -37,7 +37,7 @@ function generate_description() { function generate_keywords() { if (page.keywords && page.keywords.length > 0) { return ''; - } else if (page.tags && page.tags.length > 0) { + } else if (page.tags && Array.isArray(page.tags) && page.tags.length > 0) { return ''; } else if (config.keywords && config.keywords.length > 0) { return ''; diff --git a/scripts/generators/search.js b/scripts/generators/search.js index ea6cb15..3f349b1 100644 --- a/scripts/generators/search.js +++ b/scripts/generators/search.js @@ -43,14 +43,14 @@ hexo.extend.generator.register('search_json_generator', function (locals) { content = content.replace(/[\s]{2,}/g, ' ') temp_post.content = content.trim() } - if (post.tags && post.tags.length > 0) { + if (post.tags && Array.isArray(post.tags) && post.tags.length > 0) { var tags = [] post.tags.forEach(function (tag) { tags.push(tag.name) }) temp_post.tags = tags } - if (post.categories && post.categories.length > 0) { + if (post.categories && Array.isArray(post.categories) && post.categories.length > 0) { var categories = [] post.categories.forEach(function (cate) { categories.push(cate.name) @@ -78,4 +78,4 @@ hexo.extend.generator.register('search_json_generator', function (locals) { path: cfg.path, data: JSON.stringify(res) } -}) \ No newline at end of file +})