Skip to content
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

TOC helper: add min_depth #3288

Closed
noraj opened this issue Oct 14, 2018 · 7 comments
Closed

TOC helper: add min_depth #3288

noraj opened this issue Oct 14, 2018 · 7 comments

Comments

@noraj
Copy link
Contributor

noraj commented Oct 14, 2018

Enhancement

On the TOC helper (https://hexo.io/docs/helpers#toc), it would be great to add a min_depth option so we are able to set a minimum heading depth of generated toc.

This way we will be able to exclude h1 from the TOC for example.

@tcrowe
Copy link
Contributor

tcrowe commented Oct 23, 2018

What would min_depth do?

@tcrowe
Copy link
Contributor

tcrowe commented Oct 23, 2018

This is a duplicate post for the record

I usually use this:
https://github.com/bubkoo/hexo-toc

<!-- toc -->

Can you try and see if it works?

@noraj
Copy link
Contributor Author

noraj commented Oct 23, 2018

min_depth (set a minimum heading depth of generated toc) will do like max_depth (set a maximum heading depth of generated toc).
max_depth default is 6, so no heading deeper than h6. But it is assumed that the min depth is always 1. So min_depth will allow to set a min depth to 2 for example, generating heading for h2 to h6, avoiding to add h1 in the TOC.

@noraj
Copy link
Contributor Author

noraj commented Oct 23, 2018

hexo-toc has no min depth too bubkoo/hexo-toc#23 because it is using https://github.com/jonschlinkert/markdown-toc that has no min depth too.

@noraj
Copy link
Contributor Author

noraj commented Oct 23, 2018

@tcrowe This is not a duplicate issue at all one is TOC plugin (in addition of the helper) the other is TOC helper: add min_depth, so plugin vs helper.

https://hexo.io/docs/plugins
https://hexo.io/docs/helpers

@tcrowe
Copy link
Contributor

tcrowe commented Oct 23, 2018

@noraj I see now so that does appear useful to change from h1 to h2

@gautamz07
Copy link
Contributor

gautamz07 commented Oct 23, 2018

@noraj , a quick hot fix could be

const headingsSelector = [ 'h1' , 'h2', 'h3', 'h4', 'h5', 'h6'].slice(0, headingsMaxDepth).join(',');

deleting the headings element that you don't require in the above array eg. h1 , you should find the file in node_modules/plugins/helper/toc.js , though i would agree this is far from ideal ... just a quick hot fix :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants