Add a Table of Content only on one page?
Is there a way to add a TOC only on one page, which is very long? I don't want to have it on all the pages.
Can you link your blog to see how it might be implemented?
You could use straight markdown or wikilinks.
You could also use the archive or tag function.
What app are you using to write your posts?
Answered 2 years ago · Edit answerI'd add a custom metadata flag to the post, e.g.
TOC: yes
Then amend your template's entry.html view to use Tocbot to generate a table of contents only when that flag is set:
{{#entry.metadata.toc}}
<div class="toc" style="position:fixed;top:0;right:0;width:150px"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.css">
<script>
tocbot.init({
tocSelector: '.toc',
contentSelector: '.entry',
headingSelector: 'h1, h2, h3'
});
</script>
{{/entry.metadata.toc}}
Answered 2 years ago ·
Edit answer