From ce4a2015086f1c7ef686fa60f1887d2b99671be0 Mon Sep 17 00:00:00 2001 From: biss Date: Thu, 18 Jun 2026 16:03:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=8C=BA=20=E4=BE=A7?= =?UTF-8?q?=E8=BE=B9=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ArticleSidebar.astro | 50 +++++++- src/components/TwikooComments.astro | 72 +++++++++++ src/layouts/BaseLayout.astro | 11 ++ src/lib/posts.ts | 2 + src/pages/posts/[slug].astro | 48 +++++++ src/styles/site.css | 192 +++++++++++++++++++++++++++- 6 files changed, 368 insertions(+), 7 deletions(-) create mode 100644 src/components/TwikooComments.astro diff --git a/src/components/ArticleSidebar.astro b/src/components/ArticleSidebar.astro index eb2305a..8317afa 100644 --- a/src/components/ArticleSidebar.astro +++ b/src/components/ArticleSidebar.astro @@ -7,6 +7,11 @@ type TocItem = { id: string; }; +type TocSection = { + heading: TocItem; + children: TocItem[]; +}; + interface Props { post: BlogPost; toc: TocItem[]; @@ -15,6 +20,16 @@ interface Props { const { post, toc, relatedPosts } = Astro.props; const avatar = 'https://free.picui.cn/free/2025/08/10/689845496a283.png'; +const topDepth = toc.length > 0 ? Math.min(...toc.map((item) => item.depth)) : 1; +const tocSections = toc.reduce((sections, item) => { + if (item.depth <= topDepth || sections.length === 0) { + sections.push({ heading: item, children: [] }); + } else { + sections[sections.length - 1].children.push(item); + } + + return sections; +}, []); ---