From a1d7bd8fdb437085e864669fb51ecfdf3c021de0 Mon Sep 17 00:00:00 2001 From: lew Date: Sun, 8 Feb 2026 17:15:51 +0000 Subject: [PATCH] feat: add /dnd/ routes --- www/src/pages/dnd/[slug].astro | 38 ++++++++++++++++++++++++++++++++++ www/src/pages/dnd/index.astro | 35 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 www/src/pages/dnd/[slug].astro create mode 100644 www/src/pages/dnd/index.astro diff --git a/www/src/pages/dnd/[slug].astro b/www/src/pages/dnd/[slug].astro new file mode 100644 index 0000000..78b505f --- /dev/null +++ b/www/src/pages/dnd/[slug].astro @@ -0,0 +1,38 @@ +--- +export const prerender = false; + +import { getCollection, render } from 'astro:content'; +import { requireAdminSession } from '../../lib/auth'; +import Layout from '../../layouts/Layout.astro'; +import { getSlug, resolveRelatedPosts } from '../../lib/dnd'; + +const { session, error } = await requireAdminSession(Astro.request); +if (error) return error; +if (!session) return Astro.redirect('/api/auth/signin'); + +const slug = Astro.params.slug; +const allPosts = await getCollection('dnd'); +const post = allPosts.find(p => getSlug(p.id) === slug); + +if (!post) { + return new Response('Not found', { status: 404 }); +} + +const { Content } = await render(post); +const related = post.data.related ? resolveRelatedPosts(post.data.related, allPosts) : []; +--- + + +
+

{post.data.title}

+ +
+{related.length > 0 && ( +
+ related +
+      `${p.data.title}`
+    ).join('\n')} />
+  
+)} +
diff --git a/www/src/pages/dnd/index.astro b/www/src/pages/dnd/index.astro new file mode 100644 index 0000000..2a14df3 --- /dev/null +++ b/www/src/pages/dnd/index.astro @@ -0,0 +1,35 @@ +--- +export const prerender = false; + +import { getCollection } from 'astro:content'; +import { requireAdminSession } from '../../lib/auth'; +import Layout from '../../layouts/Layout.astro'; +import { organizePostsByCategory, getSlug } from '../../lib/dnd'; +import map from '../../content/dnd/drakkenheim/map.jpg'; + +const { session, error } = await requireAdminSession(Astro.request); +if (error) return error; +if (!session) return Astro.redirect('/api/auth/signin'); + +const posts = await getCollection('dnd'); +const { grouped, categories: sortedCategories } = organizePostsByCategory(posts); +--- + + +

logged in as {session.user?.name} sign out

+ +Drakkenheim map + +{sortedCategories.length === 0 ? ( +

nothing here

+) : ( + sortedCategories.map(category => ( +
+ {category} +
+        `${post.data.title}${post.data.pinned ? ' [pinned]' : ''}`
+      ).join('\n')} />
+    
+ )) +)} +