Skip to content

Commit 30fa8fc

Browse files
authored
Merge pull request #283 from brianler/fix221017
修复在显示全部搜索结果页面中点击结果跳转至相应页面没有高亮搜索词的问题
2 parents cef9b73 + aacc610 commit 30fa8fc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docusaurus-search-local/src/client/theme/SearchPage/SearchPage.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { getStemmedPositions } from "../../utils/getStemmedPositions";
2121
import LoadingRing from "../LoadingRing/LoadingRing";
2222
import { concatDocumentPath } from "../../utils/concatDocumentPath";
2323
import {
24+
Mark,
2425
docsPluginIdForPreferredVersion,
2526
indexDocs,
2627
searchContextByPaths,
@@ -226,11 +227,19 @@ function SearchResultItem({
226227
if (!isTitle) {
227228
pathItems.push((page as SearchDocument).t);
228229
}
230+
let search = "";
231+
if (Mark && tokens.length > 0) {
232+
const params = new URLSearchParams();
233+
for (const token of tokens) {
234+
params.append("_highlight", token);
235+
}
236+
search = `?${params.toString()}`;
237+
}
229238
return (
230239
<article className={styles.searchResultItem}>
231240
<h2>
232241
<Link
233-
to={document.u + (document.h || "")}
242+
to={document.u + search + (document.h || "")}
234243
dangerouslySetInnerHTML={{
235244
__html: isContent
236245
? highlight(articleTitle, tokens)

0 commit comments

Comments
 (0)