From 772f0a9a5e7d9c1fac005bb9c136e062de1f6a87 Mon Sep 17 00:00:00 2001 From: foxton9 Date: Mon, 28 Apr 2025 18:48:36 +0800 Subject: [PATCH] fix: TOC warning on home page (#402) - conditionally render TOC for posts route; - change warn to debug. --- src/components/widget/TOC.astro | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/widget/TOC.astro b/src/components/widget/TOC.astro index d3c02456..9a3977b9 100644 --- a/src/components/widget/TOC.astro +++ b/src/components/widget/TOC.astro @@ -16,6 +16,8 @@ for (const heading of headings) { const className = Astro.props.class; +const isPostsRoute = Astro.url.pathname.startsWith("/posts/"); + const removeTailingHash = (text: string) => { let lastIndexOfHash = text.lastIndexOf("#"); if (lastIndexOfHash !== text.length - 1) { @@ -29,6 +31,7 @@ let heading1Count = 1; const maxLevel = siteConfig.toc.depth; --- +{isPostsRoute && {headings.filter((heading) => heading.depth < minDepth + maxLevel).map((heading) => - - +}