-
Notifications
You must be signed in to change notification settings - Fork 27
/
content-collections.ts
150 lines (139 loc) · 3.45 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { authors } from "@/utils/authors";
import { defineCollection, defineConfig } from "@content-collections/core";
import { compileMDX } from "@content-collections/mdx";
import rehypeToc from "@jsdevtools/rehype-toc";
// import { transformerCopyButton } from "@rehype-pretty/transformers";
import rt, { ReadTimeResults } from "reading-time";
import rehypePrettyCode from "rehype-pretty-code";
import rehypeSlug from "rehype-slug";
import remarkGfm from "remark-gfm";
export const customers = defineCollection({
name: "Customer",
directory: "./data/customer",
include: "*.mdx",
schema: (z) => ({
company_name: z.string(),
company_url: z.string(),
company_logo: z.string(),
user_name: z.string(),
user_title: z.string(),
user_photo: z.string(),
highlight: z.string(),
cover_image: z.string(),
draft: z.boolean().optional(),
order: z.number().optional(),
}),
transform: async (doc, ctx) => {
const mdx = await compileMDX(ctx, doc);
const slug = doc._meta.path;
return {
...doc,
mdx,
slug,
};
},
});
export const jobs = defineCollection({
name: "Job",
directory: "./data/job",
include: "*.mdx",
schema: (z) => ({
title: z.string(),
summary: z.string(),
experience: z.string(),
how: z.string(),
location: z.string(),
skills: z.array(z.string()),
draft: z.boolean().optional(),
}),
transform: async (doc, ctx) => {
const mdx = await compileMDX(ctx, doc);
const slug = doc._meta.path;
return {
...doc,
mdx,
slug,
};
},
});
export const glossary = defineCollection({
name: "Glossary",
directory: "./data/glossary",
include: "*.mdx",
schema: (z) => ({
title: z.string(),
summary: z.string(),
relations: z.array(z.string()).optional(),
draft: z.boolean().optional(),
}),
transform: async (doc, ctx) => {
const mdx = await compileMDX(ctx, doc);
const slug = doc._meta.path;
return {
...doc,
mdx,
slug,
};
},
});
export const posts = defineCollection({
name: "Post",
directory: "./data/blog",
include: "*.mdx",
schema: (z) => ({
slug: z.string(),
title: z.string(),
description: z.string().optional(),
authors: z.array(z.string()),
tags: z.array(z.string()),
image: z.string().optional(),
tweet: z.string().optional(),
draft: z.boolean().optional(),
}),
transform: async (doc, ctx) => {
const mdx = await compileMDX(ctx, doc, {
remarkPlugins: [remarkGfm],
rehypePlugins: [
rehypeSlug,
[
rehypeToc,
{
headings: ["h2", "h3"],
},
],
[
rehypePrettyCode,
{
theme: "poimandres",
// transformers: [
// transformerCopyButton({
// visibility: "always",
// feedbackDuration: 3_000,
// }),
// ],
},
],
],
});
const authorsData = doc.authors.map((username) => {
const author = authors[username];
return {
username,
...author,
image: `/authors/${author.image}`,
};
});
const readingTime = rt(doc.content) as ReadTimeResults;
const date = doc._meta.fileName.substring(-1, 10);
return {
...doc,
mdx,
date,
readingTime: readingTime.text,
authorsData,
};
},
});
export default defineConfig({
collections: [customers, jobs, glossary, posts],
});