From 532f75bea033e8073c4c1bc1dff72fa6af7d5316 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 24 Dec 2024 09:26:32 +0000 Subject: Upgrades to Astro 5 --- website/src/content.config.ts | 15 +++++++++++++++ website/src/content/config.ts | 14 -------------- website/src/pages/blog/[...slug].astro | 8 ++++---- website/src/pages/blog/rss.xml.ts | 4 ++-- 4 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 website/src/content.config.ts delete mode 100644 website/src/content/config.ts (limited to 'website/src') diff --git a/website/src/content.config.ts b/website/src/content.config.ts new file mode 100644 index 0000000..5436030 --- /dev/null +++ b/website/src/content.config.ts @@ -0,0 +1,15 @@ +import { glob } from 'astro/loaders'; +import { defineCollection, z } from 'astro:content'; + +const blog = defineCollection({ + loader: glob({ pattern: '**/*.(md|mdx|html)', base: './src/content/blog' }), + schema: z.object({ + title: z.string(), + hidden: z.optional(z.boolean()), + description: z.string(), + pubDate: z.date(), + updatedDate: z.optional(z.date()), + }), +}); + +export const collections = { blog }; diff --git a/website/src/content/config.ts b/website/src/content/config.ts deleted file mode 100644 index dfdf403..0000000 --- a/website/src/content/config.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { defineCollection, z } from 'astro:content'; - -const blog = defineCollection({ - type: 'content', - schema: z.object({ - title: z.string(), - hidden: z.optional(z.boolean()), - description: z.string(), - pubDate: z.date(), - updatedDate: z.optional(z.date()), - }), -}); - -export const collections = { blog }; diff --git a/website/src/pages/blog/[...slug].astro b/website/src/pages/blog/[...slug].astro index 800c534..0754ea7 100644 --- a/website/src/pages/blog/[...slug].astro +++ b/website/src/pages/blog/[...slug].astro @@ -1,20 +1,20 @@ --- -import { type CollectionEntry, getCollection } from 'astro:content'; +import { type CollectionEntry, getCollection, render } from 'astro:content'; import BlogPost from '../../layouts/BlogPost.astro'; export async function getStaticPaths() { const posts = await getCollection('blog'); return posts.map((post) => ({ - params: { slug: post.slug }, + params: { slug: post.id }, props: post, })); } type Props = CollectionEntry<'blog'>; const post = Astro.props; -const { Content } = await post.render(); +const { Content } = await render(post); --- - \ No newline at end of file + diff --git a/website/src/pages/blog/rss.xml.ts b/website/src/pages/blog/rss.xml.ts index afd0640..5b90fd0 100644 --- a/website/src/pages/blog/rss.xml.ts +++ b/website/src/pages/blog/rss.xml.ts @@ -23,9 +23,9 @@ export async function GET(context: APIContext) { site: path.join(site.toString(), 'blog'), trailingSlash: false, items: posts.map((post) => ({ - link: `/blog/${post.slug}`, + link: `/blog/${post.id}`, title: post.data.title, - content: mdParser.render(post.body), + content: mdParser.render(post.body ?? ''), pubDate: post.data.pubDate, description: post.data.description, author: 'Joe Carstairs', -- cgit v1.2.3