From 6e554f8ebd3d4a2c5c7e4f66cff3dfe2b6aa1e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Thu, 14 May 2020 19:48:17 +0800 Subject: [PATCH] fix: The search error after setting the ID in the title (#1159) * Update search.js * Update search.js * Update search.js * Update search.js --- src/plugins/search/search.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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;