From b6802e93d8621efb82c3cdb61c8c45175740af9f Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Sun, 7 Apr 2024 14:45:09 -0700 Subject: [PATCH] refactor: isolate tocstore and move tocheader into navbar --- src/lib/components/Navbar/Navbar.svelte | 15 +++++++++++++++ src/lib/components/Toc/TocHeader.svelte | 9 ++++++--- src/lib/stores.ts | 3 +++ src/routes/blog/[year]/[slug]/+page.svelte | 7 ++----- 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/lib/stores.ts diff --git a/src/lib/components/Navbar/Navbar.svelte b/src/lib/components/Navbar/Navbar.svelte index e142629..643a7ac 100644 --- a/src/lib/components/Navbar/Navbar.svelte +++ b/src/lib/components/Navbar/Navbar.svelte @@ -8,8 +8,11 @@ import ThemePicker from '../ThemePicker.svelte'; import Button from '../ui/button/button.svelte'; import { Moon, Sun } from 'svelte-radix'; + import { tocStore } from '$lib/stores'; + import TocHeader from '../Toc/TocHeader.svelte'; let current: 'blog' | 'about' | 'home' | 'portfolio' | string; + let readingPost = false; const updateCurrent = () => { const path = window.location.pathname; @@ -17,8 +20,17 @@ current = 'home'; } else { const segments = path.split('/'); + current = segments[1] || 'home'; + if (current === 'blog' && segments.length > 2) { + readingPost = true; + console.log(readingPost); + } else { + readingPost = false; + console.log(readingPost); + } } + console.log(current); }; onMount(() => { @@ -66,6 +78,9 @@ +{#if readingPost} + +{/if}