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" "astro": "astro"
}, },
"dependencies": { "dependencies": {
"@astrojs/mdx": "^3.1.7", "@astrojs/mdx": "^4.0.2",
"@astrojs/rss": "^4.0.7", "@astrojs/rss": "^4.0.10",
"@astrojs/sitemap": "^3.1.6", "@astrojs/sitemap": "^3.2.1",
"@fontsource/roboto": "^5.0.13", "@fontsource/roboto": "^5.1.0",
"astro": "^4.16.3" "astro": "^5.0.4"
} }
} }

View File

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

View File

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

View File

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