Skip to content
Permalink
Browse files

feat($toc): always set top-level node to branch node instead of leaf …

…node
  • Loading branch information...
ulivz committed Feb 11, 2019
1 parent f62ea63 commit 44216ddb1649cb9f9a0545055d929aacb61e1730
Showing with 19 additions and 1 deletion.
  1. +4 −1 lib/__test__/toc.constant.js
  2. +15 −0 lib/toc.js
@@ -50,7 +50,10 @@ const TOC_3 = [
{ title: '私有仓库', slug: 'private-repo', depth: 2 },
{ title: '配置', slug: 'config', depth: 1 },
{ title: '进阶', slug: '#', depth: 1 },
{ title: 'Zero-Markdown', slug: 'zero-markdown', depth: 2 }
{ title: 'A', slug: 'a', depth: 1 },
{ title: 'B', slug: 'b', depth: 1 },
{ title: 'B-1', slug: 'b-1', depth: 2 },
{ title: 'C', slug: 'c', depth: 1 },
]

module.exports = [
@@ -70,6 +70,13 @@ function getSidebarByToc(toc) {
if (next.depth > cur.depth) {
safePop(stack)
pushBranch(cur, stack)
} else if (next.depth === cur.depth) {
if (cur.depth === 1) {
safePop(stack)
pushBranch(cur, stack)
} else {
pushLeaf(cur, stack)
}
} else {
pushLeaf(cur, stack)
}
@@ -78,6 +85,14 @@ function getSidebarByToc(toc) {
if (next.depth > cur.depth) {
safePop(stack)
pushBranch(cur, stack)
} else if (next.depth === cur.depth) {
if (cur.depth === 1) {
safePop(stack)
pushBranch(cur, stack)
} else {
safePop(stack)
pushLeaf(cur, stack)
}
} else {
safePop(stack)
pushLeaf(cur, stack)

0 comments on commit 44216dd

Please sign in to comment.
You can’t perform that action at this time.