diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index b1f5f0255..40e70bae3 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -1,4 +1,6 @@ /* eslint-disable no-unused-vars */ +import { getAndRemoveConfig } from '../../core/render/utils'; + let INDEXS = {}; const LOCAL_STORAGE = { @@ -65,8 +67,15 @@ export function genIndex(path, content = '', router, depth) { tokens.forEach(token => { if (token.type === 'heading' && token.depth <= depth) { - slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) }); - index[slug] = { slug, title: token.text, body: '' }; + const { str, config } = getAndRemoveConfig(token.text); + + if (config.id) { + slug = router.toURL(path, { id: slugify(config.id) }); + } else { + slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) }); + } + + index[slug] = { slug, title: str, body: '' }; } else { if (!slug) { return;