Upgrades to Astro 5

This commit is contained in:
2024-12-24 09:26:32 +00:00
parent b080e56314
commit 532f75bea0
6 changed files with 2556 additions and 1734 deletions

View File

@@ -1,8 +1,9 @@
import { glob } from 'astro/loaders';
import { defineCollection, z } from 'astro:content';
const blog = defineCollection({
type: 'content',
schema: z.object({
loader: glob({ pattern: '**/*.(md|mdx|html)', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
hidden: z.optional(z.boolean()),
description: z.string(),

View File

@@ -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);
---
<BlogPost {...post.data}>
<Content />
</BlogPost>
</BlogPost>

View File

@@ -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',