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

Customize automatically generated TOC on jekyll #120

Open
meera1002 opened this issue Sep 23, 2020 · 3 comments
Open

Customize automatically generated TOC on jekyll #120

meera1002 opened this issue Sep 23, 2020 · 3 comments

Comments

@meera1002
Copy link

meera1002 commented Sep 23, 2020

In _config.yml I have the following setting that ensures that only h2 elements show up in the automatically generated table of contents.
toc:
min_level: 2 # default: 1
max_level: 2 # default: 6

This works fine, but on some pages, I would like to include h3 elements in the toc as well. So I want to change the max_level to 3 in a particular case. Is this possible? I want to change max_level value dynamically from the template code. Please help

@daipom
Copy link

daipom commented Sep 17, 2024

I want to specify min_level and max_level per post.

For example, it would be nice to be able to specify them as follows.

---
layout: post
title: "Welcome to Jekyll!"
toc:
  min_level: 2
---

@schmittnieto
Copy link

schmittnieto commented Sep 17, 2024

Hi @daipom

currently in the main repository of Minimal Mistakes there is this file https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/toc.html

Which allows using the following command {% include toc.html=content html=content sanitize=true class=“inline_toc” id=“my_toc” h_min=2 h_max=3 %} to solve what we are asking for.

This should be added after the front matter on the first line before the article text. For this the toc: true should be removed from the front matter as well.

This afternoon if I have some time I'll take a look at it and let you know if it works as I told you.

Best regards,
Cristian

@daipom
Copy link

daipom commented Sep 17, 2024

@schmittnieto Thanks!
https://github.com/allejo/jekyll-toc works!

{% if page.toc %}
  {% include toc.html html=content h_min=page.toc.h_min h_max=page.toc.h_max %}
{% endif %}
---
toc:
  h_min: 3
---

My problem is solved. Thanks!

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

No branches or pull requests

3 participants