diff --git a/app/components/layout/Search.tsx b/app/components/layout/Search.tsx index aac65bb..fd8a4b1 100644 --- a/app/components/layout/Search.tsx +++ b/app/components/layout/Search.tsx @@ -15,13 +15,17 @@ import { function showExcerpt(body: string | null, query: string) { if (body === null) return '...' - if (!body.includes(query)) return `${body}...` + const startIndex = body.toLowerCase().indexOf(query.toLowerCase()) + if (startIndex === -1) return `${body}...` - const [before, after] = body.split(query) + const endIndex = startIndex + query.length + const before = body.slice(0, startIndex) + const matched = body.slice(startIndex, endIndex) + const after = body.slice(endIndex) return ( <> ...{before} - {query} + {matched} {after}... ) diff --git a/app/routes/documentation.$product.$ref.actions.search.tsx b/app/routes/documentation.$product.$ref.actions.search.tsx index f5856ef..a9d0e1d 100644 --- a/app/routes/documentation.$product.$ref.actions.search.tsx +++ b/app/routes/documentation.$product.$ref.actions.search.tsx @@ -7,6 +7,7 @@ function getBodyContext(body: string, term: string) { const numContextWords = 2 const searchTermRegex = new RegExp( `(?:\\s?(?:[\\w]+)\\s?){0,${numContextWords}}${term}(?:\\s?(?:[\\w]+)\\s?){0,${numContextWords}}`, + 'i', ) const excerptRegex = /^(\w+(?:\s+\w+){0,5})/ diff --git a/app/routes/documentation.private.$product.$ref.actions.search.tsx b/app/routes/documentation.private.$product.$ref.actions.search.tsx index e9859ff..15c8d40 100644 --- a/app/routes/documentation.private.$product.$ref.actions.search.tsx +++ b/app/routes/documentation.private.$product.$ref.actions.search.tsx @@ -7,6 +7,7 @@ function getBodyContext(body: string, term: string) { const numContextWords = 2 const searchTermRegex = new RegExp( `(?:\\s?(?:[\\w]+)\\s?){0,${numContextWords}}${term}(?:\\s?(?:[\\w]+)\\s?){0,${numContextWords}}`, + 'i', ) const excerptRegex = /^(\w+(?:\s+\w+){0,5})/