From 6bd7c45dd6c477c2f288a26f9dddcaff6b14d73e Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Thu, 13 Aug 2026 20:24:43 -0700 Subject: migrate codebase to astro blog v7 --- src/content.config.ts | 50 +++++++++++++++++++++++++++++++++++++++++ src/content/content.config.ts | 40 --------------------------------- src/pages/blog/[...slug].astro | 6 ++--- src/pages/blog/index.astro | 2 +- src/pages/index.astro | 4 ++-- src/pages/micro/[...slug].astro | 6 ++--- src/pages/micro/index.astro | 2 +- src/pages/rss.xml.js | 2 +- 8 files changed, 61 insertions(+), 51 deletions(-) create mode 100644 src/content.config.ts delete mode 100644 src/content/content.config.ts (limited to 'src') diff --git a/src/content.config.ts b/src/content.config.ts new file mode 100644 index 0000000..e244388 --- /dev/null +++ b/src/content.config.ts @@ -0,0 +1,50 @@ +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(), + description: z.string(), + // Transform string to Date object + pubDate: z + .string() + .or(z.date()) + .transform((val) => new Date(val)), + updatedDate: z + .string() + .optional() + .transform((str) => (str ? new Date(str) : undefined)), + heroImage: z.string().optional(), + }), +}); + +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(), + description: z.string(), + // Transform string to Date object + pubDate: z + .string() + .or(z.date()) + .transform((val) => new Date(val)), + updatedDate: z + .string() + .optional() + .transform((str) => (str ? new Date(str) : undefined)), + heroImage: z.string().optional(), + }), +}); + +export const collections = { blog, micro }; diff --git a/src/content/content.config.ts b/src/content/content.config.ts deleted file mode 100644 index e2c62ca..0000000 --- a/src/content/content.config.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { defineCollection, z } from 'astro:content'; - -const blog = defineCollection({ - // Type-check frontmatter using a schema - schema: z.object({ - title: z.string(), - description: z.string(), - // Transform string to Date object - pubDate: z - .string() - .or(z.date()) - .transform((val) => new Date(val)), - updatedDate: z - .string() - .optional() - .transform((str) => (str ? new Date(str) : undefined)), - heroImage: z.string().optional(), - }), -}); - -const micro = defineCollection({ - // Type-check frontmatter using a schema - schema: z.object({ - title: z.string(), - description: z.string(), - // Transform string to Date object - pubDate: z - .string() - .or(z.date()) - .transform((val) => new Date(val)), - updatedDate: z - .string() - .optional() - .transform((str) => (str ? new Date(str) : undefined)), - heroImage: z.string().optional(), - }), -}); - - -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); --- 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) => (
  • - {post.data.title} + {post.data.title}
  • )) } 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) => (
  • - {post.data.title} + {post.data.title}
  • )) .reverse() @@ -64,7 +64,7 @@ const microposts = (await getCollection("micro")).sort( .map((post) => (
  • - {post.data.title} + {post.data.title}
  • )) .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); --- 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) => (
  • - {post.data.title} + {post.data.title}
  • )) } 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}/`, })), }); } -- cgit v1.2.3