forked from solana-foundation/developer-content
-
Notifications
You must be signed in to change notification settings - Fork 3
/
contentlayer.config.ts
380 lines (354 loc) · 8.94 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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import {
defineDocumentType,
makeSource,
FieldDefs,
} from "contentlayer/source-files";
/**
* Standard content record fields
*/
const basicContentFields: FieldDefs = {
id: {
type: "string",
description: "Manually defined unique id for this document",
required: false,
},
title: {
type: "string",
description: "The primary title of the post",
required: true,
},
description: {
type: "string",
description:
"Brief description of the content (also used in the SEO metadata)",
required: false,
},
tags: {
type: "list",
of: { type: "string" },
description: "List of filterable tags for content",
required: false,
},
keywords: {
type: "list",
of: { type: "string" },
description:
"List of keywords for the content, primarily used for seo metadata",
required: false,
},
date: {
type: "date",
description: "The date this content was published",
required: false,
},
updatedDate: {
type: "date",
description: "The date this content was last updated",
required: false,
},
difficulty: {
type: "enum",
description: "Difficulty level of the content",
options: ["Intro", "Beginner", "Intermediate", "Expert"],
},
image: {
type: "string",
description:
"The primary image of the content (also used in the SEO metadata)",
required: false,
},
/**
* URL, link, and route information
*/
isExternal: {
type: "boolean",
description: "Is this content just a link to external content?",
default: false,
},
href: {
type: "string",
description: "Page route or absolute URL for this document",
required: false,
},
canonical: {
type: "string",
description: "Canonical url of the content",
required: false,
},
altRoutes: {
type: "list",
of: { type: "string" },
description:
"List of alternate routes that should redirect to this same document",
required: false,
},
/**
* Assorted metadata flags used for display and formatting
*/
featured: {
type: "boolean",
description: "Whether or not this content is featured",
required: false,
},
featuredPriority: {
type: "number",
description: "Sort priority for featured content displays",
default: 999,
},
metaOnly: {
type: "boolean",
description: "Whether or not this record is used for only metadata",
required: false,
default: false,
},
/**
* Custom fields that are used for the generated `nav.json` sidebar data
*/
sidebarLabel: {
type: "string",
description: "Custom sidebar label to use, instead of the document's title",
required: false,
},
sidebarSortOrder: {
type: "number",
description: "Sort order of the doc, relative to its siblings",
required: false,
},
hideTableOfContents: {
type: "boolean",
description: "Force hide the table of contents displayed on page",
required: false,
},
/**
* Custom SEO specific details
*/
seoTitle: {
type: "string",
description: "Custom title to be used for SEO purposes",
required: false,
},
seoDescription: {
type: "string",
description:
"Custom description to be used for SEO purposes (recommended max of 155 characters)",
required: false,
},
};
/**
* Content record schema for Developer Resources
*/
export const DeveloperResource = defineDocumentType(() => ({
name: "DeveloperResource",
filePathPattern: `content/resources/**/*.md`,
fields: {
// use the standard content fields
...basicContentFields,
// define custom fields for this specific content...
repoUrl: {
type: "string",
description: "Repository URL for the developer resources",
required: false,
},
category: {
required: true,
type: "enum",
description: "General type of the resource (e.g. its broad category)",
options: ["documentation", "framework", "sdk"],
},
},
}));
/**
* Content record schema for Developer Guides
*/
export const DeveloperGuide = defineDocumentType(() => ({
name: "DeveloperGuide",
filePathPattern: `content/guides/**/*.md`,
fields: {
// use the standard content fields
...basicContentFields,
// define custom fields for this specific content...
// category: {
// type: "string",
// description: "",
// required: false,
// },
},
}));
/**
* Content record schema for Developer Workshops
*/
export const DeveloperWorkshop = defineDocumentType(() => ({
name: "DeveloperWorkshop",
filePathPattern: `content/workshops/*.md`,
fields: {
// use the standard content fields
...basicContentFields,
// define custom fields for this specific content...
repoUrl: {
type: "string",
description: "Repository URL for this developer workshop",
required: true,
},
objectives: {
type: "list",
of: { type: "string" },
description: "List of objectives for this workshop",
required: true,
},
duration: {
type: "string",
description: "Estimated duration of this workshop",
required: true,
},
video: {
type: "string",
description: "Video recording of the workshop (if Available)",
required: false,
},
presentation: {
type: "string",
description: "Presentation for this workshop (if Available)",
required: false,
},
/**
* Author specific details
*/
author: {
type: "string",
description: "The name of the original author of this content",
required: false,
},
authorDescription: {
type: "string",
description: "Brief description of the original author of this content",
required: false,
},
authorTwitterHandle: {
type: "string",
description: "Twitter handle of the original author of this content",
required: false,
},
authorGithubUsername: {
type: "string",
description: "GitHub username of the original author of this content",
required: false,
},
},
}));
/**
* Content record schema for the Course metadata file
*
* File: `courses/{course-name}/metadata.json`
*/
export const CourseMetadata = defineDocumentType(() => ({
name: "CourseMetadata",
filePathPattern: `content/courses/**/metadata.json`,
fields: {
// use the standard content fields
...basicContentFields,
// define custom fields for this specific content...
structure: {
type: "list",
of: { type: "json" },
description: "",
required: false,
},
lessons: {
type: "number",
description: "Number of lessons contained within this course",
},
},
}));
/**
* Content record schema a single Course Lesson
*/
export const CourseLesson = defineDocumentType(() => ({
name: "CourseLesson",
filePathPattern: `content/courses/**/content/*.md`,
fields: {
// use the standard content fields
...basicContentFields,
// define custom fields for this specific content...
objectives: {
type: "list",
of: { type: "string" },
description: "List of objectives for the Course Lesson",
required: false,
},
},
}));
/**
* Content record schema a single Solana documentation record
*/
export const SolanaDoc = defineDocumentType(() => ({
name: "SolanaDoc",
filePathPattern: "docs/**/*.md",
fields: {
// use the standard content fields
...basicContentFields,
/**
* Custom fields for this specific content record type
*/
// none
},
}));
/**
* Content record schema a single Solana RPC documentation record
*/
export const SolanaRPCDoc = defineDocumentType(() => ({
name: "SolanaRPCDoc",
filePathPattern: "docs/rpc/**/*.mdx",
fields: {
// use the standard content fields
...basicContentFields,
},
}));
/**
* Simple record type to enable ignoring files in the contentlayer checks
* Note: This should be used sparingly (and normally only for readme files)
*
* Auto ignored documents:
* - readme.md
* - README.md
*/
export const IgnoredDoc = defineDocumentType(() => ({
name: "IgnoredDoc",
filePathPattern: `**/+(README|readme).md`,
}));
/**
* Export the contentlayer settings
*/
export default makeSource({
// set the base content directories to search for content records
contentDirPath: ".",
contentDirInclude: [
"docs/rpc/**",
"docs/**",
"content/guides/**",
"content/courses/**",
"content/resources/**",
"content/workshops/**",
],
/**
* Listing of all supported content record types
*
* @dev when new content record types are added, ensure
* the `SimpleRecordGroupName` is updated accordingly
*/
documentTypes: [
IgnoredDoc,
// developer specific content
SolanaDoc,
SolanaRPCDoc,
DeveloperGuide,
DeveloperResource,
DeveloperWorkshop,
// course specific content record types
CourseMetadata,
CourseLesson,
],
// settings to force fail on bad data schema
onUnknownDocuments: "fail",
onMissingOrIncompatibleData: "fail",
onExtraFieldData: "fail",
});