Accessing table of content tree?


#1

I would like to render a table of content on a sidebar in a hugo-generated site. But rather than using .TableOfContents, I would like to access the tree directly and iterate on it to render a customized HTML.

Currently I am using the following in my HTML:

{{ .TableOfContents }}

which results in:

<nav id="...">
  <ul>
    <li>...</li>
     ...
     <ul>
     ...
     </ul>
  </ul>
</nav>

But I would like to customize the markup. Concretely, without <nav> and with custom classes for some elements. I think I can achieve this if I can access the struct that holds the tree representation of the table of contents.

Any ideas or alternative suggestions?