fix(gen-tree): cache toc list, fixed #88
This commit is contained in:
parent
b4fc6a9d72
commit
3394ebb9a5
2 changed files with 4 additions and 7 deletions
|
|
@ -12,7 +12,7 @@ let markdownCompiler = marked
|
||||||
let contentBase = ''
|
let contentBase = ''
|
||||||
let currentPath = ''
|
let currentPath = ''
|
||||||
let renderer = new marked.Renderer()
|
let renderer = new marked.Renderer()
|
||||||
const TOC = {}
|
const cacheTree = {}
|
||||||
let toc = []
|
let toc = []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -120,11 +120,9 @@ export function sidebar (text, level) {
|
||||||
export function subSidebar (el, level) {
|
export function subSidebar (el, level) {
|
||||||
if (el) {
|
if (el) {
|
||||||
toc[0] && toc[0].level === 1 && toc.shift()
|
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">')
|
el.parentNode.innerHTML += treeTpl(tree, '<ul class="app-sub-sidebar">')
|
||||||
}
|
cacheTree[currentPath] = tree
|
||||||
if (toc.length) {
|
|
||||||
TOC[currentPath] = toc.slice()
|
|
||||||
}
|
}
|
||||||
toc = []
|
toc = []
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ export function genTree (toc, maxLevel) {
|
||||||
|
|
||||||
if (level > maxLevel) return
|
if (level > maxLevel) return
|
||||||
if (last[len]) {
|
if (last[len]) {
|
||||||
last[len].children = last[len].children || []
|
last[len].children = (last[len].children || []).concat(headline)
|
||||||
last[len].children.push(headline)
|
|
||||||
} else {
|
} else {
|
||||||
headlines.push(headline)
|
headlines.push(headline)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue