Skip to content

Commit

Permalink
fix: fix docsify-ignore in seach title. (#1872)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 authored Aug 30, 2022
1 parent 3c9b3d9 commit 9832805
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/core/util/str.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<!-- {docsify-ignore} -->/, '')
.replace(/{docsify-ignore}/, '')
.replace(/<!-- {docsify-ignore-all} -->/, '')
.replace(/{docsify-ignore-all}/, '')
.trim();
}
12 changes: 5 additions & 7 deletions src/plugins/search/search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-unused-vars */
import { getAndRemoveConfig } from '../../core/render/utils';
import { removeDocsifyIgnoreTag } from '../../core/util/str';

let INDEXS = {};

Expand Down Expand Up @@ -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(/<!-- {docsify-ignore} -->/, '')
.replace(/{docsify-ignore}/, '')
.replace(/<!-- {docsify-ignore-all} -->/, '')
.replace(/{docsify-ignore-all}/, '')
.trim();
title = removeDocsifyIgnoreTag(str);
}

index[slug] = { slug, title: title, body: '' };
Expand Down

1 comment on commit 9832805

@vercel
Copy link

@vercel vercel bot commented on 9832805 Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.