Log in Sign up

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.

2 replies Asked Sep 18 '22 at 1:17 · Improve this question

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 Sep 19 '22 at 0:07 · Improve this answer

I'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:

<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">
  tocSelector: '.toc',
  contentSelector: '.entry',
  headingSelector: 'h1, h2, h3'
Answered Sep 21 '22 at 13:45 · Improve this answer

Markdown allowed