From f90592d8a106bea418cbd3d8bce9c2d86029f93c Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 9 Apr 2026 08:47:37 +0000 Subject: feat: migrated to Astro 6 --- src/components/PostElement.astro | 6 +++--- src/components/Sections/LatestPosts.astro | 2 +- src/content.config.ts | 18 ++++++++++++++++++ src/content/config.ts | 16 ---------------- src/pages/blog/[...slug].astro | 10 +++++----- src/pages/feed.xml.js | 5 ++--- src/utils/schemas/blogSchema.ts | 2 +- 7 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 src/content.config.ts delete mode 100644 src/content/config.ts (limited to 'src') diff --git a/src/components/PostElement.astro b/src/components/PostElement.astro index 8b4b7c4..051a8ff 100644 --- a/src/components/PostElement.astro +++ b/src/components/PostElement.astro @@ -1,5 +1,5 @@ --- -import { type CollectionEntry } from "astro:content"; +import { type CollectionEntry, render } from "astro:content"; import dayjs from "dayjs"; type Props = { @@ -7,7 +7,7 @@ type Props = { }; const { post } = Astro.props; -const { remarkPluginFrontmatter } = await post.render(); +const { remarkPluginFrontmatter } = await render(post); const formattedDate = dayjs(post.data.datePublished.toString()).format("MMMM DD, YYYY"); const datePublished = post.data.datePublished.toISOString(); @@ -28,7 +28,7 @@ const datePublished = post.data.datePublished.toISOString();
  • - {post.data.title} + {post.data.title}
    diff --git a/src/components/Sections/LatestPosts.astro b/src/components/Sections/LatestPosts.astro index e514ff5..5c6afd9 100644 --- a/src/components/Sections/LatestPosts.astro +++ b/src/components/Sections/LatestPosts.astro @@ -27,7 +27,7 @@ const latestPosts = posts.slice(0, 5); { latestPosts.map((post) => (
  • - + {post.data.title} diff --git a/src/content.config.ts b/src/content.config.ts new file mode 100644 index 0000000..189848c --- /dev/null +++ b/src/content.config.ts @@ -0,0 +1,18 @@ +import { defineCollection } from "astro:content"; +import { glob } from "astro/loaders"; +import { z } from "astro/zod"; + +const blog = defineCollection({ + loader: glob({ pattern: "**/*.md", base: "./src/content/blog" }), + schema: z.object({ + basedOn: z.optional(z.string()), + dateModified: z.coerce.date(), + datePublished: z.coerce.date(), + description: z.string(), + draft: z.optional(z.boolean()), + lang: z.string(), + title: z.string(), + }), +}); + +export const collections = { blog }; diff --git a/src/content/config.ts b/src/content/config.ts deleted file mode 100644 index 4277edc..0000000 --- a/src/content/config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { defineCollection, z } from "astro:content"; - -const blog = defineCollection({ - type: "content", - schema: z.object({ - basedOn: z.optional(z.string()), - dateModified: z.coerce.date(), - datePublished: z.coerce.date(), - description: z.string(), - draft: z.optional(z.boolean()), - lang: z.string(), - title: z.string(), - }), -}); - -export const collections = { blog }; diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index d12ff05..3bd2c61 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -1,5 +1,5 @@ --- -import { type CollectionEntry, getCollection } from "astro:content"; +import { type CollectionEntry, getCollection, render } from "astro:content"; import Comments from "../../components/Comments.astro"; import Layout from "../../layouts/BaseLayout.astro"; import blogPostSchema from "../../utils/schemas/blogPostSchema"; @@ -13,20 +13,20 @@ export async function getStaticPaths() { }); return posts.map((post) => ({ - params: { slug: post.slug }, + params: { slug: post.id }, props: post, })); } const post = Astro.props; -const { Content, remarkPluginFrontmatter } = await post.render(); +const { Content, remarkPluginFrontmatter } = await render(post); const description = post.data.description; const isBasedOn = post.data.basedOn; const lang = post.data.lang; -const preview = `/images/preview/${post.slug}.png`; -const slug = post.slug; +const preview = `/images/preview/${post.id}.png`; +const slug = post.id; const title = post.data.title; const dateModified = post.data.dateModified?.toISOString(); diff --git a/src/pages/feed.xml.js b/src/pages/feed.xml.js index 7c41b4f..5aea78b 100644 --- a/src/pages/feed.xml.js +++ b/src/pages/feed.xml.js @@ -13,10 +13,9 @@ export async function GET(context) { customData: `en`, description: description, items: posts.map((post) => ({ - customData: post.data.customData, description: post.data.description, - link: `/blog/${post.slug}`, - pubDate: post.data.pubDate, + link: `/blog/${post.id}`, + pubDate: post.data.datePublished, title: post.data.title, })), site: context.site, diff --git a/src/utils/schemas/blogSchema.ts b/src/utils/schemas/blogSchema.ts index 77f4632..196f037 100644 --- a/src/utils/schemas/blogSchema.ts +++ b/src/utils/schemas/blogSchema.ts @@ -19,7 +19,7 @@ export default ({ siteUrl, title, posts }: BlogSchemaParams): WithContext ({ "@type": "ListItem", "position": index + 1, - "url": new URL(`/blog/${post.slug}`, siteUrl).toString(), + "url": new URL(`/blog/${post.id}`, siteUrl).toString(), "name": post.data.title, })), }, -- cgit v1.2.3