diff options
author | 2024-12-03 11:00:43 +0100 | |
---|---|---|
committer | 2024-12-03 11:00:43 +0100 | |
commit | 3a144b1a69679730bb1d721aae2a28008b8a9064 (patch) | |
tree | 3f385ce8140726e47b9a6b9862655748139456e4 /examples/blog/src | |
parent | 1dc8f5eb7c515c89aadc85cfa0a300d4f65e8671 (diff) | |
download | astro-3a144b1a69679730bb1d721aae2a28008b8a9064.tar.gz astro-3a144b1a69679730bb1d721aae2a28008b8a9064.tar.zst astro-3a144b1a69679730bb1d721aae2a28008b8a9064.zip |
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
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}/`, })), }); } |