Putting TOC in an arbitrary place in the post

Am I right that it is not currently possible to put TOC in an arbitrary place in the page content?

Say I want TOC to be after the first introductory paragraph of content, or after the first few paragraphs (depends on the actual post). I tried using a shortcode with <div>{{ .TableOfContents}}</div> in it, but had little success.

You are right.

I guess nothing changed related to this request, right? Is this something that could be brought up again and dicsussed? I’m currently using Jekyll. On my blog I only include the TOC in some cases, when I have more lengthy tutorial style articles. Including a TOC there (with Kramdown) is as simple as:

## Table of Contents
{:.no_toc}
* TOC
{:toc}

I moved this out into a “partial”, probably a shortcode in Hugo and include it whenever and at which position in the article where I want it.

My plan is to migrate to Hugo, because Jekyll is damn damn slow while Hugo is extremely, mindblowingly fast. But this issue is somehow a blocker right now for me as I cannot somehow add the TOC into the flow of my article. Here’s an example: https://juristr.com/blog/2017/07/ng2-dynamic-tab-component/

Any workaround for now is also more than welcome. I’ve seen some issues on GitHub around this discussion, like this one (#1778) and this (#716), but there doesn’t seem much activity around there. How do others solve this?

thx :slight_smile:

Maybe use WordCount to check before adding the TOC?

No, my issue it not to automate the adding of the TOC. I could simply use some custom frontmatter property to switch it on/off.
I was searching for a possibility to add the TOC inside the flow of the overall article. Right now it seems to be impossible. You have to add it to some different outside of the article container element…

TOC is currently a product of the page rendering, so this is impossible. It should be possible with Blackfriday 2 soon to be released, but it does require some work.

2 Likes

Thinking about this: Have you tried accessing the TOC from a shortcode?

I’ve tried some things yes, but I’m totally new to Hugo and Golang, so I might have missed some opportunities :slight_smile: Like I tried some suggestions from here: .TableOfContents in Markdown but they didn’t work.

What exactly were you thinking about? (sorry for newbie questions :sweat_smile:

Oh wait, getting some result now. Ignore the styling, it’s currently a prototype.

Problem here is that the “TOC” title itself gets included as well, which in Jekyll you can prevent as I’ve highlighted in my snippet before. But I can work around this for sure.

awesome! Not sure why this didn’t work before as I’ve tried it already…anyways. Thx for the help :slight_smile:

A post was split to a new topic: Asciidoc and TOC shortcode