Update Astro to 5.0 and adapt content collections to breaking changes

This commit is contained in:
Maciej Pędzich 2024-12-11 10:55:52 +01:00
parent 928b9dee13
commit b4df9225aa
Signed by: maciejpedzich
GPG Key ID: CE4A303D84882F0D
5 changed files with 1296 additions and 1574 deletions

2850
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,10 +10,10 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/mdx": "^3.1.7",
"@astrojs/rss": "^4.0.7",
"@astrojs/sitemap": "^3.1.6",
"@fontsource/roboto": "^5.0.13",
"astro": "^4.16.3"
"@astrojs/mdx": "^4.0.2",
"@astrojs/rss": "^4.0.10",
"@astrojs/sitemap": "^3.2.1",
"@fontsource/roboto": "^5.1.0",
"astro": "^5.0.4"
}
}

View File

@ -28,7 +28,7 @@ const posts = (
<ul class="post-list">
{posts.map((post) => (
<li>
<a href={`/blog/${post.slug}`}>{post.data.title}</a>
<a href={`/blog/${post.id}`}>{post.data.title}</a>
</li>
))}
</ul>

View File

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

View File

@ -1,6 +1,6 @@
---
import type { CollectionEntry } from 'astro:content';
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro';
import TableOfContents from '../../components/TableOfContents.astro';
@ -9,7 +9,7 @@ export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({
params: { slug: post.slug },
params: { slug: post.id },
props: post
}));
}
@ -17,7 +17,7 @@ export async function getStaticPaths() {
type Props = CollectionEntry<'blog'>;
const post = Astro.props;
const { Content, headings } = await post.render();
const { Content, headings } = await render(post);
---
<BlogPost {...post.data}>