From 2b9f6bc5bb7b8dc02453cfa77056c2f836baa135 Mon Sep 17 00:00:00 2001 From: saicaca Date: Sun, 27 Oct 2024 16:44:12 +0800 Subject: [PATCH] feat: UX improvements for the TOC component --- src/components/widget/TOC.astro | 3 ++- src/layouts/Layout.astro | 12 ++++-------- src/layouts/MainGridLayout.astro | 25 ++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/components/widget/TOC.astro b/src/components/widget/TOC.astro index 364148a..7b4f2a1 100644 --- a/src/components/widget/TOC.astro +++ b/src/components/widget/TOC.astro @@ -45,11 +45,12 @@ let heading1Count = 1;
{heading.depth == minDepth && heading1Count++} - {heading.depth == minDepth + 1 &&
} + {heading.depth == minDepth + 1 &&
}
- {siteConfig.banner.enable && } @@ -414,8 +408,10 @@ let backToTopBtn = document.getElementById('back-to-top-btn'); let toc = document.getElementById('toc-wrapper'); let navbar = document.getElementById('navbar-wrapper') function scrollFunction() { + let bannerHeight = window.innerHeight * 0.30 + if (backToTopBtn) { - if (document.body.scrollTop > 600 || document.documentElement.scrollTop > 600) { + if (document.body.scrollTop > bannerHeight || document.documentElement.scrollTop > bannerHeight) { backToTopBtn.classList.remove('hide') } else { backToTopBtn.classList.add('hide') @@ -423,7 +419,7 @@ function scrollFunction() { } if (toc) { - if (document.body.scrollTop > 600 || document.documentElement.scrollTop > 600) { + if (document.body.scrollTop > bannerHeight || document.documentElement.scrollTop > bannerHeight) { toc.classList.remove('toc-hide') } else { toc.classList.add('toc-hide') diff --git a/src/layouts/MainGridLayout.astro b/src/layouts/MainGridLayout.astro index b532deb..3193169 100644 --- a/src/layouts/MainGridLayout.astro +++ b/src/layouts/MainGridLayout.astro @@ -8,6 +8,7 @@ import { Icon } from 'astro-icon/components' import { siteConfig } from '../config' import type { MarkdownHeading } from 'astro' import TOC from "../components/widget/TOC.astro"; +import ImageWrapper from "../components/misc/ImageWrapper.astro"; interface Props { title?: string @@ -25,6 +26,8 @@ const hasBannerLink = !!siteConfig.banner.credit.url --- + +
-
-
+ +{siteConfig.banner.enable && } + + +
+ +
@@ -69,6 +82,13 @@ const hasBannerLink = !!siteConfig.banner.credit.url
+ +
+
+ + +
+
@@ -79,7 +99,6 @@ const hasBannerLink = !!siteConfig.banner.credit.url
-