fix: ensure tags and categories are arrays before iterating (#512)
This commit is contained in:
parent
0ca983f992
commit
9a96310660
|
@ -37,7 +37,7 @@ function generate_description() {
|
||||||
function generate_keywords() {
|
function generate_keywords() {
|
||||||
if (page.keywords && page.keywords.length > 0) {
|
if (page.keywords && page.keywords.length > 0) {
|
||||||
return '<meta name="keywords" content="' + page.keywords + '">';
|
return '<meta name="keywords" content="' + page.keywords + '">';
|
||||||
} else if (page.tags && page.tags.length > 0) {
|
} else if (page.tags && Array.isArray(page.tags) && page.tags.length > 0) {
|
||||||
return '<meta name="keywords" content="' + page.tags.map(tag => tag.name).join(',') + '">';
|
return '<meta name="keywords" content="' + page.tags.map(tag => tag.name).join(',') + '">';
|
||||||
} else if (config.keywords && config.keywords.length > 0) {
|
} else if (config.keywords && config.keywords.length > 0) {
|
||||||
return '<meta name="keywords" content="' + config.keywords + '">';
|
return '<meta name="keywords" content="' + config.keywords + '">';
|
||||||
|
|
|
@ -43,14 +43,14 @@ hexo.extend.generator.register('search_json_generator', function (locals) {
|
||||||
content = content.replace(/[\s]{2,}/g, ' ')
|
content = content.replace(/[\s]{2,}/g, ' ')
|
||||||
temp_post.content = content.trim()
|
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 = []
|
var tags = []
|
||||||
post.tags.forEach(function (tag) {
|
post.tags.forEach(function (tag) {
|
||||||
tags.push(tag.name)
|
tags.push(tag.name)
|
||||||
})
|
})
|
||||||
temp_post.tags = tags
|
temp_post.tags = tags
|
||||||
}
|
}
|
||||||
if (post.categories && post.categories.length > 0) {
|
if (post.categories && Array.isArray(post.categories) && post.categories.length > 0) {
|
||||||
var categories = []
|
var categories = []
|
||||||
post.categories.forEach(function (cate) {
|
post.categories.forEach(function (cate) {
|
||||||
categories.push(cate.name)
|
categories.push(cate.name)
|
||||||
|
@ -78,4 +78,4 @@ hexo.extend.generator.register('search_json_generator', function (locals) {
|
||||||
path: cfg.path,
|
path: cfg.path,
|
||||||
data: JSON.stringify(res)
|
data: JSON.stringify(res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue