-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathsource.config.ts
More file actions
211 lines (184 loc) · 6.8 KB
/
source.config.ts
File metadata and controls
211 lines (184 loc) · 6.8 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { defineDocs, defineConfig, frontmatterSchema } from "fumadocs-mdx/config";
import monokaiProLightRaw from "./lib/themes/monokai-pro-light.json";
// JSON imports widen fontStyle to `string` instead of the required literal union.
// Cast through unknown to satisfy Shiki's ThemeRegistrationAny at runtime.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const monokaiProLight = monokaiProLightRaw as unknown as any;
import remarkGfm from "remark-gfm";
import { remarkMdxMermaid } from "fumadocs-core/mdx-plugins";
import { mdxJsxToMarkdown } from "mdast-util-mdx-jsx";
import { z } from "zod";
// YAML parses unquoted dates (e.g. `date: 2023-07-19`) as JS Date objects.
// Use this helper so both string dates and Date objects are accepted and
// normalised to an ISO date string (YYYY-MM-DD).
const yamlDateField = z
.union([
z.string(),
z.date().transform((d) => d.toISOString().split("T")[0]),
])
.nullish();
// Base schema that adds canonical and noindex to the default frontmatter schema.
// All per-collection schemas should extend this so these fields are always parsed.
const baseFrontmatterSchema = frontmatterSchema.extend({
canonical: z.string().nullish(),
noindex: z.boolean().nullish(),
// Optional SEO title override: when set, used for <title> and OG title
// instead of the navigation title (keeps sidebar labels short).
seoTitle: z.string().nullish(),
// Optional per-page OG image override (site-relative path, e.g. /images/foo.jpg).
// When set, used instead of the generated /api/og card.
ogImage: z.string().nullish(),
});
// Extended schema for blog pages — adds date, tag, author, ogImage fields
// used by BlogIndex for thumbnails and filtering.
const blogFrontmatterSchema = baseFrontmatterSchema.extend({
date: yamlDateField,
tag: z.string().nullish(),
author: z.string().nullish(),
showInBlogIndex: z.boolean().nullish(),
highlight: z.boolean().nullish(),
});
// Extended schema for changelog pages — adds date, author, ogImage, ogVideo, badge
// that the Changelog widget and ChangelogHeader read from frontMatter.
const changelogFrontmatterSchema = baseFrontmatterSchema.extend({
date: yamlDateField,
author: z.string().nullish(),
ogVideo: z.string().nullish(),
gif: z.string().nullish(),
badge: z.string().nullish(),
});
// Extended schema for customer story pages — preserves all default fields and
// adds the custom frontmatter fields used by CustomerCarousel / CustomerIndex.
const customerFrontmatterSchema = baseFrontmatterSchema.extend({
// Use .nullish() so empty YAML values (parsed as null) are accepted too
date: yamlDateField,
tag: z.string().nullish(),
author: z.string().nullish(),
customerLogo: z.string().nullish(),
customerLogoDark: z.string().nullish(),
customerQuote: z.string().nullish(),
quoteAuthor: z.string().nullish(),
quoteRole: z.string().nullish(),
quoteCompany: z.string().nullish(),
quoteAuthorImage: z.string().nullish(),
showInCustomerIndex: z.boolean().nullish(),
});
// remarkPlugins is applied globally in defineConfig; per-collection mdxOptions
// are only needed for schema customization.
// Schema for collections whose sidebar labels can be overridden via frontmatter.
// shortTitle takes precedence; sidebarTitle is the legacy alias.
// Both are consumed by the shortTitleTransformer registered in lib/source.ts.
const sidebarFrontmatterSchema = baseFrontmatterSchema.extend({
shortTitle: z.string().nullish(),
sidebarTitle: z.string().nullish(),
});
export const docs = defineDocs({
dir: "content/docs",
docs: { schema: sidebarFrontmatterSchema },
});
const selfHostingFrontmatterSchema = sidebarFrontmatterSchema.extend({
label: z.string().nullish(),
});
export const selfHosting = defineDocs({
dir: "content/self-hosting",
docs: {
schema: selfHostingFrontmatterSchema,
},
});
export const blog = defineDocs({
dir: "content/blog",
docs: {
schema: blogFrontmatterSchema,
},
});
export const changelog = defineDocs({
dir: "content/changelog",
docs: {
schema: changelogFrontmatterSchema,
},
});
const guidesFrontmatterSchema = sidebarFrontmatterSchema.extend({
category: z.string().nullish(),
});
export const guides = defineDocs({
dir: "content/guides",
docs: {
schema: guidesFrontmatterSchema,
},
});
const faqFrontmatterSchema = sidebarFrontmatterSchema.extend({
tags: z.array(z.string()).optional(),
});
export const faq = defineDocs({
dir: "content/faq",
docs: {
schema: faqFrontmatterSchema,
},
});
const integrationsFrontmatterSchema = sidebarFrontmatterSchema.extend({
logo: z.string().nullish(),
});
export const integrations = defineDocs({
dir: "content/integrations",
docs: {
schema: integrationsFrontmatterSchema,
},
});
export const security = defineDocs({
dir: "content/security",
docs: { schema: sidebarFrontmatterSchema },
});
export const library = defineDocs({
dir: "content/library",
docs: { schema: sidebarFrontmatterSchema },
});
export const customers = defineDocs({
dir: "content/customers",
docs: {
schema: customerFrontmatterSchema,
},
});
export const handbook = defineDocs({
dir: "content/handbook",
docs: { schema: sidebarFrontmatterSchema },
});
const marketingFrontmatterSchema = baseFrontmatterSchema.extend({
contentWidth: z.enum(["docs", "full"]).nullish(),
});
export const academy = defineDocs({
dir: "content/academy",
docs: { schema: sidebarFrontmatterSchema },
});
export const marketing = defineDocs({
dir: "content/marketing",
docs: { schema: marketingFrontmatterSchema },
});
export default defineConfig({
mdxOptions: {
remarkPlugins: [remarkGfm, remarkMdxMermaid],
providerImportSource: "@/mdx-components",
// Disable remark-image: many content files reference remote images via https://
// and the plugin tries to fetch dimensions at compile time, causing build failures
remarkImageOptions: false,
// Teach remark-structure's mdast-util-to-markdown serializer how to handle
// MDX JSX nodes (mdxJsxFlowElement / mdxJsxTextElement). Without this, it
// throws "Cannot handle unknown node `mdxJsxFlowElement`" when pages contain
// JSX components like <Callout>, <Tabs>, etc.
remarkStructureOptions: {
// @ts-ignore — extensions is valid in mdast-util-to-markdown but the
// StructureOptions type doesn't expose it directly
stringify: { extensions: [mdxJsxToMarkdown()] },
},
// @ts-ignore — RehypeCodeOptions types themes as BundledTheme strings but
// Shiki's ThemeRegistrationAny (custom JSON object) is valid at runtime.
// fumadocs automatically sets defaultColor:false so --shiki-light / --shiki-dark
// CSS vars are generated and fumadocs-ui's CSS switches them per dark/light mode.
rehypeCodeOptions: {
lazy: false,
themes: {
light: monokaiProLight,
dark: "monokai",
},
},
},
});