feat: 优化stellar搜索引擎 (#538)

修复代码块行号开启时搜索到一串代码行号的bug,过滤HTML实体
This commit is contained in:
codepzj 2024-11-19 15:53:11 +08:00 committed by GitHub
parent 3812567f1c
commit f6027d6b85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -31,11 +31,13 @@ hexo.extend.generator.register('search_json_generator', function (locals) {
temp_post.path = root + post.path
}
if (cfg.content != false && post.content) {
var content = stripHTML(post.content).trim()
var content = stripHTML(post.content.replace(/<span class="line">\d+<\/span>/g, '')).trim()
// 部分HTML标签
content = content.replace(/<iframe[\s|\S]+iframe>/g, '')
content = content.replace(/<hr>/g, '')
content = content.replace(/<br>/g, '')
// 去除HTML实体
content = content.replace(/&[^\s;]+;/g, "")
// 换行符换成空格
content = content.replace(/\\n/g, ' ')
content = content.replace(/\n/g, ' ')