-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathfrontmatter.ts
More file actions
466 lines (451 loc) · 11.9 KB
/
frontmatter.ts
File metadata and controls
466 lines (451 loc) · 11.9 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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
// when updating to typescript,
// update links in content/contributing as well
import parse from '@/frame/lib/read-frontmatter'
import { allVersions } from '@/versions/lib/all-versions'
import { allTools } from '@/tools/lib/all-tools'
import { getDeepDataByLanguage } from '@/data-directory/lib/get-data'
interface SchemaProperty {
type?: string | string[]
translatable?: boolean
deprecated?: boolean
default?: any
minimum?: number
maximum?: number
enum?: any[]
errorMessage?: string
items?: any
properties?: Record<string, any>
required?: string[]
additionalProperties?: boolean
patternProperties?: Record<string, any>
format?: string
description?: string
minItems?: number
maxItems?: number
}
interface Schema {
type: string
required: string[]
additionalProperties: boolean
properties: Record<string, SchemaProperty>
}
const layoutNames = [
'default',
'graphql-explorer',
'product-landing',
'release-notes',
'inline',
'category-landing',
'bespoke-landing',
'discovery-landing',
'journey-landing',
false,
]
// Content type values derived from directory structure.
export const contentTypesEnum = [
'get-started',
'concepts',
'how-tos',
'reference',
'tutorials',
'homepage', // Only applies to the sole 'content/index.md' file (the homepage).
'landing', // Only applies to 'content/<product>/index.md' files (product landings).
'rai', // Only applies to files that live in directories with 'responsible-use' in the name.
'other', // Everything else.
]
// Values supported in the docsTeamMetrics frontmatter property. Used to track
// related articles (e.g. by feature or subject) that may span different directories.
export const docsTeamMetricsEnum = ['copilot-cli']
export const schema: Schema = {
type: 'object',
required: ['title', 'versions'],
additionalProperties: false,
properties: {
title: {
type: 'string',
translatable: true,
},
shortTitle: {
type: 'string',
translatable: true,
},
intro: {
type: 'string',
translatable: true,
},
product: {
type: 'string',
translatable: true,
},
permissions: {
type: 'string',
translatable: true,
},
// true by default on articles, false on all other content
showMiniToc: {
type: 'boolean',
},
// This frontmatter property is deprecated. Despite what `miniTocMaxHeadingLevel` says, the max level of mini TOC is *always* 2. See github/docs-engineering#2701.
miniTocMaxHeadingLevel: {
deprecated: true,
type: 'number',
default: 2,
minimum: 2,
maximum: 4,
},
subcategory: {
type: 'boolean',
},
// allow hidden articles under `early-access`
hidden: {
type: 'boolean',
},
// specify whether an Early Access article should not have a header notice
noEarlyAccessBanner: {
type: 'boolean',
},
// specify whether an Early Access product should have a table of contents
// (EA categories and subcategories have them by default, but products don't)
earlyAccessToc: {
type: 'boolean',
},
layout: {
type: ['string', 'boolean'],
enum: layoutNames,
errorMessage: 'must be the filename of an existing layout file, or `false` for no layout',
},
redirect_from: {
type: 'array',
},
allowTitleToDifferFromFilename: {
type: 'boolean',
},
introLinks: {
type: 'object',
},
authors: {
type: 'array',
items: {
type: 'string',
},
},
examples_source: {
type: 'string',
},
effectiveDate: {
type: 'string',
},
featuredLinks: {
type: 'object',
properties: {
gettingStarted: {
type: 'array',
items: { type: 'string' },
},
startHere: {
type: 'array',
items: { type: 'string' },
},
guideCards: {
type: 'array',
items: { type: 'string' },
},
popular: {
type: 'array',
items: { type: 'string' },
},
// allows you to use an alternate heading for the popular column
popularHeading: {
type: 'string',
translatable: true,
},
},
},
// Shown in `product-landing.html` "What's new" section
changelog: {
type: 'object',
properties: {
label: { type: 'string' },
prefix: { type: 'string' },
},
},
audience: {
type: 'array',
items: {
type: 'string',
enum: ['builder', 'driver'],
},
},
contentType: {
type: 'string',
enum: contentTypesEnum,
},
// Optional heading override for the single-track journey landing UI
journeyArticlesHeading: {
type: 'string',
translatable: true,
description: 'Override the default "Articles" heading on single-track journey landing pages',
},
// Journey tracks for journey landing pages
journeyTracks: {
type: 'array',
items: {
type: 'object',
required: ['id', 'title', 'guides'],
properties: {
id: {
type: 'string',
description: 'Unique identifier for the journey track',
},
title: {
type: 'string',
translatable: true,
description: 'Display title for the journey track',
},
description: {
type: 'string',
translatable: true,
description: 'Optional description for the journey track',
},
guides: {
type: 'array',
items: {
type: 'object',
required: ['href'],
properties: {
href: {
type: 'string',
description: 'Path to the article in the journey track',
},
alternativeNextStep: {
type: 'string',
description:
'Optional branching text for the article when guiding users through the journey',
},
},
additionalProperties: false,
},
description: 'Array of article paths that make up this journey track',
},
},
additionalProperties: false,
},
description: 'Array of journey tracks for journey landing pages',
},
// Used in `product-landing.html`
beta_product: {
type: 'boolean',
},
// Hero image for landing pages
heroImage: {
type: 'string',
},
interactive: {
type: 'boolean',
},
docsTeamMetrics: {
type: 'array',
items: {
type: 'string',
enum: docsTeamMetricsEnum,
},
},
communityRedirect: {
type: 'object',
properties: {
name: {
type: 'string',
},
href: {
type: 'string',
},
},
},
// Platform-specific content preference
defaultPlatform: {
type: 'string',
enum: ['mac', 'windows', 'linux'],
},
// Tool-specific content preference, the list of tools are kept in
// make it easier to update in a single place
defaultTool: {
type: 'string',
enum: Object.keys(allTools),
},
// Child groups specified on top-level TOC
childGroups: {
type: 'array',
},
// Child links specified on any TOC page
children: {
type: 'array',
},
// External products specified on the homepage
externalProducts: {
type: 'object',
required: ['electron'],
properties: {
electron: {
type: 'object',
required: ['id', 'name', 'href', 'external'],
properties: {
id: { type: 'string' },
name: { type: 'string' },
href: { type: 'string', format: 'url' },
external: { type: 'boolean' },
},
},
},
},
// whether or not the page is mirrored by an experimental page
hasExperimentalAlternative: {
type: 'boolean',
},
// Translation metadata properties added during the translation process,
// we don't use these properties ourselves.
'ms.openlocfilehash': {
type: 'string',
},
'ms.sourcegitcommit': {
type: 'string',
},
'ms.translationtype': {
type: 'string',
},
'ms.contentlocale': {
type: 'string',
},
'ms.lasthandoff': {
type: 'string',
},
'ms.locfileid': {
type: 'string',
},
autogenerated: {
type: 'string',
enum: [
'audit-logs',
'codeql-cli',
'github-apps',
'graphql',
'rest',
'secret-scanning',
'webhooks',
],
},
// START category-landing tags
category: {
type: 'array',
errorMessage: `must be an array, which is written in frontmatter like:
category:
- Category Name`,
},
complexity: {
type: 'array',
},
industry: {
type: 'array',
},
octicon: {
type: 'string',
},
// END category landing tags
// Custom sidebar link for category pages
sidebarLink: {
type: 'object',
required: ['text', 'href'],
properties: {
text: {
type: 'string',
translatable: true,
},
href: {
type: 'string',
},
},
},
// Spotlight configuration for category landing pages
spotlight: {
type: 'array',
items: {
type: 'object',
required: ['article', 'image'],
properties: {
article: {
type: 'string',
description: 'Path to the article to spotlight',
},
image: {
type: 'string',
description: 'Path to image for the spotlight card',
},
},
additionalProperties: false,
},
description: 'Array of articles to feature in the spotlight section',
},
// Carousels configuration for category landing pages (supports multiple carousels)
carousels: {
type: 'object',
description: 'Multiple named carousels with articles to feature',
patternProperties: {
'^[a-zA-Z_][a-zA-Z0-9_]*$': {
type: 'array',
minItems: 3,
maxItems: 9,
items: {
type: 'string',
},
},
},
},
// Included categories for article grid filtering
includedCategories: {
type: 'array',
items: {
type: 'string',
},
description: 'Array of category names to include in the article grid dropdown filter',
},
},
}
// returns a list of deprecated properties
export const deprecatedProperties = Object.keys(schema.properties).filter((prop: string) => {
return (schema.properties as Record<string, SchemaProperty>)[prop].deprecated
})
const featureVersionsProp = {
feature: {
type: ['string', 'array'],
enum: Object.keys(getDeepDataByLanguage('features', 'en')),
items: {
type: 'string',
},
errorMessage:
'must be the name (or names) of a feature that matches "filename" in data/features/_filename_.yml',
},
}
const semverRange = {
type: 'string',
format: 'semver',
// This is JSON pointer syntax with ajv so we can specify the bad version
// in the error message.
errorMessage: 'Must be a valid SemVer range: ${0}',
}
;(schema.properties as Record<string, any>).versions = {
type: ['object', 'string'], // allow a '*' string to indicate all versions
additionalProperties: false, // don't allow any versions in FM that aren't defined in lib/all-versions
properties: Object.values(allVersions).reduce((acc: any, versionObj) => {
acc[versionObj.plan] = semverRange
acc[versionObj.shortName] = semverRange
return acc
}, featureVersionsProp),
}
export function frontmatter(markdown: string, opts: any = {}) {
const defaults = {
schema,
}
return parse(markdown, Object.assign({}, defaults, opts))
}
// attach the schema object so it can be `require`d elsewhere.
frontmatter.schema = schema
export default frontmatter