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

Conversation

alexcambose
Copy link
Contributor

@alexcambose alexcambose commented Feb 16, 2019

Add support for ignoreSubHeading when loadSidebar is false.

The issue

When {docsify-ignore} is applied on a heading, the generated sidebar still contains the header and its subheaders. When loadSidebar is false only the sidebar() method is called so the filtering needs to be inserted there.

proto._renderSidebar = function (text) {
const {maxLevel, subMaxLevel, loadSidebar} = this.config
this._renderTo('.sidebar-nav', this.compiler.sidebar(text, maxLevel))
const activeEl = getAndActive(this.router, '.sidebar-nav', true, true)
if (loadSidebar && activeEl) {
activeEl.parentNode.innerHTML +=
this.compiler.subSidebar(subMaxLevel) || ''
} else {
// Reset toc
this.compiler.subSidebar()
}
// Bind event
this._bindEventOnRendered(activeEl)
}

I used classic splice() method and for loops to remove the header and all it's subheaders because I saw this method being used subSidebar(). I was probably better to just use the [].filter() way but it works anyways.


Please makes sure these boxes are checked before submitting your PR, thank you!

  • Make sure you are merging your commits to master branch.
  • Add some descriptions and refer relative issues for you PR.
  • DO NOT include files inside lib directory.

@timaschew
Copy link
Member

Hey Alexandru, thanks for your contribution!
Can you please provide some unit tests?

@alexcambose
Copy link
Contributor Author

I would like to but i can't figure out how to get the rendered html of the sidebar in the tests file.

@timaschew
Copy link
Member

You can rebase on my branch: improve-test-setup I've added some tests cases which should be helpful for you.

@timaschew
Copy link
Member

Please run these commands to trigger netlify deployment for this Pull Request:

git commit --amend --no-edit
git push --force

@timaschew timaschew changed the base branch from master to develop April 14, 2019 15:26
@timaschew timaschew merged commit 78f5564 into docsifyjs:develop Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants