feat: add side toc support and update toc style

This commit is contained in:
st1020 2025-10-02 20:07:02 +08:00
parent 9d208b7bd1
commit b7a197c648
10 changed files with 291 additions and 241 deletions

View file

@ -0,0 +1,23 @@
{% if page.toc and page.extra.side_toc | default(value=config.extra.side_toc) %}
<nav
class="prose prose-neutral dark:prose-invert prose-a:block prose-a:truncate prose-a:font-normal prose-a:secondary-link max-h-lvh overflow-y-auto px-2 pt-18 pb-4"
>
<b class="ml-1.5">Table of Contents</b>
<ul>
{% for h1 in page.toc %}
<li>
<a href="#{{ h1.id | safe }}">{{ h1.title }}</a>
{% if h1.children %}
<ul>
{% for h2 in h1.children %}
<li>
<a href="#{{ h2.id | safe }}">{{ h2.title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
{% endif %}

View file

@ -1,31 +1,25 @@
{% if page.toc %}<!---->
<div class="block-bg mb-12 flex rounded-lg p-2 text-lg">
{% if page.toc %}
<nav class="block-bg prose-a:secondary-link mb-12 flex rounded-lg p-2 text-lg">
<details>
<summary class="cursor-pointer py-1 pl-4">
<span>Table of Contents</span>
<span class="ml-2">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>
<ul class="mx-2">
{% for h1 in page.toc %}
<li>
<a href="#{{ h1.id | safe }}">{{ h1.title }}</a>
{% if h1.children %}
<ul>
{% for h2 in h1.children %}
<li>
<a href="#{{ h2.id | safe }}">{{ h2.title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</details>
</div>
</nav>
{% endif %}