{{ if and (isset .Params "toc") .Params.toc  }}
  <details>
    <summary>Table of Contents</summary>
    {{ .TableOfContents }}
  </details>
  <script>
    const el = document.querySelector('details summary')
    el.onclick = () => {
      (function(l,o,a,d,e,r){e=o.createElement(a),r=o.getElementsByTagName(a)[0];e.async=1;e.src=d;r.parentNode.insertBefore(e,r)})(window,document,'script','/js/smoothscroll.js');
      el.onclick = null
    }
    document.querySelectorAll('#TableOfContents a').forEach(link => {
      link.addEventListener('click', () => {
        document.querySelector(
          link.href.slice(link.href.indexOf('#'))
        ).scrollIntoView({ behavior: 'smooth' })
      })
    })
  </script>
{{ end }}
