refactor(router): clean global api

This commit is contained in:
qingwei.li 2017-05-29 19:55:28 +08:00 • committed by cinwell.li
commit 8741c746df
12 changed files with 46 additions and 126 deletions

View file

@ -14,18 +14,18 @@ function escapeHtml (string) {
return String(string).replace(/[&<>"'\/]/g, s => entityMap[s])
}
function getAllPaths () {
function getAllPaths (router) {
const paths = []
helper.dom.findAll('a:not([data-nosearch])')
.map(node => {
const href = node.href
const originHref = node.getAttribute('href')
const path = helper.route.parse(href).path
const path = router.parse(href).path
if (path &&
paths.indexOf(path) === -1 &&
!helper.route.isAbsolutePath(originHref)) {
!Docsify.util.isAbsolutePath(originHref)) {
paths.push(path)
}
})
@ -38,10 +38,10 @@ function saveData (maxAge) {
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS))
}
export function genIndex (path, content = '') {
export function genIndex (path, content = '', router) {
const tokens = window.marked.lexer(content)
const slugify = window.Docsify.slugify
const toURL = Docsify.route.toURL
const toURL = router.toURL
const index = {}
let slug
@ -145,7 +145,7 @@ export function init (config, vm) {
return
}
const paths = isAuto ? getAllPaths() : config.paths
const paths = isAuto ? getAllPaths(vm.router) : config.paths
const len = paths.length
let count = 0
@ -155,7 +155,7 @@ export function init (config, vm) {
helper
.get(vm.router.getFile(path))
.then(result => {
INDEXS[path] = genIndex(path, result)
INDEXS[path] = genIndex(path, result, vm.router)
len === ++count && saveData(config.maxAge)
})
})