27 lines
712 B
TypeScript
27 lines
712 B
TypeScript
import { z, defineCollection } from "astro:content";
|
||
|
||
const articles = defineCollection({
|
||
slug: ({ defaultSlug, data }) => {
|
||
// Use `permalink` from the entry’s frontmatter as the slug, if it exists.
|
||
// Otherwise, fall back to the default slug.
|
||
return data.slug || defaultSlug;
|
||
},
|
||
schema: {
|
||
title: z.string(),
|
||
subtitle: z.string(),
|
||
lang: z.enum(["fr", "en"]),
|
||
slug: z.string().optional(),
|
||
tags: z.array(z.string()), // An array of strings
|
||
// Parse pubDate as a browser-standard `Date` object
|
||
pubDate: z
|
||
.string()
|
||
.transform((str) => new Date(str))
|
||
.optional(),
|
||
},
|
||
});
|
||
|
||
export const collections = {
|
||
// Don't forget 'quotes' for collection names containing dashes
|
||
articles,
|
||
};
|