Skip to content

How should I add TOC in my Blog page? #1206

Closed Answered by h-enk
siyehua asked this question in Q&A
Discussion options

You must be logged in to vote

That's not supported out-of-the-box

You could overwrite the blog single template and add the ToC (based on the _default/single.html template) — for example:

  • copy node_modules/@hyas/doks-core/layouts/blog/single.html and paste as layouts/blog/single.html
  • insert on line 27 something like:
    {{ if ne .Params.toc false -}}
    <nav class="my-3" aria-label="Secondary navigation">
        {{ partial "sidebar/docs-toc-mobile.html" . }}
    </nav>
    {{ end -}}
  • make sure to set in the page's frontmatter: toc: true (not top: true — typo in your code example)

And, you'll get something like this:

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by siyehua
Comment options

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