From 108789d4687dc833c7346ff1f359f9aa87117985 Mon Sep 17 00:00:00 2001 From: Abdelati Date: Sun, 20 Oct 2024 18:33:08 +0100 Subject: [PATCH] Refactor: Add team schema and update --- src/components/about/member.astro | 7 ------- src/components/about/team.astro | 3 +-- src/content/config.ts | 3 ++- src/content/shema.ts | 10 ++++++++++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/about/member.astro b/src/components/about/member.astro index 04b541ac..c6eec380 100644 --- a/src/components/about/member.astro +++ b/src/components/about/member.astro @@ -2,13 +2,6 @@ import { Image } from "astro:assets"; import { Icon } from "astro-icon/components"; -export interface MemberProps { - name: string; - x_handle: string; - profile_image: string; - status: "active" | "past"; -} - const { name, x_handle, profile_image } = Astro.props; --- diff --git a/src/components/about/team.astro b/src/components/about/team.astro index 656c81e4..11a5fa88 100644 --- a/src/components/about/team.astro +++ b/src/components/about/team.astro @@ -1,10 +1,9 @@ --- import Member from "./member.astro"; -import type { MemberProps } from "./member.astro"; import { getCollection } from "astro:content"; const teamCollection = await getCollection("team"); -const teamMembers: MemberProps[] = teamCollection.map(member => ({ +const teamMembers = teamCollection.map(member => ({ name: member.data.name, x_handle: member.data.x_handle, profile_image: member.data.profile_image, diff --git a/src/content/config.ts b/src/content/config.ts index da9e1591..95b3343b 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,7 +1,7 @@ import { file, glob } from "astro/loaders"; import { defineCollection } from "astro:content"; import { cldAssetsLoader } from "astro-cloudinary/loaders"; -import { episodeSchema } from "./shema"; +import { episodeSchema, teamSchema } from "./shema"; /** * Podcast collection * Read episodes markdown files from episodes folder in the root of the project @@ -31,6 +31,7 @@ const gallery = !import.meta.env.PUBLIC_CLOUDINARY_CLOUD_NAME const team = defineCollection({ loader: file("src/components/about/team-members.json"), + schema: teamSchema, }); export const collections = { podcast, gallery, team }; diff --git a/src/content/shema.ts b/src/content/shema.ts index a953436a..bbd5505a 100644 --- a/src/content/shema.ts +++ b/src/content/shema.ts @@ -46,3 +46,13 @@ export const episodeSchema = z dateString, }; }); + +export const teamSchema = z.object({ + id: z.number(), + name: z.string().min(1, "Name cannot be empty"), + x_handle: z.string().regex(/^@\w+$/, "Invalid Twitter handle format"), + profile_image: z + .string() + .regex(/\.(jpg|jpeg|png|gif)$/, "Invalid image file format"), + status: z.enum(["active", "past"]), +});