From 3a144b1a69679730bb1d721aae2a28008b8a9064 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Tue, 3 Dec 2024 11:00:43 +0100 Subject: Update examples for v5 (#12588) * Revert "chore: downgrade examples to not use beta releases (#12557)" This reverts commit 6031962ab5f56457de986eb82bd24807e926ba1b. * Update blog template for new content collections * Update portfolio template for new content collections * Update starlog template for new content collections --- examples/blog/src/content.config.ts | 18 ++++++++++++++++++ examples/blog/src/content/config.ts | 16 ---------------- examples/blog/src/pages/blog/[...slug].astro | 5 +++-- examples/blog/src/pages/blog/index.astro | 2 +- examples/blog/src/pages/rss.xml.js | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 examples/blog/src/content.config.ts delete mode 100644 examples/blog/src/content/config.ts (limited to 'examples/blog/src') diff --git a/examples/blog/src/content.config.ts b/examples/blog/src/content.config.ts new file mode 100644 index 000000000..7d92b1a3b --- /dev/null +++ b/examples/blog/src/content.config.ts @@ -0,0 +1,18 @@ +import { glob } from 'astro/loaders'; +import { defineCollection, z } from 'astro:content'; + +const blog = defineCollection({ + // 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(), + description: z.string(), + // Transform string to Date object + pubDate: z.coerce.date(), + updatedDate: z.coerce.date().optional(), + heroImage: z.string().optional(), + }), +}); + +export const collections = { blog }; diff --git a/examples/blog/src/content/config.ts b/examples/blog/src/content/config.ts deleted file mode 100644 index 667a31cc7..000000000 --- a/examples/blog/src/content/config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { defineCollection, z } from 'astro:content'; - -const blog = defineCollection({ - type: 'content', - // Type-check frontmatter using a schema - schema: z.object({ - title: z.string(), - description: z.string(), - // Transform string to Date object - pubDate: z.coerce.date(), - updatedDate: z.coerce.date().optional(), - heroImage: z.string().optional(), - }), -}); - -export const collections = { blog }; 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); --- 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) => (
  • - +

    {post.data.title}

    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}/`, })), }); } -- cgit v1.2.3