Skip to content

Commit

Permalink
fix: The search error after setting the ID in the title (#1159)
Browse files Browse the repository at this point in the history
* Update search.js

* Update search.js

* Update search.js

* Update search.js
  • Loading branch information
sy-records committed May 14, 2020
1 parent 708ca9d commit 6e554f8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions 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 = {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6e554f8

Please sign in to comment.