-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent-collections.ts
114 lines (107 loc) · 2.66 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { slugify } from "@/lib/utils";
import { defineCollection, defineConfig } from "@content-collections/core";
import { compileMDX } from "@content-collections/mdx";
import {
createDocSchema,
createMetaSchema,
transformMDX,
} from "@fumadocs/content-collections/configuration";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import { rehypeParseCodeBlocks } from "./shiki-rehype.mjs";
const docs = defineCollection({
name: "docs",
directory: "content/docs",
include: "**/*.mdx",
schema: createDocSchema,
transform: transformMDX,
});
const metas = defineCollection({
name: "meta",
directory: "content/docs",
include: "**/meta.json",
parser: "json",
schema: createMetaSchema,
});
const posts = defineCollection({
name: "posts",
directory: "content/posts",
include: ["**/*.md", "**/*.mdx"],
schema: (z) => ({
title: z.string(),
description: z.string(),
image: z.string(),
author: z.string(),
authorAvatar: z.string(),
date: z.string(),
category: z.string(),
tags: z.array(z.string()),
seo: z.array(z.string()),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
rehypePlugins: [
rehypeParseCodeBlocks,
[
rehypeAutolinkHeadings,
{
properties: {
className: ["anchor"],
},
},
],
],
});
const regXHeader = /^(?:[\n\r]|)(?<flag>#{1,6})\s+(?<content>.+)/gm;
const headings = Array.from(document.content.matchAll(regXHeader)).map(
({ groups }) => {
const flag = groups?.flag;
const content = groups?.content;
return {
level: flag?.length,
text: content,
slug: slugify(content ?? "#"),
};
},
);
return {
...document,
headings,
mdx,
};
},
});
const projects = defineCollection({
name: "projects",
directory: "content/projects",
include: ["**/*.md", "**/*.mdx"],
schema: (z) => ({
order: z.number(),
title: z.string(),
category: z.enum([
"Android",
"Next.js",
"Web",
"Mobile",
"HTML, CSS, JS",
"Other",
] as const),
created_at: z.string(),
image: z.string(),
featured: z.boolean(),
webUrl: z.string().nullable(),
youtubeUrl: z.string().nullable(),
githubUrl: z.string().nullable(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
rehypePlugins: [rehypeParseCodeBlocks],
});
return {
...document,
mdx,
};
},
});
export default defineConfig({
collections: [posts, projects, docs, metas],
});