www/content-collections.ts

48 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

import { defineCollection, defineConfig } from "@content-collections/core";
import { compileMDX } from "@content-collections/mdx";
const authors = defineCollection({
name: "authors",
directory: "data/authors/",
include: "*.md",
schema: (z) => ({
name: z.string(),
displayName: z.string(),
active: z.boolean().default(true),
role: z.string(),
avatarUrl: z.string(),
bluesky: z.string().optional(),
x: z.string().optional(),
}),
});
const posts = defineCollection({
name: "posts",
directory: "data/posts/",
include: "**/*.mdx",
schema: (z) => ({
title: z.string(),
author: z.string().default("mimi"),
date: z.string(),
summary: z.string(),
image: z.string().optional(),
imageDesc: z.string().optional(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document);
const author = await context
.documents(authors)
.find((a) => a.name === document.author);
return {
...document,
author,
mdx,
urlPath: `blog/${document._meta.path}`,
imageURL: document.image !== undefined ? `https://cdn.xeiaso.net/file/christine-static/${document.image}.jpg` : undefined,
};
},
});
export default defineConfig({
collections: [authors, posts],
});