Skip to content

Added filtering in sidebar for ignoreSubHeading #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,25 @@ export class Compiler {
* Compile sidebar
*/
sidebar(text, level) {
const {toc} = this
const currentPath = this.router.getCurrentPath()
let html = ''

if (text) {
html = this.compile(text)
} else {
const tree = this.cacheTree[currentPath] || genTree(this.toc, level)
for (let i = 0; i < toc.length; i++) {
if (toc[i].ignoreSubHeading) {
const deletedHeaderLevel = toc[i].level
toc.splice(i, 1)
// Remove headers who are under current header
for (let j = i; deletedHeaderLevel < toc[j].level && j < toc.length; j++) {
toc.splice(j, 1) && j-- && i++
}
i--
}
}
const tree = this.cacheTree[currentPath] || genTree(toc, level)
html = treeTpl(tree, '<ul>{inner}</ul>')
this.cacheTree[currentPath] = tree
}
Expand All @@ -360,7 +372,6 @@ export class Compiler {
for (let i = 0; i < toc.length; i++) {
toc[i].ignoreSubHeading && toc.splice(i, 1) && i--
}

const tree = cacheTree[currentPath] || genTree(toc, level)

cacheTree[currentPath] = tree
Expand Down