forked from lmsqueezy/wedges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentlayer.config.ts
118 lines (112 loc) · 3.32 KB
/
contentlayer.config.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
import {
defineDocumentType,
defineNestedType,
makeSource,
type ComputedFields,
} from "contentlayer/source-files";
import { fromHtmlIsomorphic } from "hast-util-from-html-isomorphic";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypePrettyCode, { type Options } from "rehype-pretty-code";
import rehypeSlug from "rehype-slug";
import remarkGfm from "remark-gfm";
import { addCode, postProcess, preProcess } from "./src/lib/rehype";
const computedFields: ComputedFields = {
slug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
slugAsParams: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
};
const LinkProperties = defineNestedType(() => ({
name: "LinkProperties",
fields: {
radix: {
type: "string",
},
source: {
type: "string",
},
sandbox: {
type: "string",
},
},
}));
const Doc = defineDocumentType(() => ({
name: "Doc",
filePathPattern: `**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
description: "The title of the article",
required: true,
},
description: {
type: "string",
description: "The description of the article",
required: false,
},
breadcrumbs: {
type: "list",
of: { type: "string" },
description: "The breadcrumbs of the article. An array of strings.",
required: false,
},
links: {
type: "nested",
of: LinkProperties,
description: "The links of the article. An array of strings.",
required: false,
},
toc: {
type: "boolean",
default: true,
required: false,
},
},
computedFields,
}));
const prettyCodeOptions: Options = {
defaultLang: {
block: "tsx",
},
grid: true,
};
export default makeSource({
contentDirPath: "src/content",
documentTypes: [Doc],
mdx: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
preProcess,
rehypeSlug,
[
rehypeAutolinkHeadings,
{
behavior: "append",
properties: {
className: [
"bg-surface outline-primary outline-offset-2 w-6 h-6 rounded-lg flex items-center justify-center",
],
},
headingProperties: {
"data-link": "",
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
content: fromHtmlIsomorphic(
'<svg fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M16.75 13.25L18 12C19.6569 10.3431 19.6569 7.65685 18 6V6C16.3431 4.34315 13.6569 4.34315 12 6L10.75 7.25"></path><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7.25 10.75L6 12C4.34315 13.6569 4.34315 16.3431 6 18V18C7.65685 19.6569 10.3431 19.6569 12 18L13.25 16.75"></path><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M14.25 9.75L9.75 14.25"></path</svg>',
{ fragment: true }
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
).children,
},
],
addCode,
// @ts-expect-error rehype-pretty-code types are wrong
[rehypePrettyCode, prettyCodeOptions],
postProcess,
],
},
});