refactor: move schemas into individual files

This commit is contained in:
Stefan Imhoff
2023-05-27 16:00:57 +02:00
parent 34943b79b2
commit 36d09dcaa2
6 changed files with 90 additions and 82 deletions

View File

@@ -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,
};

15
src/schema/ai-art.ts Normal file
View File

@@ -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(),
})
),
}),
});

9
src/schema/haiku.ts Normal file
View File

@@ -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(),
}),
});

4
src/schema/index.ts Normal file
View File

@@ -0,0 +1,4 @@
export * from './ai-art';
export * from './haiku';
export * from './projects';
export * from './sketchnotes';

42
src/schema/projects.ts Normal file
View File

@@ -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(),
}),
});

15
src/schema/sketchnotes.ts Normal file
View File

@@ -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(),
})
),
}),
});