diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/content.config.ts (renamed from src/content/content.config.ts) | 12 | ||||
| -rw-r--r-- | src/pages/blog/[...slug].astro | 6 | ||||
| -rw-r--r-- | src/pages/blog/index.astro | 2 | ||||
| -rw-r--r-- | src/pages/index.astro | 4 | ||||
| -rw-r--r-- | src/pages/micro/[...slug].astro | 6 | ||||
| -rw-r--r-- | src/pages/micro/index.astro | 2 | ||||
| -rw-r--r-- | src/pages/rss.xml.js | 2 |
7 files changed, 22 insertions, 12 deletions
diff --git a/src/content/content.config.ts b/src/content.config.ts index e2c62ca..e244388 100644 --- a/src/content/content.config.ts +++ b/src/content.config.ts @@ -1,6 +1,12 @@ import { defineCollection, z } from 'astro:content'; +import { glob } from 'astro/loaders'; const blog = defineCollection({ + loader: glob({ + pattern: '**/*.{md,mdx}', + base: './src/content/blog', + generate: (entry) => entry.replace(/\.(md|mdx)$/, '').replace(/\/index$/, ''), + }), // Type-check frontmatter using a schema schema: z.object({ title: z.string(), @@ -19,6 +25,11 @@ const blog = defineCollection({ }); const micro = defineCollection({ + loader: glob({ + pattern: '**/*.{md,mdx}', + base: './src/content/micro', + generate: (entry) => entry.replace(/\.(md|mdx)$/, '').replace(/\/index$/, ''), + }), // Type-check frontmatter using a schema schema: z.object({ title: z.string(), @@ -36,5 +47,4 @@ const micro = defineCollection({ }), }); - export const collections = { blog, micro }; diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 12436c2..eb88f66 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -1,18 +1,18 @@ --- -import { CollectionEntry, getCollection } from 'astro:content'; +import { CollectionEntry, getCollection, render } from 'astro:content'; import BlogPost from '../../layouts/BlogPost.astro'; 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/src/pages/blog/index.astro b/src/pages/blog/index.astro index 11201b1..79034d4 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -42,7 +42,7 @@ const posts = (await getCollection('blog')).sort( posts.map((post) => ( <li> <FormattedDate date={post.data.pubDate} /> - <a href={`/blog/${post.slug}/`}>{post.data.title}</a> + <a href={`/blog/${post.id}/`}>{post.data.title}</a> </li> )) } diff --git a/src/pages/index.astro b/src/pages/index.astro index ec63ed6..1ef4af0 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -48,7 +48,7 @@ const microposts = (await getCollection("micro")).sort( .map((post) => ( <li> <FormattedDate date={post.data.pubDate} /> - <a href={`/blog/${post.slug}/`}>{post.data.title}</a> + <a href={`/blog/${post.id}/`}>{post.data.title}</a> </li> )) .reverse() @@ -64,7 +64,7 @@ const microposts = (await getCollection("micro")).sort( .map((post) => ( <li> <FormattedDate date={post.data.pubDate} /> - <a href={`/micro/${post.slug}/`}>{post.data.title}</a> + <a href={`/micro/${post.id}/`}>{post.data.title}</a> </li> )) .reverse() diff --git a/src/pages/micro/[...slug].astro b/src/pages/micro/[...slug].astro index 0ad6f8b..099d78f 100644 --- a/src/pages/micro/[...slug].astro +++ b/src/pages/micro/[...slug].astro @@ -1,18 +1,18 @@ --- -import { CollectionEntry, getCollection } from 'astro:content'; +import { CollectionEntry, getCollection, render } from 'astro:content'; import BlogPost from '../../layouts/BlogPost.astro'; export async function getStaticPaths() { const posts = await getCollection('micro'); return posts.map((post) => ({ - params: { slug: post.slug }, + params: { slug: post.id }, props: post, })); } type Props = CollectionEntry<'micro'>; const post = Astro.props; -const { Content } = await post.render(); +const { Content } = await render(post); --- <BlogPost {...post.data}> diff --git a/src/pages/micro/index.astro b/src/pages/micro/index.astro index 7393216..1abc9df 100644 --- a/src/pages/micro/index.astro +++ b/src/pages/micro/index.astro @@ -42,7 +42,7 @@ const posts = (await getCollection('micro')).sort( posts.map((post) => ( <li> <FormattedDate date={post.data.pubDate} /> - <a href={`/micro/${post.slug}/`}>{post.data.title}</a> + <a href={`/micro/${post.id}/`}>{post.data.title}</a> </li> )) } diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 83f4946..5c0c9bc 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -17,7 +17,7 @@ export async function GET(context) { site: context.site, items: posts.map((post) => ({ ...post.data, - link: `/${post.collection}/${post.slug}/`, + link: `/${post.collection}/${post.id}/`, })), }); } |
