diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 1c7c77895..d876c55df 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -165,13 +165,18 @@ export function search(query) { end = postContent.length; } - const matchContent = - '...' + - escapeHtml(postContent) - .substring(start, end) - .replace(regEx, `${keyword}`) + - '...'; - + let content = escapeHtml(postContent).substring(start, end); + let matchKeywords = content.match(regEx); + + matchKeywords = new Set(matchKeywords); + matchKeywords.forEach(keyword => { + content = content.replace( + new RegExp(keyword, 'g'), + `${keyword}` + ); + }); + + const matchContent = '...' + content + '...'; resultStr += matchContent; } });