Skip to content

Commit

Permalink
Refactor: Add team schema and update
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizendae authored and yjose committed Oct 20, 2024
1 parent 4f7484e commit 108789d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 0 additions & 7 deletions src/components/about/member.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
---

Expand Down
3 changes: 1 addition & 2 deletions src/components/about/team.astro
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 };
10 changes: 10 additions & 0 deletions src/content/shema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
});

0 comments on commit 108789d

Please sign in to comment.