Table of content in Pug

Pug is a templating engine. It is a great tool to create HTML pages (especially if you are creating multiple static pages) and despite the fact that is does not seem to be maintained anymore.

I was looking for a way to generate a table of content in a Pug file and I settled on the following construct.
I created the following code in my Pug template file:

mixin toc(parts)
 br
 br
 article
   aside
     h3 Content
     nav
       ul
         each part in parts
           - var link = '#' + part.replace(/\s/g, '-').toLowerCase()
           li
             a(href=link)= part

mixin tocTitle(title)
  - var link = title.replace(/\s/g, '-').toLowerCase()
  h2(id=link)= title

then in my content file, I added the following:

+toc(['Domain Name Provider', 'Page Hosting', ...])

+tocTitle('Domain Name Provider')
...
+tocTitle('Page Hosting')
...

I hope someone will find this useful. :)