Skip to content

How to enable TOC for all headers #1364

Closed Answered by kungfux
opabravo asked this question in Q&A
Discussion options

You must be logged in to vote

Here is the working solution.

Create a file _includes/metadata-hook.html with the following content (this file is completely empty in Chirpy repo and is made specifically to include extra information into the <head> section without the need to modify and support other files like head.html):

<script type="text/javascript" src="/assets/js/toc.js" defer></script>

Then, create a javascript file assets/js/toc.js to overrides TOC configuration e.g.:

document.querySelector("main h2, main h3")&&tocbot.refresh({
    tocSelector:"#toc",
    contentSelector:".content",
    ignoreSelector:"[data-toc-skip]",
    headingSelector:"h2, h3, h4, h5, h6",
    orderedList:!1,
    scrollSmooth:!1,
    collaps…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@opabravo
Comment options

Comment options

You must be logged in to vote
3 replies
@huanyushi
Comment options

@kungfux
Comment options

kungfux Apr 24, 2024
Collaborator

@huanyushi
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by opabravo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants