-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcontent-collections.ts
60 lines (57 loc) · 1.7 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { defineCollection, defineConfig } from "@content-collections/core";
import { compileMDX } from "@content-collections/mdx";
import readingTime from "reading-time";
import autolinkHeadings from "./content/plugins/autolink-headings";
import prettyCode from "./content/plugins/rehype-pretty-code";
import slug from "rehype-slug";
const crafts = defineCollection({
name: "crafts",
directory: "content/crafts",
include: "*.mdx",
schema: (z) => ({
title: z.string(),
date: z.coerce.date(),
githubUrl: z.string().url(),
description: z.string(),
component: z.string(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
// @ts-expect-error
rehypePlugins: [slug, autolinkHeadings, prettyCode],
});
return {
...document,
slug: document._meta.fileName.replace(/\.mdx$/, ""),
url: `/post/${document._meta.fileName.replace(/\.mdx$/, "")}`,
readingTime: readingTime(document.content).text,
mdx,
};
},
});
const brews = defineCollection({
name: "brews",
directory: "content/brews",
include: "*.mdx",
schema: (z) => ({
title: z.string(),
date: z.coerce.date(),
description: z.string(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
// @ts-expect-error
rehypePlugins: [slug, autolinkHeadings, prettyCode],
});
return {
...document,
slug: document._meta.fileName.replace(/\.mdx$/, ""),
url: `/post/${document._meta.fileName.replace(/\.mdx$/, "")}`,
readingTime: readingTime(document.content).text,
mdx,
};
},
});
export default defineConfig({
collections: [crafts, brews],
});