fix(search): incorrect anchor link, fixed #90

This commit is contained in:
qingwei.li 2017-02-22 21:38:02 +08:00 committed by cinwell.li
commit b8a3d8f380
5 changed files with 9 additions and 7 deletions

View file

@ -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)
})
}

View file

@ -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
}