Skip to content

Commit 6e554f8

Browse files
authored
fix: The search error after setting the ID in the title (#1159)
* Update search.js * Update search.js * Update search.js * Update search.js
1 parent 708ca9d commit 6e554f8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/plugins/search/search.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* eslint-disable no-unused-vars */
2+
import { getAndRemoveConfig } from '../../core/render/utils';
3+
24
let INDEXS = {};
35

46
const LOCAL_STORAGE = {
@@ -65,8 +67,15 @@ export function genIndex(path, content = '', router, depth) {
6567

6668
tokens.forEach(token => {
6769
if (token.type === 'heading' && token.depth <= depth) {
68-
slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) });
69-
index[slug] = { slug, title: token.text, body: '' };
70+
const { str, config } = getAndRemoveConfig(token.text);
71+
72+
if (config.id) {
73+
slug = router.toURL(path, { id: slugify(config.id) });
74+
} else {
75+
slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) });
76+
}
77+
78+
index[slug] = { slug, title: str, body: '' };
7079
} else {
7180
if (!slug) {
7281
return;

0 commit comments

Comments
 (0)