From 9832805681cc6099e9c78deecf6dc0c6fb61fd9b Mon Sep 17 00:00:00 2001 From: Koy Zhuang Date: Tue, 30 Aug 2022 18:46:08 +0800 Subject: [PATCH] fix: fix docsify-ignore in seach title. (#1872) --- src/core/util/str.js | 9 +++++++++ src/plugins/search/search.js | 12 +++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/util/str.js b/src/core/util/str.js index f8b8ec4c6..4663b5ebe 100644 --- a/src/core/util/str.js +++ b/src/core/util/str.js @@ -5,3 +5,12 @@ export function startsWith(str, prefix) { export function endsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; } + +export function removeDocsifyIgnoreTag(str) { + return str + .replace(//, '') + .replace(/{docsify-ignore}/, '') + .replace(//, '') + .replace(/{docsify-ignore-all}/, '') + .trim(); +} diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index f889a08e5..91a21094e 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -1,5 +1,6 @@ /* eslint-disable no-unused-vars */ import { getAndRemoveConfig } from '../../core/render/utils'; +import { removeDocsifyIgnoreTag } from '../../core/util/str'; let INDEXS = {}; @@ -89,19 +90,16 @@ export function genIndex(path, content = '', router, depth) { if (token.type === 'heading' && token.depth <= depth) { const { str, config } = getAndRemoveConfig(token.text); + const text = removeDocsifyIgnoreTag(token.text); + if (config.id) { slug = router.toURL(path, { id: slugify(config.id) }); } else { - slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) }); + slug = router.toURL(path, { id: slugify(escapeHtml(text)) }); } if (str) { - title = str - .replace(//, '') - .replace(/{docsify-ignore}/, '') - .replace(//, '') - .replace(/{docsify-ignore-all}/, '') - .trim(); + title = removeDocsifyIgnoreTag(str); } index[slug] = { slug, title: title, body: '' };