diff options
| author | Nikhil M Warrier <nikhilmw.dev@gmail.com> | 2026-03-13 08:52:29 +0530 |
|---|---|---|
| committer | Nikhil M Warrier <nikhilmw.dev@gmail.com> | 2026-03-13 08:52:29 +0530 |
| commit | 30a3651c17bfd8a771feaaaa4cb700788b757f80 (patch) | |
| tree | 1a7560a6d9e0144c59a4792bcb629ea150564301 /src/content.config.ts | |
| parent | 102a717ae001564349c2f0b2992459d6d5f91d08 (diff) | |
feat: Add forms
Diffstat (limited to 'src/content.config.ts')
| -rw-r--r-- | src/content.config.ts | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/content.config.ts b/src/content.config.ts index 1bd3526..c9c4810 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -48,6 +48,42 @@ const members = defineCollection({ }), }) +const forms = defineCollection({ + loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/forms' }), + schema: () => + z.object({ + title: z.string(), + description: z.string(), + date: z.coerce.date(), + // sqlite-safe + id: z.string().regex(/^[a-zA-Z0-9_]+$/, { + message: + "Form 'id' can only contain letters, numbers, and underscores.", + }), + submit_text: z.string().default('Submit'), + form: z.object({ + submit_text: z.string().default('Submit'), + fields: z + .array( + z.object({ + id: z.string().regex(/^[a-zA-Z0-9_]+$/, { + message: + "Field 'name' can only contain letters, numbers, and underscores.", + }), + label: z.string(), + type: z + .enum(['text', 'email', 'number', 'textarea', 'tel', 'url']) + .default('text'), + required: z.boolean().default(false), + }), + ) + .min(1, { + message: 'A form must have at least one field defined.', + }), + }), + }), +}) + const projects = defineCollection({ loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/projects' }), schema: ({ image }) => @@ -62,4 +98,4 @@ const projects = defineCollection({ }), }) -export const collections = { events, blog, members, projects } +export const collections = { events, blog, members, projects, forms } |
