From 24e0a6f1ffa4e2a97e7b27a1da431afbd1e0a3a7 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Sat, 6 Apr 2024 18:31:45 -0700 Subject: [PATCH] feat: overhaul sticky toc styling --- src/lib/components/Blog/Article.svelte | 2 + src/lib/components/StickyToc.svelte | 72 ---------------------- src/lib/components/Toc/StickyToc.svelte | 34 ++++++++++ src/routes/blog/[year]/[slug]/+page.svelte | 56 +++++++---------- 4 files changed, 59 insertions(+), 105 deletions(-) delete mode 100644 src/lib/components/StickyToc.svelte create mode 100644 src/lib/components/Toc/StickyToc.svelte diff --git a/src/lib/components/Blog/Article.svelte b/src/lib/components/Blog/Article.svelte index 9ea3c30..debe5cb 100644 --- a/src/lib/components/Blog/Article.svelte +++ b/src/lib/components/Blog/Article.svelte @@ -1,6 +1,7 @@ @@ -31,5 +32,6 @@
{@html doc.content} +
diff --git a/src/lib/components/StickyToc.svelte b/src/lib/components/StickyToc.svelte deleted file mode 100644 index 93da107..0000000 --- a/src/lib/components/StickyToc.svelte +++ /dev/null @@ -1,72 +0,0 @@ - - - diff --git a/src/lib/components/Toc/StickyToc.svelte b/src/lib/components/Toc/StickyToc.svelte new file mode 100644 index 0000000..0819fef --- /dev/null +++ b/src/lib/components/Toc/StickyToc.svelte @@ -0,0 +1,34 @@ + + + + +

On this page

+
+ + {#if $tocStore.items.size} +
    + {#each $tocStore.items.values() as tocItem} +
  1. + + +
  2. + {/each} +
+ {/if} + + diff --git a/src/routes/blog/[year]/[slug]/+page.svelte b/src/routes/blog/[year]/[slug]/+page.svelte index ecec4dd..6bcc36b 100644 --- a/src/routes/blog/[year]/[slug]/+page.svelte +++ b/src/routes/blog/[year]/[slug]/+page.svelte @@ -6,24 +6,9 @@ import { cn } from '$lib/utils.js'; import Article from '$lib/components/Blog/Article.svelte'; import { toc, createTocStore } from '@svelte-put/toc'; - import StickyToc from '$lib/components/StickyToc.svelte'; + import StickyToc from '$lib/components/Toc/StickyToc.svelte'; import { onMount } from 'svelte'; - let distanceFromRight = 0; - - let mainElement: HTMLElement; - - const handleResize = () => { - const screenWidth = window.innerWidth; - const mainWidth = mainElement.offsetWidth; - distanceFromRight = screenWidth - mainWidth - mainElement.offsetLeft; - console.log(distanceFromRight); - }; - - onMount(() => { - handleResize(); - }); - const tocStore = createTocStore(); export let data: PageData; @@ -48,21 +33,26 @@ - +
+
+
+
-
-
-
- - + +