diff --git a/src/core/global-api.js b/src/core/global-api.js index aa2ae0ee5..b5565d9cb 100644 --- a/src/core/global-api.js +++ b/src/core/global-api.js @@ -2,12 +2,13 @@ import * as util from './util' import * as dom from './util/dom' import * as render from './render/compiler' import * as route from './route/hash' +import { slugify } from './render/slugify' import { get } from './fetch/ajax' import marked from 'marked' import prism from 'prismjs' export default function () { - window.Docsify = { util, dom, render, route, get } + window.Docsify = { util, dom, render, route, get, slugify } window.marked = marked window.Prism = prism } diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 58db9b3a8..785f70c35 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -2,7 +2,7 @@ import marked from 'marked' import Prism from 'prismjs' import { helper as helperTpl, tree as treeTpl } from './tpl' import { genTree } from './gen-tree' -import { slugify, clearSlugCache } from './slugify' +import { slugify } from './slugify' import { emojify } from './emojify' import { toURL, parse } from '../route/hash' import { getBasePath, isAbsolutePath, getPath } from '../route/util' @@ -25,7 +25,7 @@ export const markdown = cached(text => { html = markdownCompiler(text) html = emojify(html) - clearSlugCache() + slugify.clear() return html }) diff --git a/src/core/render/slugify.js b/src/core/render/slugify.js index a6e9d39b9..bb34758a1 100644 --- a/src/core/render/slugify.js +++ b/src/core/render/slugify.js @@ -22,6 +22,6 @@ export function slugify (str) { return slug } -export function clearSlugCache () { +slugify.clear = function () { cache = {} } diff --git a/src/plugins/search/component.js b/src/plugins/search/component.js index cc7d0ec08..524448c8e 100644 --- a/src/plugins/search/component.js +++ b/src/plugins/search/component.js @@ -107,7 +107,7 @@ function bindEvents () { e => e.target.tagName !== 'A' && e.stopPropagation()) dom.on($input, 'input', e => { clearTimeout(timeId) - timeId = setTimeout(_ => doSearch(e.target.value.trim()), 200) + timeId = setTimeout(_ => doSearch(e.target.value.trim()), 100) }) } diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 58e8cbf3e..9888d63a9 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -40,13 +40,14 @@ function saveData (maxAge) { export function genIndex (path, content = '') { const tokens = window.marked.lexer(content) + const slugify = window.Docsify.slugify const toURL = Docsify.route.toURL const index = {} let slug tokens.forEach(token => { if (token.type === 'heading' && token.depth <= 2) { - slug = toURL(path, { id: token.text }) + slug = toURL(path, { id: slugify(token.text) }) index[slug] = { slug, title: token.text, body: '' } } else { if (!slug) return @@ -61,7 +62,7 @@ export function genIndex (path, content = '') { } } }) - + slugify.clear() return index }