-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent-collections.ts
43 lines (40 loc) · 1.23 KB
/
content-collections.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import remarkGfm from "remark-gfm";
import rehypeSlug from "rehype-slug";
import { codeImport } from "remark-code-import";
import { compileMDX } from "@content-collections/mdx";
import { defineCollection, defineConfig } from "@content-collections/core";
const docs = defineCollection({
name: "Docs",
directory: "src/content",
include: "**/*.mdx",
schema: (z) => ({
title: z.string(),
description: z.string(),
published: z.boolean().default(false),
date: z.string().optional(),
author: z
.object({
name: z.string().optional(),
twitter: z.string().optional()
})
.optional()
}),
transform: async (document, context) => {
const body = await compileMDX(context, document, {
remarkPlugins: [codeImport, remarkGfm],
rehypePlugins: [rehypeSlug]
});
return {
...document,
slug: `/${document._meta.path}`,
slugAsParams: document._meta.path.split("/").slice(1).join("/"),
body: {
raw: document.content,
code: body
}
};
}
});
export default defineConfig({
collections: [docs]
});