Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

frontmatter.js 4.6 KB

You have to be logged in to leave a comment. Sign In
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
  1. const parse = require('./read-frontmatter')
  2. const layoutNames = Object.keys(require('./layouts')).concat([false])
  3. const semverRange = {
  4. type: 'string',
  5. conform: require('semver').validRange,
  6. message: 'Must be a valid SemVer range'
  7. }
  8. const versionIds = Object.keys(require('./all-versions'))
  9. const guideTypes = ['overview', 'quick_start', 'tutorial', 'how_to', 'reference']
  10. const schema = {
  11. properties: {
  12. title: {
  13. type: 'string',
  14. required: true
  15. },
  16. shortTitle: {
  17. type: 'string'
  18. },
  19. intro: {
  20. type: 'string'
  21. },
  22. product: {
  23. type: 'string'
  24. },
  25. permissions: {
  26. type: 'string'
  27. },
  28. // true by default on articles, false on all other content
  29. showMiniToc: {
  30. type: 'boolean'
  31. },
  32. miniTocMaxHeadingLevel: {
  33. type: 'number',
  34. default: 3,
  35. minimum: 2,
  36. maximum: 4
  37. },
  38. mapTopic: {
  39. type: 'boolean'
  40. },
  41. // allow hidden articles under `early-access`
  42. hidden: {
  43. type: 'boolean'
  44. },
  45. layout: {
  46. type: ['string', 'boolean'],
  47. enum: layoutNames,
  48. message: 'must be the filename of an existing layout file, or `false` for no layout'
  49. },
  50. redirect_from: {
  51. type: ['array', 'string']
  52. },
  53. allowTitleToDifferFromFilename: {
  54. type: 'boolean'
  55. },
  56. introLinks: {
  57. type: 'object',
  58. properties: {
  59. quickstart: { type: 'string' },
  60. reference: { type: 'string' },
  61. overview: { type: 'string' }
  62. }
  63. },
  64. authors: {
  65. type: 'array',
  66. items: {
  67. type: 'string'
  68. }
  69. },
  70. featuredLinks: {
  71. type: 'object',
  72. additionalProperties: false,
  73. patternProperties: {
  74. '^[a-zA-Z-_]+$': {
  75. type: 'array',
  76. items: { type: 'string' }
  77. }
  78. }
  79. },
  80. // Shown in `product-landing.html` "What's new" section
  81. changelog: {
  82. type: 'object',
  83. properties: {
  84. label: { type: 'string' },
  85. prefix: { type: 'string' }
  86. }
  87. },
  88. type: {
  89. type: 'string',
  90. enum: guideTypes
  91. },
  92. topics: {
  93. type: 'array'
  94. },
  95. includeGuides: {
  96. type: 'array'
  97. },
  98. learningTracks: {
  99. type: 'array'
  100. },
  101. // Used in `product-landing.html`
  102. beta_product: {
  103. type: 'boolean'
  104. },
  105. // Show in `product-landing.html`
  106. product_video: {
  107. type: 'string'
  108. },
  109. interactive: {
  110. type: 'boolean'
  111. },
  112. // Platform-specific content preference
  113. defaultPlatform: {
  114. type: 'string',
  115. enum: ['mac', 'windows', 'linux']
  116. },
  117. // Documentation contributed by a third party, such as a GitHub Partner
  118. contributor: {
  119. type: 'object',
  120. properties: {
  121. name: { type: 'string' },
  122. URL: { type: 'string' }
  123. }
  124. },
  125. // Child links specified on any TOC page
  126. children: {
  127. type: 'array'
  128. },
  129. // External products specified on the homepage
  130. externalProducts: {
  131. type: 'object',
  132. properties: {
  133. cli: {
  134. type: 'object',
  135. required: true,
  136. properties: {
  137. id: { type: 'string', required: true },
  138. name: { type: 'string', required: true },
  139. href: { type: 'string', format: 'url', required: true },
  140. external: { type: 'boolean', required: true }
  141. }
  142. },
  143. atom: {
  144. type: 'object',
  145. required: true,
  146. properties: {
  147. id: { type: 'string', required: true },
  148. name: { type: 'string', required: true },
  149. href: { type: 'string', format: 'url', required: true },
  150. external: { type: 'boolean', required: true }
  151. }
  152. },
  153. electron: {
  154. type: 'object',
  155. required: true,
  156. properties: {
  157. id: { type: 'string', required: true },
  158. name: { type: 'string', required: true },
  159. href: { type: 'string', format: 'url', required: true },
  160. external: { type: 'boolean', required: true }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. schema.properties.versions = {
  168. type: ['object', 'string'], // allow a '*' string to indicate all versions
  169. required: true,
  170. properties: versionIds.reduce((acc, versionId) => {
  171. acc[versionId] = semverRange
  172. return acc
  173. }, {})
  174. }
  175. function frontmatter (markdown, opts = {}) {
  176. const defaults = {
  177. schema,
  178. validateKeyNames: true,
  179. validateKeyOrder: false // TODO: enable this once we've sorted all the keys. See issue 9658
  180. }
  181. return parse(markdown, Object.assign({}, defaults, opts))
  182. }
  183. // attach the schema object so it can be `require`d elsewhere.
  184. frontmatter.schema = schema
  185. module.exports = frontmatter
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...