mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-03 20:48:55 +08:00
fix(gen-tree): cache toc list, fixed #88
This commit is contained in:
parent
b4fc6a9d72
commit
3394ebb9a5
@ -12,7 +12,7 @@ let markdownCompiler = marked
|
||||
let contentBase = ''
|
||||
let currentPath = ''
|
||||
let renderer = new marked.Renderer()
|
||||
const TOC = {}
|
||||
const cacheTree = {}
|
||||
let toc = []
|
||||
|
||||
/**
|
||||
@ -120,11 +120,9 @@ export function sidebar (text, level) {
|
||||
export function subSidebar (el, level) {
|
||||
if (el) {
|
||||
toc[0] && toc[0].level === 1 && toc.shift()
|
||||
const tree = genTree(TOC[currentPath] || toc, level)
|
||||
const tree = cacheTree[currentPath] || genTree(toc, level)
|
||||
el.parentNode.innerHTML += treeTpl(tree, '<ul class="app-sub-sidebar">')
|
||||
}
|
||||
if (toc.length) {
|
||||
TOC[currentPath] = toc.slice()
|
||||
cacheTree[currentPath] = tree
|
||||
}
|
||||
toc = []
|
||||
}
|
||||
|
@ -15,8 +15,7 @@ export function genTree (toc, maxLevel) {
|
||||
|
||||
if (level > maxLevel) return
|
||||
if (last[len]) {
|
||||
last[len].children = last[len].children || []
|
||||
last[len].children.push(headline)
|
||||
last[len].children = (last[len].children || []).concat(headline)
|
||||
} else {
|
||||
headlines.push(headline)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user