diff --git a/apps/www/src/pages/draft/[slug].astro b/apps/www/src/pages/draft/[slug].astro new file mode 100644 index 0000000..21028c6 --- /dev/null +++ b/apps/www/src/pages/draft/[slug].astro @@ -0,0 +1,49 @@ +--- +export const prerender = false; + +import { getSession } from 'auth-astro/server'; +import { getCollection, render } from 'astro:content'; +import { isAdmin } from '../../lib/auth'; +import Layout from '../../layouts/Layout.astro'; + +let session; +try { + session = await getSession(Astro.request); +} catch { + return new Response('Auth not configured', { status: 500 }); +} + +if (!session) { + return Astro.redirect('/api/auth/signin'); +} + +if (!isAdmin(session.user?.id)) { + return new Response('Forbidden', { status: 403 }); +} + +const slug = Astro.params.slug; +const posts = await getCollection('posts', ({ data }) => data.draft === true); +const post = posts.find(p => p.id === slug); + +if (!post) { + return new Response('Not found', { status: 404 }); +} + +const { Content } = await render(post); + +function formatDate(date: Date): string { + const d = String(date.getDate()).padStart(2, '0'); + const m = String(date.getMonth() + 1).padStart(2, '0'); + const y = String(date.getFullYear()).slice(-2); + return `${d}/${m}/${y}`; +} +--- + + +
+

[DRAFT] back to drafts

+

{post.data.title}

+

{formatDate(post.data.date)}

+ +
+