Skip to content

Commit

Permalink
fix: Solved that localsearch throw error when post has code snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyib committed Oct 2, 2019
1 parent 5a46af3 commit 97fb081
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions layout/_third-party/search/localsearch.pug
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ script.
var title = (data.title && data.title.trim()) || '!{_p("post.untitled")}';
var titleLower = title && title.toLowerCase();
// 删除 HTML 标签 和 所有空白字符
var content = data.content && data.content.replace(/<[^>]+>|\s+/, '');
var content = data.content && data.content.replace(/<[^>]+>/g, '');
var contentLower = content && content.toLowerCase();
// 删除重复的 /
var postURL = data.url && decodeURI(data.url).replace(/\/{2,}/, '/');
var postURL = data.url && decodeURI(data.url).replace(/\/{2,}/g, '/');

// 标题中匹配到的关键词
var titleHitSlice = [];
Expand Down Expand Up @@ -136,10 +136,8 @@ script.
return result;
}

titleHitSlice = titleHitSlice.concat(
getIndexByword(keyword, titleLower, false, WEIGHT.title));
contentHitSlice = contentHitSlice.concat(
getIndexByword(keyword, contentLower, false, WEIGHT.content));
titleHitSlice = titleHitSlice.concat(getIndexByword(keyword, titleLower, false, WEIGHT.title));
contentHitSlice = contentHitSlice.concat(getIndexByword(keyword, contentLower, false, WEIGHT.content));
});

var hitTitle = titleHitSlice.length;
Expand Down

0 comments on commit 97fb081

Please sign in to comment.