🐛 fix: 修復當menu沒設置圖標時,會報Cannot read property 'trim' of undefined 的bug

🐛 fix: 修復meta description 自動生成文章前200文字時部分沒有轉義的bug
This commit is contained in:
Jerry
2020-04-27 02:37:20 +08:00
parent 6cf59387c8
commit 92111f3c32
2 changed files with 9 additions and 6 deletions

View File

@@ -8,16 +8,16 @@
'use strict'
const { stripHTML } = require('hexo-util')
const { stripHTML, escapeHTML } = require('hexo-util')
hexo.extend.helper.register('page_description', function () {
const { config, page } = this
let description = page.description || page.content || page.title || config.description
if (description) {
description = stripHTML(description).substring(0, 200)
description = escapeHTML(stripHTML(description).substring(0, 200)
.trim()
.replace(/\n/g, ' ')
).replace(/\n/g, ' ')
return description
}
})