update astro to v5 #3

Merged
smjklake merged 1 commits from upgrade_astro_v5 into main 2024-12-03 19:19:30 -07:00
6 changed files with 760 additions and 1671 deletions

2408
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,15 +10,15 @@
"astro": "astro" "astro": "astro"
}, },
"dependencies": { "dependencies": {
"@astrojs/check": "^0.3.4", "@astrojs/check": "^0.9.4",
"@astrojs/mdx": "^2.3.1", "@astrojs/mdx": "^4.0.1",
"@astrojs/rss": "^4.0.9", "@astrojs/rss": "^4.0.9",
"@astrojs/sitemap": "^3.2.1", "@astrojs/sitemap": "^3.2.1",
"astro": "^4.16.14", "astro": "^5.0.2",
"typescript": "^5.7.2" "typescript": "^5.7.2"
}, },
"devDependencies": { "devDependencies": {
"prettier": "^3.3.3", "prettier": "^3.4.1",
"prettier-plugin-astro": "^0.12.3" "prettier-plugin-astro": "^0.14.1"
} }
} }

View File

@@ -1,7 +1,9 @@
import { glob } from 'astro/loaders';
import { defineCollection, z } from 'astro:content'; import { defineCollection, z } from 'astro:content';
const blog = defineCollection({ const blog = defineCollection({
type: 'content', // Load Markdown and MDX files in the `src/content/blog/` directory.
loader: glob({ base: './src/content/blog', pattern: '**/*.{md,mdx}' }),
// Type-check frontmatter using a schema // Type-check frontmatter using a schema
schema: z.object({ schema: z.object({
title: z.string(), title: z.string(),

View File

@@ -1,18 +1,19 @@
--- ---
import { type CollectionEntry, getCollection } from 'astro:content'; import { type CollectionEntry, getCollection } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro'; import BlogPost from '../../layouts/BlogPost.astro';
import {render} from 'astro:content';
export async function getStaticPaths() { 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,
})); }));
} }
type Props = CollectionEntry<'blog'>; type Props = CollectionEntry<'blog'>;
const post = Astro.props; const post = Astro.props;
const { Content } = await post.render(); const { Content } = await render(post);
--- ---
<BlogPost {...post.data}> <BlogPost {...post.data}>

View File

@@ -94,7 +94,7 @@ const posts = (await getCollection("blog")).sort((a, b) =>
{ {
posts.map((post) => ( posts.map((post) => (
<li> <li>
<a href={`/blog/${post.slug}/`}> <a href={`/blog/${post.id}/`}>
{post.data.heroImage && {post.data.heroImage &&
<Image <Image
width={720} width={720}

View File

@@ -10,7 +10,7 @@ export async function GET(context) {
site: context.site, site: context.site,
items: posts.map((post) => ({ items: posts.map((post) => ({
...post.data, ...post.data,
link: `/blog/${post.slug}/`, link: `/blog/${post.id}/`,
})), })),
}); });
} }