feat: add TOC

This commit is contained in:
st1020 2023-10-22 17:29:59 +08:00
parent f46a830abf
commit 66b48ea8d7
3 changed files with 58 additions and 0 deletions

View file

@ -6,6 +6,38 @@
{% include "partials/page_info.html" %}
</header>
{% if page.toc %}
<div class="mb-12 flex rounded-lg bg-black/[3%] p-2 text-lg dark:bg-white/[8%]">
<details>
<summary class="cursor-pointer py-1 pl-4">
<span>Table of Contents</span>
</summary>
<div class="px-2">
<ul>
{% for h1 in page.toc %}
<li>
<a class="no-underline hover:underline" href="{{ h1.permalink | safe }}"
>{{ h1.title }}</a
>
{% if h1.children %}
<ul>
{% for h2 in h1.children %}
<li>
<a class="no-underline hover:underline" href="{{ h2.permalink | safe }}"
>{{ h2.title }}</a
>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
</details>
</div>
{% endif %}
<section>{{ page.content | safe }}</section>
<hr />