Skip to content

Commit 3394ebb

Browse files
committed
fix(gen-tree): cache toc list, fixed #88
1 parent b4fc6a9 commit 3394ebb

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/core/render/compiler.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let markdownCompiler = marked
1212
let contentBase = ''
1313
let currentPath = ''
1414
let renderer = new marked.Renderer()
15-
const TOC = {}
15+
const cacheTree = {}
1616
let toc = []
1717

1818
/**
@@ -120,11 +120,9 @@ export function sidebar (text, level) {
120120
export function subSidebar (el, level) {
121121
if (el) {
122122
toc[0] && toc[0].level === 1 && toc.shift()
123-
const tree = genTree(TOC[currentPath] || toc, level)
123+
const tree = cacheTree[currentPath] || genTree(toc, level)
124124
el.parentNode.innerHTML += treeTpl(tree, '<ul class="app-sub-sidebar">')
125-
}
126-
if (toc.length) {
127-
TOC[currentPath] = toc.slice()
125+
cacheTree[currentPath] = tree
128126
}
129127
toc = []
130128
}

src/core/render/gen-tree.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export function genTree (toc, maxLevel) {
1515

1616
if (level > maxLevel) return
1717
if (last[len]) {
18-
last[len].children = last[len].children || []
19-
last[len].children.push(headline)
18+
last[len].children = (last[len].children || []).concat(headline)
2019
} else {
2120
headlines.push(headline)
2221
}

0 commit comments

Comments
 (0)