feat: custom sidebar, #4 (#5)

* feat: custom sidebar, #4

* fix dev html

* fix doc

* fix doc
This commit is contained in:
cinwell.li 2016-11-27 18:53:31 +08:00 • committed by GitHub
commit 37e7984e7e
6 changed files with 71 additions and 15 deletions

View file

@ -25,8 +25,8 @@ const tocToTree = function (toc, maxLevel) {
const buildHeadlinesTree = function (tree, tpl = '') {
if (!tree || !tree.length) return ''
tree.forEach((node) => {
tpl += `<li><a class="section-link" href="#${node.slug}">${node.title}</a></li>`
tree.forEach(node => {
tpl += `<li><a class="section-link" href="${node.slug}">${node.title}</a></li>`
if (node.children) {
tpl += `<li><ul class="children">${buildHeadlinesTree(node.children)}</li></ul>`
}
@ -35,7 +35,10 @@ const buildHeadlinesTree = function (tree, tpl = '') {
return tpl
}
export default function (toc, maxLevel) {
var tree = tocToTree(toc, maxLevel)
export default function (toc, opts) {
var tree = Array.isArray(opts.sidebar)
? opts.sidebar
: tocToTree(toc, opts['max-level'])
return buildHeadlinesTree(tree, '<ul>')
}