From 49d33349e2075b295fa9e9f68cffd3bbc5d1353d Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Tue, 9 Jun 2026 19:33:48 +0530 Subject: [PATCH] fix: finish astro v6 migration --- src/{content/config.js => content.config.js} | 90 ++++++++++++-------- src/pages/blog/[...slug].astro | 6 +- src/pages/blog/index.astro | 2 +- 3 files changed, 59 insertions(+), 39 deletions(-) rename src/{content/config.js => content.config.js} (51%) diff --git a/src/content/config.js b/src/content.config.js similarity index 51% rename from src/content/config.js rename to src/content.config.js index 056bebc..834d63e 100644 --- a/src/content/config.js +++ b/src/content.config.js @@ -1,35 +1,38 @@ -// 1. Import utilities from `astro:content` -import { z, defineCollection, reference } from 'astro:content'; +import { defineCollection } from "astro:content"; +import { glob } from "astro/loaders"; +import { z } from "astro/zod"; -// 2. Define a `type` and `schema` for each collection const strings = defineCollection({ - type: 'data', // v2.5.0 and later + loader: glob({ + base: "./src/content/strings", + pattern: "**/*.json", + }), schema: z.object({ header: z.object({ apps: z.string(), blog: z.string(), team: z.string(), - about: z.string() + about: z.string(), }), hero: z.object({ title: z.string(), subtitle: z.string(), - donate: z.string() + donate: z.string(), }), profile: z.object({ title: z.string(), subtitle: z.string(), about: z.object({ - description: z.string() + description: z.string(), }), vision: z.object({ title: z.string(), - text: z.string() + text: z.string(), }), mission: z.object({ title: z.string(), - text: z.string() - }) + text: z.string(), + }), }), donation: z.object({ title: z.string(), @@ -40,7 +43,7 @@ const strings = defineCollection({ description: z.string(), hint: z.string(), label: z.string(), - close: z.string() + close: z.string(), }), contributors: z.object({ title: z.string(), @@ -51,34 +54,44 @@ const strings = defineCollection({ description: z.string(), }), footer: z.object({ - copyright: z.string() - }) + copyright: z.string(), + }), }), }); const apps = defineCollection({ - type: "data", - schema: ({ image }) => z.object({ - isDraft: z.boolean(), - title: z.string(), - description: z.string(), - featuresTitle: z.string(), - features: z.array(z.string()), - img: image(), - }) -}) + loader: glob({ + base: "./src/content/apps", + pattern: "**/*.json", + }), + schema: ({ image }) => + z.object({ + isDraft: z.boolean(), + title: z.string(), + description: z.string(), + featuresTitle: z.string(), + features: z.array(z.string()), + img: image(), + }), +}); const links = defineCollection({ - type: "data", + loader: glob({ + base: "./src/content/links", + pattern: "**/*.json", + }), schema: z.object({ - github: z.string().url(), - play: z.string().url().optional(), - fdroid: z.string().url().optional() - }) -}) + github: z.url(), + play: z.url().optional(), + fdroid: z.url().optional(), + }), +}); const blog = defineCollection({ - type: "content", + loader: glob({ + base: "./src/content/blog", + pattern: "**/*.{md,mdx}", + }), schema: ({ image }) => z.object({ isDraft: z.boolean(), @@ -86,13 +99,20 @@ const blog = defineCollection({ summary: z.string(), tags: z.array(z.string()).optional(), author: z.string().default("Anonymous"), - date: z.date(), - updatedAt: z.date().optional(), - image: z.object({ src: image(), alt: z.string() }).optional(), + date: z.coerce.date(), + updatedAt: z.coerce.date().optional(), + image: z + .object({ + src: image(), + alt: z.string(), + }) + .optional(), }), }); -// 3. Export a single `collections` object to register your collection(s) export const collections = { - strings, apps, links, blog + strings, + apps, + links, + blog, }; \ No newline at end of file diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 4703949..e6063d8 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -1,14 +1,14 @@ --- import Layout from "../../layouts/Layout.astro"; import DateFormat from "../../components/DateFormat.astro"; -import { getCollection } from "astro:content"; +import { getCollection, render } from "astro:content"; import type { CollectionEntry } from "astro:content"; import { Image } from "astro:assets"; export async function getStaticPaths() { const blog = await getCollection("blog"); return blog.map((post) => ({ - params: { slug: post.slug }, + params: { slug: post.id }, props: { post }, })); } @@ -20,7 +20,7 @@ interface Props { const { post } = Astro.props; const { title, summary, author, date, image, tags } = post.data; -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 2a45de0..4b0b9b0 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -25,7 +25,7 @@ const posts = blogPosts

Latest blog posts

{ posts.map((post) => ( - + ))