From 36d09dcaa226edea1a572609bbbbd0fae826d1d0 Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Sat, 27 May 2023 16:00:57 +0200 Subject: [PATCH] refactor: move schemas into individual files --- src/content/config.ts | 87 +++------------------------------------ src/schema/ai-art.ts | 15 +++++++ src/schema/haiku.ts | 9 ++++ src/schema/index.ts | 4 ++ src/schema/projects.ts | 42 +++++++++++++++++++ src/schema/sketchnotes.ts | 15 +++++++ 6 files changed, 90 insertions(+), 82 deletions(-) create mode 100644 src/schema/ai-art.ts create mode 100644 src/schema/haiku.ts create mode 100644 src/schema/index.ts create mode 100644 src/schema/projects.ts create mode 100644 src/schema/sketchnotes.ts diff --git a/src/content/config.ts b/src/content/config.ts index 4c5a744..17ff8ef 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,85 +1,8 @@ -import { defineCollection, z } from 'astro:content'; - -const haikuCollection = defineCollection({ - schema: z.object({ - date: z.date(), - de: z.string(), - en: z.string(), - }), -}); - -const projectCollection = defineCollection({ - schema: z.object({ - title: z.string(), - format: z.enum(['100-end', '100-start', '50-end', '50-start', '70-end', '70-start']), - image: z - .object({ - src: z.string(), - height: z.number().optional(), - width: z.number().optional(), - aspectRatio: z.number().optional(), - }) - .optional(), - sort: z.number().optional(), - showcase: z.boolean().optional(), - description: z.string().optional(), - intro: z.string().optional(), - categories: z.array( - z.enum([ - 'Design', - 'Graphic Design', - 'Icon Design', - 'Illustration', - 'Painting', - 'Photography', - 'Poetry', - 'Typeface Design', - 'Web Design', - 'Web Development', - 'Writing', - ]) - ), - more: z - .object({ - text: z.string().optional(), - link: z.string(), - }) - .optional(), - class: z.string().optional(), - }), -}); - -const sketchnotesCollection = defineCollection({ - schema: z.object({ - title: z.string(), - sort: z.number().optional(), - coverSize: z.enum(['small', 'medium', 'large']).default('small'), - images: z.array( - z.object({ - src: z.string(), - aspectRatio: z.number(), - }) - ), - }), -}); - -const aiArtCollection = defineCollection({ - schema: z.object({ - title: z.string(), - sort: z.number().optional(), - coverSize: z.enum(['small', 'medium', 'large']).default('small'), - images: z.array( - z.object({ - src: z.string(), - aspectRatio: z.number(), - }) - ), - }), -}); +import { aiArt, haiku, projects, sketchnotes } from '../schema'; export const collections = { - haiku: haikuCollection, - projects: projectCollection, - sketchnotes: sketchnotesCollection, - 'ai-art': aiArtCollection, + haiku: haiku, + projects: projects, + sketchnotes: sketchnotes, + 'ai-art': aiArt, }; diff --git a/src/schema/ai-art.ts b/src/schema/ai-art.ts new file mode 100644 index 0000000..faefaa1 --- /dev/null +++ b/src/schema/ai-art.ts @@ -0,0 +1,15 @@ +import { defineCollection, z } from 'astro:content'; + +export const aiArt = defineCollection({ + schema: z.object({ + title: z.string(), + sort: z.number().optional(), + coverSize: z.enum(['small', 'medium', 'large']).default('small'), + images: z.array( + z.object({ + src: z.string(), + aspectRatio: z.number(), + }) + ), + }), +}); diff --git a/src/schema/haiku.ts b/src/schema/haiku.ts new file mode 100644 index 0000000..37f814a --- /dev/null +++ b/src/schema/haiku.ts @@ -0,0 +1,9 @@ +import { defineCollection, z } from 'astro:content'; + +export const haiku = defineCollection({ + schema: z.object({ + date: z.date(), + de: z.string(), + en: z.string(), + }), +}); diff --git a/src/schema/index.ts b/src/schema/index.ts new file mode 100644 index 0000000..0e427df --- /dev/null +++ b/src/schema/index.ts @@ -0,0 +1,4 @@ +export * from './ai-art'; +export * from './haiku'; +export * from './projects'; +export * from './sketchnotes'; diff --git a/src/schema/projects.ts b/src/schema/projects.ts new file mode 100644 index 0000000..678ded1 --- /dev/null +++ b/src/schema/projects.ts @@ -0,0 +1,42 @@ +import { defineCollection, z } from 'astro:content'; + +export const projects = defineCollection({ + schema: z.object({ + title: z.string(), + format: z.enum(['100-end', '100-start', '50-end', '50-start', '70-end', '70-start']), + image: z + .object({ + src: z.string(), + height: z.number().optional(), + width: z.number().optional(), + aspectRatio: z.number().optional(), + }) + .optional(), + sort: z.number().optional(), + showcase: z.boolean().optional(), + description: z.string().optional(), + intro: z.string().optional(), + categories: z.array( + z.enum([ + 'Design', + 'Graphic Design', + 'Icon Design', + 'Illustration', + 'Painting', + 'Photography', + 'Poetry', + 'Typeface Design', + 'Web Design', + 'Web Development', + 'Writing', + ]) + ), + more: z + .object({ + text: z.string().optional(), + link: z.string(), + }) + .optional(), + class: z.string().optional(), + }), +}); diff --git a/src/schema/sketchnotes.ts b/src/schema/sketchnotes.ts new file mode 100644 index 0000000..5fcc86e --- /dev/null +++ b/src/schema/sketchnotes.ts @@ -0,0 +1,15 @@ +import { defineCollection, z } from 'astro:content'; + +export const sketchnotes = defineCollection({ + schema: z.object({ + title: z.string(), + sort: z.number().optional(), + coverSize: z.enum(['small', 'medium', 'large']).default('small'), + images: z.array( + z.object({ + src: z.string(), + aspectRatio: z.number(), + }) + ), + }), +});