Skip to content

Commit

Permalink
fix: fix search terms highlighting
Browse files Browse the repository at this point in the history
closes #266
  • Loading branch information
weareoutman committed Oct 17, 2022
1 parent 9ec0197 commit aacc610
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docusaurus-search-local/src/client/theme/SearchPage/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getStemmedPositions } from "../../utils/getStemmedPositions";
import LoadingRing from "../LoadingRing/LoadingRing";
import { concatDocumentPath } from "../../utils/concatDocumentPath";
import {
Mark,
docsPluginIdForPreferredVersion,
indexDocs,
searchContextByPaths,
Expand Down Expand Up @@ -226,12 +227,19 @@ function SearchResultItem({
if (!isTitle) {
pathItems.push((page as SearchDocument).t);
}
const hightLightWords = tokens.map(x=>"_highlight="+x).join("&");
let search = "";
if (Mark && tokens.length > 0) {
const params = new URLSearchParams();
for (const token of tokens) {
params.append("_highlight", token);
}
search = `?${params.toString()}`;
}
return (
<article className={styles.searchResultItem}>
<h2>
<Link
to={document.u + "?" + hightLightWords + (document.h || "")}
to={document.u + search + (document.h || "")}
dangerouslySetInnerHTML={{
__html: isContent
? highlight(articleTitle, tokens)
Expand Down

0 comments on commit aacc610

Please sign in to comment.