27 lines
892 B
TypeScript
27 lines
892 B
TypeScript
import { defineCollection } from 'astro:content';
|
|
import { z } from 'astro/zod';
|
|
import { glob } from 'astro/loaders';
|
|
import examples from './data/examples.json';
|
|
|
|
const destination = z.string().refine(
|
|
(value) => !value || /^(\/(?!\/)|https?:\/\/|mailto:|#)/.test(value),
|
|
'Use a site path, https:// URL, mailto: address, or fragment.',
|
|
);
|
|
const pages = defineCollection({
|
|
// Only these four files can become public content pages.
|
|
loader: glob({
|
|
pattern: `{${examples.map(({ slug }) => slug).join(',')}}.md`,
|
|
base: './src/content/pages',
|
|
}),
|
|
schema: z.object({
|
|
title: z.string().min(1),
|
|
introduction: z.string().optional(),
|
|
image: z.string().optional(),
|
|
imageAlt: z.string().optional(),
|
|
imageCaption: z.string().optional(),
|
|
buttonLabel: z.string().optional(),
|
|
buttonUrl: destination.optional(),
|
|
}),
|
|
});
|
|
export const collections = { pages };
|