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

@ -8,19 +8,27 @@
<!-- Body Start inject -->
{% include "injects/body_start.html" ignore missing %}
<main
class="prose prose-neutral dark:prose-invert prose-pre:rounded-lg prose-img:rounded-lg relative mx-auto min-h-[calc(100vh-9rem)] max-w-3xl px-4 pt-24 pb-16 break-words lg:pt-32"
>
{% block main %}
<div class="flex">
<div class="order-1 hidden w-[calc((100%-var(--container-3xl))/2)] lg:block"></div>
<aside
class="sticky top-0 order-3 mt-48 hidden h-min w-[calc((100%-var(--container-3xl))/2)] lg:block"
>
{% include "partials/side_toc.html" %}
</aside>
<main
class="prose prose-neutral dark:prose-invert prose-pre:rounded-lg prose-img:rounded-lg order-2 mx-auto min-h-[calc(100vh-9rem)] w-full max-w-3xl px-4 pt-24 pb-16 break-words lg:pt-32"
>
{% block main %}
<!-- Profile -->
{% if paginator is undefined or paginator.current_index == 1 %}<!---->
{% include "partials/profile.html" %}<!---->
{% endif %}<!---->
<!-- Profile -->
{% if paginator is undefined or paginator.current_index == 1 %}<!---->
{% include "partials/profile.html" %}<!---->
{% endif %}<!---->
{% include "partials/page_list.html" %}<!---->
{% endblock main %}
</main>
{% include "partials/page_list.html" %}<!---->
{% endblock main %}
</main>
</div>
{% include "partials/footer.html" %}

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 %}