scully-plugin-toc — A Plugin for generating table of contents
You need just to define a placeholder at the place where the TOC should appear. The plugin will generate a TOC for all the headings it will find (you can also specify the level) and then insert the generated TOC at the place where you put the placeholder for it.
Check out how to set it up by reading the docs in the Github repository.
You haven't heard about Scully yet? Check out my article series about the static site generator Scully.