diff options
Diffstat (limited to 'examples/blog/src')
-rw-r--r-- | examples/blog/src/content.config.ts (renamed from examples/blog/src/content/config.ts) | 4 | ||||
-rw-r--r-- | examples/blog/src/pages/blog/[...slug].astro | 5 | ||||
-rw-r--r-- | examples/blog/src/pages/blog/index.astro | 2 | ||||
-rw-r--r-- | examples/blog/src/pages/rss.xml.js | 2 |
4 files changed, 8 insertions, 5 deletions
diff --git a/examples/blog/src/content/config.ts b/examples/blog/src/content.config.ts index 667a31cc7..7d92b1a3b 100644 --- a/examples/blog/src/content/config.ts +++ b/examples/blog/src/content.config.ts @@ -1,7 +1,9 @@ +import { glob } from 'astro/loaders'; import { defineCollection, z } from 'astro:content'; 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 schema: z.object({ title: z.string(), diff --git a/examples/blog/src/pages/blog/[...slug].astro b/examples/blog/src/pages/blog/[...slug].astro index 07dbce26b..096bd1e82 100644 --- a/examples/blog/src/pages/blog/[...slug].astro +++ b/examples/blog/src/pages/blog/[...slug].astro @@ -1,18 +1,19 @@ --- import { type CollectionEntry, getCollection } from 'astro:content'; import BlogPost from '../../layouts/BlogPost.astro'; +import { render } from 'astro:content'; 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}> diff --git a/examples/blog/src/pages/blog/index.astro b/examples/blog/src/pages/blog/index.astro index a1019da5b..1d8d02aa5 100644 --- a/examples/blog/src/pages/blog/index.astro +++ b/examples/blog/src/pages/blog/index.astro @@ -93,7 +93,7 @@ const posts = (await getCollection('blog')).sort( { posts.map((post) => ( <li> - <a href={`/blog/${post.slug}/`}> + <a href={`/blog/${post.id}/`}> <img width={720} height={360} src={post.data.heroImage} alt="" /> <h4 class="title">{post.data.title}</h4> <p class="date"> diff --git a/examples/blog/src/pages/rss.xml.js b/examples/blog/src/pages/rss.xml.js index 9ff9801e0..ae5e4c4ec 100644 --- a/examples/blog/src/pages/rss.xml.js +++ b/examples/blog/src/pages/rss.xml.js @@ -10,7 +10,7 @@ export async function GET(context) { site: context.site, items: posts.map((post) => ({ ...post.data, - link: `/blog/${post.slug}/`, + link: `/blog/${post.id}/`, })), }); } |