summaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-08-26 10:28:00 +0800
committerEltrac <hi@guhub.cn>2025-08-26 10:28:00 +0800
commit6fc8a8a1e563bea6c9efcc19f2424f45009a71de (patch)
tree3426f897eac1628bc3b5ef78eb4649c6561f7128 /layouts
parent52345965347199d43452168fd4462e06e0dbdaf1 (diff)
feat: add toc to library and normal pages
Former-commit-id: e7f41626f0e3d8019562ef2d7a3d99e05e0b1e55
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_partials/posts/toc.html3
-rw-r--r--layouts/library/page.html7
-rw-r--r--layouts/page.html1
-rw-r--r--layouts/posts/page.html7
4 files changed, 8 insertions, 10 deletions
diff --git a/layouts/_partials/posts/toc.html b/layouts/_partials/posts/toc.html
index ea87bb26..0bc96782 100644
--- a/layouts/_partials/posts/toc.html
+++ b/layouts/_partials/posts/toc.html
@@ -1,7 +1,8 @@
+{{ $top := cond (eq .Section "posts") "top-[19rem]" (cond (eq .Section "library") "top-[34rem]" "top-[17rem]") }}
{{ if .Params.toc }}
<div id="toc-container"
class="absolute bottom-0 left-[calc(50%_+_var(--page-width)_/_2)] right-auto
- h-full w-[calc(50%_-_var(--page-width)_/_2)] top-[19rem] hidden lg:block">
+ h-full w-[calc(50%_-_var(--page-width)_/_2)] {{ $top }} hidden lg:block">
<div id="toc"
class="sticky top-12 text-size-xs xl:text-size-sm 2xl:text-size-base w-full"
>{{ .TableOfContents }}</div>
diff --git a/layouts/library/page.html b/layouts/library/page.html
index e8760b60..1e9753a5 100644
--- a/layouts/library/page.html
+++ b/layouts/library/page.html
@@ -27,8 +27,9 @@
</p>
</header>
- <div class="markdown-body">
- <div class="leading-loose">{{ .Content }}</div>
+ <div class="markdown-body leading-loose">
+ {{ partial "posts/toc" . }}
+ <div>{{ .Content }}</div>
{{ partial "posts/endnotes" . }}
</div>
@@ -43,7 +44,7 @@
{{ $books := where (where .Site.RegularPages "Section" "library") ".Params.author" "==" .Params.author }}
{{ $thisBookID := .File.UniqueID }}
- {{ if gt (count $books) 1 }}
+ {{ if gt (len $books) 1 }}
<h2>我读过的{{ .Params.author }}的其它书籍</h2>
<div class="grid grid-cols-4 md:grid-cols-6 items-center gap-4 my-4">
{{ range $books }}
diff --git a/layouts/page.html b/layouts/page.html
index e8e4221b..7b01bf7c 100644
--- a/layouts/page.html
+++ b/layouts/page.html
@@ -3,6 +3,7 @@
<article>
<div id="post-content" class="post-content markdown-body leading-loose"
style="view-transition-name: post-content-{{ .File.UniqueID }}">
+ {{ partial "posts/toc" . }}
{{ .Content }}
</div>
</article>
diff --git a/layouts/posts/page.html b/layouts/posts/page.html
index 545be626..ef891f7e 100644
--- a/layouts/posts/page.html
+++ b/layouts/posts/page.html
@@ -37,13 +37,8 @@
<!-- Post Content -->
<div class="min-h-[60%] leading-loose mb-8 markdown-body"
style="view-transition-name: post-content-{{ .File.UniqueID }}">
- <!-- TOC -->
{{ partial "posts/toc" . }}
- <!-- Content -->
- <div id="post-content">
- {{ .Content }}
- </div>
- <!-- Endnotes -->
+ <div id="post-content">{{ .Content }}</div>
{{ partial "posts/endnotes" . }}
</div>