feat: add toc default state setting

This commit is contained in:
Erzbir
2026-06-15 22:23:34 +08:00
parent b7a5ce82ac
commit bf7686d2a2
2 changed files with 14 additions and 1 deletions
+12
View File
@@ -255,6 +255,18 @@ spec:
name: show_toc name: show_toc
label: 显示文章目录 label: 显示文章目录
value: true value: true
- $formkit: select
name: toc_default_open
label: 文章目录默认状态
value: "auto"
help: 自动模式会在普通布局默认展开, 全屏布局默认收起
options:
- label: "自动"
value: "auto"
- label: "默认展开"
value: "open"
- label: "默认收起"
value: "closed"
- $formkit: checkbox - $formkit: checkbox
name: show_tags name: show_tags
label: 显示文章标签 label: 显示文章标签
+2 -1
View File
@@ -20,7 +20,8 @@
</section> </section>
</article> </article>
<nav id="toc" th:if="${theme.config.post_page.show_toc}" class="toc" <nav id="toc" th:if="${theme.config.post_page.show_toc}" class="toc"
th:attr="data-default-open=${theme.config.style.fullscreen_layout ? 'false' : 'true'}"> th:with="tocDefaultOpen=${theme.config.post_page.toc_default_open ?: 'auto'}"
th:attr="data-default-open=${tocDefaultOpen == 'open' ? 'true' : (tocDefaultOpen == 'closed' ? 'false' : (theme.config.style.fullscreen_layout ? 'false' : 'true'))}">
<button id="toc-toggle" class="toc-toggle" aria-label="Hide Table of Contents"></button> <button id="toc-toggle" class="toc-toggle" aria-label="Hide Table of Contents"></button>
<div id="toc-content" class="toc-content"></div> <div id="toc-content" class="toc-content"></div>
</nav> </nav>