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

Automatic Table of contents at the side #178

Open
0xricksanchez opened this issue Feb 22, 2022 · 1 comment
Open

Automatic Table of contents at the side #178

0xricksanchez opened this issue Feb 22, 2022 · 1 comment

Comments

@0xricksanchez
Copy link

One suggestion for this wonderful theme would be including a sticky Table of Contents at the side.
This would be particular helpful for longer blog posts.

Reference: https://ghost.org/docs/tutorials/adding-a-table-of-contents/

@0xricksanchez
Copy link
Author

0xricksanchez commented Oct 9, 2022

If anyone else would like to have a simple ToC at the top of the main page, hacking one into the code injection capabilities is fairly easy:

Add the following to site footer injections:

<!-- Add ToC capabiltiies -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.18.2/tocbot.min.js"></script>

<script>
    tocbot.init({
    // Where to render the table of contents.
    tocSelector: '.toc',
    // Where to grab the headings to build the table of contents.
    contentSelector: '.post-body',
    // Which headings to grab inside of the contentSelector element.
    headingSelector: 'h1, h2, h3, h4, h5, h6' ,
    // For headings inside relative or absolute positioned containers within content.
    hasInnerContainers: true,
    // Also include collapsed containers
    isCollapsedClass: '',
    });
</script>

<style>
.toc-heading{
    text-align: center;
    font-weight: bold;
}
.toc  ol {
    counter-reset: item;
}

.toc  ol  li {
    display: block;
    margin-left: 10px;
    list-style: decimal;
}

.toc  li:before {
    content: counters(item, ".") " ";
    counter-increment: item;
}
</style>

As the first thing in each post just add the following html card:

<div class="toc-container">
    <div class="toc-heading">Table fo contents</div>
	<aside class="toc"></aside>
</div>

Maybe someone can hack this into the theme itself some day.
That said one like in the link above would be even nicer

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

1 participant