diff --git a/src/routes/posts/[slug]/+page.server.ts b/src/routes/posts/[slug]/+page.server.ts index c1d7475..353b4d7 100644 --- a/src/routes/posts/[slug]/+page.server.ts +++ b/src/routes/posts/[slug]/+page.server.ts @@ -32,7 +32,11 @@ export const load: PageServerLoad = async ({ platform, params }) => { content: dummyMarkdown, date: '2026-07-12', author: 'Admin' - } + }, + tags: [ + { name: 'Welcome', id: 1 }, + { name: 'Design', id: 2 } + ] }; } @@ -48,11 +52,20 @@ export const load: PageServerLoad = async ({ platform, params }) => { error(404, 'Post not found'); } + const tagsQuery: any = await db.prepare( + `SELECT t.name, t.id + FROM tags t + JOIN post_tags pt ON t.id = pt.tag_id + WHERE pt.post_id = ?` + ).bind(post.id).all(); + const tags = tagsQuery.results || []; + return { post: { ...post, date: new Date(post.date as string).toLocaleDateString() - } + }, + tags }; } catch (err) { console.error('Error fetching post:', err); diff --git a/src/routes/posts/[slug]/+page.svelte b/src/routes/posts/[slug]/+page.svelte index 75c3251..54d1690 100644 --- a/src/routes/posts/[slug]/+page.svelte +++ b/src/routes/posts/[slug]/+page.svelte @@ -156,6 +156,18 @@ sidebarShow = false; } + $effect(() => { + if (sidebarShow) { + document.body.classList.add('sidebar-show'); + } else { + document.body.classList.remove('sidebar-show'); + } + + return () => { + document.body.classList.remove('sidebar-show'); + }; + }); + // 绑定 Fancybox Fancybox.bind('[data-fancybox]', {}); @@ -276,20 +288,28 @@