@@ -257,12 +257,14 @@ export function genIndex(path, content = '', router, depth, indexKey) {
257257 indexKey : indexKey ,
258258 } ;
259259 } else {
260+ const codeText = token . type === 'code' ? token . text : null ;
261+
260262 if ( tokenIndex === 0 ) {
261263 slug = router . toURL ( path ) ;
262264 index [ slug ] = {
263265 slug,
264266 title : path !== '/' ? path . slice ( 1 ) : 'Home Page' ,
265- body : markdownToTxt ( /** @type { any } */ ( token ) . text || '' ) ,
267+ body : '' ,
266268 path : path ,
267269 indexKey : indexKey ,
268270 } ;
@@ -280,16 +282,17 @@ export function genIndex(path, content = '', router, depth, indexKey) {
280282 // @ts -expect-error
281283 token . text = getListData ( token ) ;
282284
283- // @ts -expect-error
284- index [ slug ] . body += '\n' + markdownToTxt ( token . text || '' ) ;
285+ index [ slug ] . body +=
286+ '\n' +
287+ ( codeText ?? markdownToTxt ( /** @type {any } */ ( token ) . text || '' ) ) ;
285288 } else {
286289 // @ts -expect-error
287290 token . text = getTableData ( token ) ;
288291 // @ts -expect-error
289292 token . text = getListData ( token ) ;
290293
291- // @ts -expect-error
292- index [ slug ] . body = markdownToTxt ( token . text || '' ) ;
294+ index [ slug ] . body =
295+ codeText ?? markdownToTxt ( /** @type { any } */ ( token ) . text || '' ) ;
293296 }
294297
295298 index [ slug ] . path = path ;
@@ -337,6 +340,11 @@ export function search(query) {
337340 const postUrl = post . slug || '' ;
338341
339342 if ( postTitle ) {
343+ handlePostTitle = escapeHtml ( ignoreDiacriticalMarks ( postTitle ) ) ;
344+ handlePostContent = postContent
345+ ? escapeHtml ( ignoreDiacriticalMarks ( postContent ) )
346+ : postContent ;
347+
340348 keywords . forEach ( keyword => {
341349 // From https://github.com/sindresorhus/escape-string-regexp
342350 const regEx = new RegExp (
@@ -346,13 +354,6 @@ export function search(query) {
346354 ) ,
347355 'gi' ,
348356 ) ;
349- handlePostTitle = postTitle
350- ? escapeHtml ( ignoreDiacriticalMarks ( postTitle ) )
351- : postTitle ;
352- handlePostContent = postContent
353- ? escapeHtml ( ignoreDiacriticalMarks ( postContent ) )
354- : postContent ;
355-
356357 const indexTitle = postTitle ? handlePostTitle . search ( regEx ) : - 1 ;
357358 let indexContent = postContent ? handlePostContent . search ( regEx ) : - 1 ;
358359
0 commit comments