@@ -159,6 +159,8 @@ export function search(query) {
159
159
const post = data [ i ] ;
160
160
let matchesScore = 0 ;
161
161
let resultStr = '' ;
162
+ let handlePostTitle = '' ;
163
+ let handlePostContent = '' ;
162
164
const postTitle = post . title && post . title . trim ( ) ;
163
165
const postContent = post . body && post . body . trim ( ) ;
164
166
const postUrl = post . slug || '' ;
@@ -167,21 +169,23 @@ export function search(query) {
167
169
keywords . forEach ( keyword => {
168
170
// From https://github.com/sindresorhus/escape-string-regexp
169
171
const regEx = new RegExp (
170
- ignoreDiacriticalMarks ( keyword ) . replace (
172
+ escapeHtml ( ignoreDiacriticalMarks ( keyword ) ) . replace (
171
173
/ [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g,
172
174
'\\$&'
173
175
) ,
174
176
'gi'
175
177
) ;
176
178
let indexTitle = - 1 ;
177
179
let indexContent = - 1 ;
180
+ handlePostTitle = postTitle
181
+ ? escapeHtml ( ignoreDiacriticalMarks ( postTitle ) )
182
+ : postTitle ;
183
+ handlePostContent = postContent
184
+ ? escapeHtml ( ignoreDiacriticalMarks ( postContent ) )
185
+ : postContent ;
178
186
179
- indexTitle = postTitle
180
- ? ignoreDiacriticalMarks ( postTitle ) . search ( regEx )
181
- : - 1 ;
182
- indexContent = postContent
183
- ? ignoreDiacriticalMarks ( postContent ) . search ( regEx )
184
- : - 1 ;
187
+ indexTitle = postTitle ? handlePostTitle . search ( regEx ) : - 1 ;
188
+ indexContent = postContent ? handlePostContent . search ( regEx ) : - 1 ;
185
189
186
190
if ( indexTitle >= 0 || indexContent >= 0 ) {
187
191
matchesScore += indexTitle >= 0 ? 3 : indexContent >= 0 ? 2 : 0 ;
@@ -201,7 +205,7 @@ export function search(query) {
201
205
202
206
const matchContent =
203
207
'...' +
204
- escapeHtml ( ignoreDiacriticalMarks ( postContent ) )
208
+ handlePostContent
205
209
. substring ( start , end )
206
210
. replace (
207
211
regEx ,
@@ -215,7 +219,7 @@ export function search(query) {
215
219
216
220
if ( matchesScore > 0 ) {
217
221
const matchingPost = {
218
- title : escapeHtml ( ignoreDiacriticalMarks ( postTitle ) ) ,
222
+ title : handlePostTitle ,
219
223
content : postContent ? resultStr : '' ,
220
224
url : postUrl ,
221
225
score : matchesScore ,
0 commit comments