@azerion/bunosaurus-plugin-content-docs 0.0.0-stage → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +6 -2
  2. package/lib/categoryGeneratedIndex.d.ts +12 -0
  3. package/lib/categoryGeneratedIndex.js +36 -0
  4. package/lib/cli.d.ts +13 -0
  5. package/lib/cli.js +124 -0
  6. package/lib/client/doc.d.ts +29 -0
  7. package/lib/client/doc.js +47 -0
  8. package/lib/client/docSidebarItemsExpandedState.d.ts +30 -0
  9. package/lib/client/docSidebarItemsExpandedState.js +27 -0
  10. package/lib/client/docsClientUtils.d.ts +15 -0
  11. package/lib/client/docsClientUtils.js +86 -0
  12. package/lib/client/docsPreferredVersion.d.ts +29 -0
  13. package/lib/client/docsPreferredVersion.js +124 -0
  14. package/lib/client/docsSearch.d.ts +19 -0
  15. package/lib/client/docsSearch.js +39 -0
  16. package/lib/client/docsSidebar.d.ts +25 -0
  17. package/lib/client/docsSidebar.js +29 -0
  18. package/lib/client/docsUtils.d.ts +112 -0
  19. package/lib/client/docsUtils.js +299 -0
  20. package/lib/client/docsVersion.d.ts +19 -0
  21. package/lib/client/docsVersion.js +25 -0
  22. package/lib/client/index.d.ts +91 -0
  23. package/lib/client/index.js +83 -0
  24. package/lib/client/structuredDataUtils.d.ts +11 -0
  25. package/lib/client/structuredDataUtils.js +35 -0
  26. package/lib/constants.d.ts +14 -0
  27. package/lib/constants.js +17 -0
  28. package/lib/contentHelpers.d.ts +12 -0
  29. package/lib/contentHelpers.js +31 -0
  30. package/lib/docs.d.ts +48 -0
  31. package/lib/docs.js +252 -0
  32. package/lib/frontMatter.d.ts +10 -0
  33. package/lib/frontMatter.js +46 -0
  34. package/lib/globalData.d.ts +9 -0
  35. package/lib/globalData.js +59 -0
  36. package/lib/index.d.ts +10 -0
  37. package/lib/index.js +198 -0
  38. package/lib/numberPrefix.d.ts +11 -0
  39. package/lib/numberPrefix.js +50 -0
  40. package/lib/options.d.ts +10 -0
  41. package/lib/options.js +138 -0
  42. package/lib/props.d.ts +21 -0
  43. package/lib/props.js +156 -0
  44. package/lib/routes.d.ts +22 -0
  45. package/lib/routes.js +184 -0
  46. package/lib/server-export.d.ts +9 -0
  47. package/lib/server-export.js +25 -0
  48. package/lib/sidebars/generator.d.ts +10 -0
  49. package/lib/sidebars/generator.js +217 -0
  50. package/lib/sidebars/index.d.ts +13 -0
  51. package/lib/sidebars/index.js +99 -0
  52. package/lib/sidebars/normalization.d.ts +13 -0
  53. package/lib/sidebars/normalization.js +58 -0
  54. package/lib/sidebars/postProcessor.d.ts +11 -0
  55. package/lib/sidebars/postProcessor.js +82 -0
  56. package/lib/sidebars/processor.d.ts +10 -0
  57. package/lib/sidebars/processor.js +77 -0
  58. package/lib/sidebars/types.d.ts +192 -0
  59. package/lib/sidebars/types.js +8 -0
  60. package/lib/sidebars/utils.d.ts +69 -0
  61. package/lib/sidebars/utils.js +327 -0
  62. package/lib/sidebars/validation.d.ts +11 -0
  63. package/lib/sidebars/validation.js +152 -0
  64. package/lib/slug.d.ts +15 -0
  65. package/lib/slug.js +51 -0
  66. package/lib/translations.d.ts +10 -0
  67. package/lib/translations.js +243 -0
  68. package/lib/types.d.ts +27 -0
  69. package/lib/types.js +8 -0
  70. package/lib/versions/files.d.ts +54 -0
  71. package/lib/versions/files.js +152 -0
  72. package/lib/versions/loadVersion.d.ts +17 -0
  73. package/lib/versions/loadVersion.js +126 -0
  74. package/lib/versions/validation.d.ts +17 -0
  75. package/lib/versions/validation.js +70 -0
  76. package/lib/versions/version.d.ts +40 -0
  77. package/lib/versions/version.js +189 -0
  78. package/package.json +70 -4
  79. package/src/categoryGeneratedIndex.ts +60 -0
  80. package/src/cli.ts +180 -0
  81. package/src/client/doc.tsx +71 -0
  82. package/src/client/docSidebarItemsExpandedState.tsx +55 -0
  83. package/src/client/docsClientUtils.ts +140 -0
  84. package/src/client/docsPreferredVersion.tsx +245 -0
  85. package/src/client/docsSearch.test.ts +15 -0
  86. package/src/client/docsSearch.ts +57 -0
  87. package/src/client/docsSidebar.tsx +50 -0
  88. package/src/client/docsUtils.tsx +442 -0
  89. package/src/client/docsVersion.tsx +36 -0
  90. package/src/client/index.ts +211 -0
  91. package/src/client/structuredDataUtils.ts +54 -0
  92. package/src/constants.ts +15 -0
  93. package/src/contentHelpers.ts +34 -0
  94. package/src/docs.ts +402 -0
  95. package/src/frontMatter.ts +57 -0
  96. package/src/globalData.ts +79 -0
  97. package/src/index.ts +289 -0
  98. package/src/numberPrefix.ts +62 -0
  99. package/src/options.ts +185 -0
  100. package/src/plugin-content-docs.d.ts +667 -0
  101. package/src/props.ts +223 -0
  102. package/src/routes.ts +263 -0
  103. package/src/server-export.ts +26 -0
  104. package/src/sidebars/README.md +10 -0
  105. package/src/sidebars/generator.ts +307 -0
  106. package/src/sidebars/index.ts +130 -0
  107. package/src/sidebars/normalization.ts +91 -0
  108. package/src/sidebars/postProcessor.ts +115 -0
  109. package/src/sidebars/processor.ts +122 -0
  110. package/src/sidebars/types.ts +293 -0
  111. package/src/sidebars/utils.ts +529 -0
  112. package/src/sidebars/validation.ts +189 -0
  113. package/src/slug.ts +79 -0
  114. package/src/translations.ts +365 -0
  115. package/src/types.ts +34 -0
  116. package/src/versions/files.ts +240 -0
  117. package/src/versions/loadVersion.ts +185 -0
  118. package/src/versions/validation.ts +115 -0
  119. package/src/versions/version.ts +300 -0
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isCategoriesShorthand = isCategoriesShorthand;
10
+ exports.transformSidebarItems = transformSidebarItems;
11
+ exports.collectSidebarDocItems = collectSidebarDocItems;
12
+ exports.collectSidebarCategories = collectSidebarCategories;
13
+ exports.collectSidebarLinks = collectSidebarLinks;
14
+ exports.collectSidebarRefs = collectSidebarRefs;
15
+ exports.collectSidebarDocIds = collectSidebarDocIds;
16
+ exports.collectSidebarNavigation = collectSidebarNavigation;
17
+ exports.collectSidebarsDocIds = collectSidebarsDocIds;
18
+ exports.collectSidebarsNavigations = collectSidebarsNavigations;
19
+ exports.createSidebarsUtils = createSidebarsUtils;
20
+ exports.toDocNavigationLink = toDocNavigationLink;
21
+ exports.toNavigationLink = toNavigationLink;
22
+ const tslib_1 = require("tslib");
23
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
24
+ const utils_1 = require("@docusaurus/utils");
25
+ function isCategoriesShorthand(item) {
26
+ return typeof item === 'object' && !item.type;
27
+ }
28
+ function transformSidebarItems(sidebar, updateFn) {
29
+ function transformRecursive(item) {
30
+ if (item.type === 'category') {
31
+ return updateFn({
32
+ ...item,
33
+ items: item.items.map(transformRecursive),
34
+ });
35
+ }
36
+ return updateFn(item);
37
+ }
38
+ return sidebar.map(transformRecursive);
39
+ }
40
+ /**
41
+ * Flatten sidebar items into a single flat array (containing categories/docs on
42
+ * the same level). Order matters (useful for next/prev nav), top categories
43
+ * appear before their child elements
44
+ */
45
+ function flattenSidebarItems(items) {
46
+ function flattenRecursive(item) {
47
+ return item.type === 'category'
48
+ ? [item, ...item.items.flatMap(flattenRecursive)]
49
+ : [item];
50
+ }
51
+ return items.flatMap(flattenRecursive);
52
+ }
53
+ function collectSidebarItemsOfType(type, sidebar) {
54
+ return flattenSidebarItems(sidebar).filter((item) => item.type === type);
55
+ }
56
+ function collectSidebarDocItems(sidebar) {
57
+ return collectSidebarItemsOfType('doc', sidebar);
58
+ }
59
+ function collectSidebarCategories(sidebar) {
60
+ return collectSidebarItemsOfType('category', sidebar);
61
+ }
62
+ function collectSidebarLinks(sidebar) {
63
+ return collectSidebarItemsOfType('link', sidebar);
64
+ }
65
+ function collectSidebarRefs(sidebar) {
66
+ return collectSidebarItemsOfType('ref', sidebar);
67
+ }
68
+ // /!\ docId order matters for navigation!
69
+ function collectSidebarDocIds(sidebar) {
70
+ return flattenSidebarItems(sidebar).flatMap((item) => {
71
+ if (item.type === 'category') {
72
+ return item.link?.type === 'doc' ? [item.link.id] : [];
73
+ }
74
+ if (item.type === 'doc') {
75
+ return [item.id];
76
+ }
77
+ return [];
78
+ });
79
+ }
80
+ function collectSidebarNavigation(sidebar) {
81
+ return flattenSidebarItems(sidebar).flatMap((item) => {
82
+ if (item.type === 'category' && item.link) {
83
+ return [item];
84
+ }
85
+ if (item.type === 'doc') {
86
+ return [item];
87
+ }
88
+ return [];
89
+ });
90
+ }
91
+ function collectSidebarsDocIds(sidebars) {
92
+ return lodash_1.default.mapValues(sidebars, collectSidebarDocIds);
93
+ }
94
+ function collectSidebarsNavigations(sidebars) {
95
+ return lodash_1.default.mapValues(sidebars, collectSidebarNavigation);
96
+ }
97
+ function createSidebarsUtils(sidebars) {
98
+ const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
99
+ const sidebarNameToNavigationItems = collectSidebarsNavigations(sidebars);
100
+ // Reverse mapping
101
+ const docIdToSidebarName = Object.fromEntries(Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) => docIds.map((docId) => [docId, sidebarName])));
102
+ function getFirstDocIdOfFirstSidebar() {
103
+ return Object.values(sidebarNameToDocIds)[0]?.[0];
104
+ }
105
+ function getSidebarNameByDocId(docId) {
106
+ return docIdToSidebarName[docId];
107
+ }
108
+ function emptySidebarNavigation() {
109
+ return {
110
+ sidebarName: undefined,
111
+ previous: undefined,
112
+ next: undefined,
113
+ };
114
+ }
115
+ function getDocNavigation({ docId, displayedSidebar, unlistedIds, }) {
116
+ const sidebarName = displayedSidebar === undefined
117
+ ? getSidebarNameByDocId(docId)
118
+ : displayedSidebar;
119
+ if (!sidebarName) {
120
+ return emptySidebarNavigation();
121
+ }
122
+ let navigationItems = sidebarNameToNavigationItems[sidebarName];
123
+ if (!navigationItems) {
124
+ throw new Error(`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`);
125
+ }
126
+ // Filter unlisted items from navigation
127
+ navigationItems = navigationItems.filter((item) => {
128
+ if (item.type === 'doc' && unlistedIds.has(item.id)) {
129
+ return false;
130
+ }
131
+ if (item.type === 'category' &&
132
+ item.link.type === 'doc' &&
133
+ unlistedIds.has(item.link.id)) {
134
+ return false;
135
+ }
136
+ return true;
137
+ });
138
+ const currentItemIndex = navigationItems.findIndex((item) => {
139
+ if (item.type === 'doc') {
140
+ return item.id === docId;
141
+ }
142
+ if (item.type === 'category' && item.link.type === 'doc') {
143
+ return item.link.id === docId;
144
+ }
145
+ return false;
146
+ });
147
+ if (currentItemIndex === -1) {
148
+ return { sidebarName, next: undefined, previous: undefined };
149
+ }
150
+ return {
151
+ sidebarName,
152
+ previous: navigationItems[currentItemIndex - 1],
153
+ next: navigationItems[currentItemIndex + 1],
154
+ };
155
+ }
156
+ function getCategoryGeneratedIndexList() {
157
+ return Object.values(sidebarNameToNavigationItems)
158
+ .flat()
159
+ .flatMap((item) => {
160
+ if (item.type === 'category' && item.link.type === 'generated-index') {
161
+ return [item];
162
+ }
163
+ return [];
164
+ });
165
+ }
166
+ /**
167
+ * We identity the category generated index by its permalink (should be
168
+ * unique). More reliable than using object identity
169
+ */
170
+ function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
171
+ function isCurrentCategoryGeneratedIndexItem(item) {
172
+ return (item.type === 'category' &&
173
+ item.link.type === 'generated-index' &&
174
+ item.link.permalink === categoryGeneratedIndexPermalink);
175
+ }
176
+ const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
177
+ const navigationItems = sidebarNameToNavigationItems[sidebarName];
178
+ const currentItemIndex = navigationItems.findIndex(isCurrentCategoryGeneratedIndexItem);
179
+ return {
180
+ sidebarName,
181
+ previous: navigationItems[currentItemIndex - 1],
182
+ next: navigationItems[currentItemIndex + 1],
183
+ };
184
+ }
185
+ // TODO remove in Docusaurus v4
186
+ function getLegacyVersionedPrefix(versionMetadata) {
187
+ return `version-${versionMetadata.versionName}/`;
188
+ }
189
+ // In early v2, sidebar names used to be versioned
190
+ // example: "version-2.0.0-alpha.66/my-sidebar-name"
191
+ // In v3 it's not the case anymore and we throw an error to explain
192
+ // TODO remove in Docusaurus v4
193
+ function checkLegacyVersionedSidebarNames({ versionMetadata, sidebarFilePath, }) {
194
+ const illegalPrefix = getLegacyVersionedPrefix(versionMetadata);
195
+ const legacySidebarNames = Object.keys(sidebars).filter((sidebarName) => sidebarName.startsWith(illegalPrefix));
196
+ if (legacySidebarNames.length > 0) {
197
+ throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
198
+ These legacy versioned sidebar names are not supported anymore in Docusaurus v3:
199
+ - ${legacySidebarNames.sort().join('\n- ')}
200
+
201
+ The sidebar names you should now use are:
202
+ - ${legacySidebarNames
203
+ .sort()
204
+ .map((legacyName) => legacyName.split('/').splice(1).join('/'))
205
+ .join('\n- ')}
206
+
207
+ Please remove the "${illegalPrefix}" prefix from your versioned sidebar file.
208
+ This breaking change is documented on Docusaurus v3 release notes: https://docusaurus.io/blog/releases/3.0
209
+ `);
210
+ }
211
+ }
212
+ // throw a better error message for Docusaurus v3 breaking change
213
+ // TODO this can be removed in Docusaurus v4
214
+ function handleLegacyVersionedDocIds({ invalidDocIds, sidebarFilePath, versionMetadata, }) {
215
+ const illegalPrefix = getLegacyVersionedPrefix(versionMetadata);
216
+ // In older v2.0 alpha/betas, versioned docs had a legacy versioned prefix
217
+ // Example: "version-1.4/my-doc-id"
218
+ //
219
+ const legacyVersionedDocIds = invalidDocIds.filter((docId) => docId.startsWith(illegalPrefix));
220
+ if (legacyVersionedDocIds.length > 0) {
221
+ throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
222
+ These legacy versioned document ids are not supported anymore in Docusaurus v3:
223
+ - ${legacyVersionedDocIds.sort().join('\n- ')}
224
+
225
+ The document ids you should now use are:
226
+ - ${legacyVersionedDocIds
227
+ .sort()
228
+ .map((legacyId) => legacyId.split('/').splice(1).join('/'))
229
+ .join('\n- ')}
230
+
231
+ Please remove the "${illegalPrefix}" prefix from your versioned sidebar file.
232
+ This breaking change is documented on Docusaurus v3 release notes: https://docusaurus.io/blog/releases/3.0
233
+ `);
234
+ }
235
+ }
236
+ function checkSidebarsDocIds({ allDocIds, sidebarFilePath, versionMetadata, }) {
237
+ const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
238
+ const invalidDocIds = lodash_1.default.difference(allSidebarDocIds, allDocIds);
239
+ if (invalidDocIds.length > 0) {
240
+ handleLegacyVersionedDocIds({
241
+ invalidDocIds,
242
+ sidebarFilePath,
243
+ versionMetadata,
244
+ });
245
+ throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
246
+ These sidebar document ids do not exist:
247
+ - ${invalidDocIds.sort().join('\n- ')}
248
+
249
+ Available document ids are:
250
+ - ${lodash_1.default.uniq(allDocIds).sort().join('\n- ')}
251
+ `);
252
+ }
253
+ }
254
+ function getFirstLink(sidebar) {
255
+ for (const item of sidebar) {
256
+ if (item.type === 'doc') {
257
+ return {
258
+ type: 'doc',
259
+ id: item.id,
260
+ label: item.label ?? item.id,
261
+ };
262
+ }
263
+ else if (item.type === 'category') {
264
+ if (item.link?.type === 'doc') {
265
+ return {
266
+ type: 'doc',
267
+ id: item.link.id,
268
+ label: item.label,
269
+ };
270
+ }
271
+ else if (item.link?.type === 'generated-index') {
272
+ return {
273
+ type: 'generated-index',
274
+ permalink: item.link.permalink,
275
+ label: item.label,
276
+ };
277
+ }
278
+ const firstSubItem = getFirstLink(item.items);
279
+ if (firstSubItem) {
280
+ return firstSubItem;
281
+ }
282
+ }
283
+ }
284
+ return undefined;
285
+ }
286
+ return {
287
+ sidebars,
288
+ getFirstDocIdOfFirstSidebar,
289
+ getSidebarNameByDocId,
290
+ getDocNavigation,
291
+ getCategoryGeneratedIndexList,
292
+ getCategoryGeneratedIndexNavigation,
293
+ checkLegacyVersionedSidebarNames,
294
+ checkSidebarsDocIds,
295
+ getFirstLink: (id) => getFirstLink(sidebars[id]),
296
+ };
297
+ }
298
+ function toDocNavigationLink(doc, options) {
299
+ const { title, permalink, frontMatter: { pagination_label: paginationLabel, sidebar_label: sidebarLabel, }, } = doc;
300
+ return {
301
+ title: paginationLabel ?? sidebarLabel ?? options?.sidebarItemLabel ?? title,
302
+ permalink,
303
+ };
304
+ }
305
+ function toNavigationLink(navigationItem, docsById) {
306
+ function getDocById(docId) {
307
+ const doc = docsById[docId];
308
+ if (!doc) {
309
+ throw new Error(`Can't create navigation link: no doc found with id=${docId}`);
310
+ }
311
+ return doc;
312
+ }
313
+ if (!navigationItem) {
314
+ return undefined;
315
+ }
316
+ if (navigationItem.type === 'category') {
317
+ return navigationItem.link.type === 'doc'
318
+ ? toDocNavigationLink(getDocById(navigationItem.link.id))
319
+ : {
320
+ title: navigationItem.label,
321
+ permalink: navigationItem.link.permalink,
322
+ };
323
+ }
324
+ return toDocNavigationLink(getDocById(navigationItem.id), {
325
+ sidebarItemLabel: navigationItem?.label,
326
+ });
327
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { NormalizedSidebars, CategoryMetadataFile } from './types';
8
+ export declare function validateSidebars(sidebars: {
9
+ [sidebarId: string]: unknown;
10
+ }): asserts sidebars is NormalizedSidebars;
11
+ export declare function validateCategoryMetadataFile(unsafeContent: unknown): CategoryMetadataFile;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateSidebars = validateSidebars;
10
+ exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
11
+ const utils_validation_1 = require("@docusaurus/utils-validation");
12
+ // NOTE: we don't add any default values during validation on purpose!
13
+ // Config types are exposed to users for typechecking and we use the same type
14
+ // in normalization
15
+ const sidebarItemBaseSchema = utils_validation_1.Joi.object({
16
+ key: utils_validation_1.Joi.string(),
17
+ className: utils_validation_1.Joi.string(),
18
+ customProps: utils_validation_1.Joi.object().unknown(),
19
+ });
20
+ const sidebarItemAutogeneratedSchema = sidebarItemBaseSchema.append({
21
+ type: 'autogenerated',
22
+ dirName: utils_validation_1.Joi.string()
23
+ .required()
24
+ .pattern(/^[^/](?:.*[^/])?$/)
25
+ .message('"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash'),
26
+ });
27
+ const sidebarItemDocSchema = sidebarItemBaseSchema.append({
28
+ type: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
29
+ id: utils_validation_1.Joi.string().required(),
30
+ label: utils_validation_1.Joi.string(),
31
+ translatable: utils_validation_1.Joi.boolean(),
32
+ });
33
+ const sidebarItemHtmlSchema = sidebarItemBaseSchema.append({
34
+ type: 'html',
35
+ value: utils_validation_1.Joi.string().required(),
36
+ defaultStyle: utils_validation_1.Joi.boolean(),
37
+ });
38
+ const sidebarItemLinkSchema = sidebarItemBaseSchema.append({
39
+ type: 'link',
40
+ href: utils_validation_1.URISchema.required(),
41
+ autoAddBaseUrl: utils_validation_1.Joi.boolean(),
42
+ label: utils_validation_1.Joi.string()
43
+ .required()
44
+ .messages({ 'any.unknown': '"label" must be a string' }),
45
+ description: utils_validation_1.Joi.string().optional().messages({
46
+ 'any.unknown': '"description" must be a string',
47
+ }),
48
+ });
49
+ const sidebarItemCategoryLinkSchema = utils_validation_1.Joi.object()
50
+ .allow(null)
51
+ .when('.type', {
52
+ switch: [
53
+ {
54
+ is: 'doc',
55
+ then: utils_validation_1.Joi.object({
56
+ type: 'doc',
57
+ id: utils_validation_1.Joi.string().required(),
58
+ }),
59
+ },
60
+ {
61
+ is: 'generated-index',
62
+ then: utils_validation_1.Joi.object({
63
+ type: 'generated-index',
64
+ slug: utils_validation_1.Joi.string().optional(),
65
+ // This one is not in the user config, only in the normalized version
66
+ // permalink: Joi.string().optional(),
67
+ title: utils_validation_1.Joi.string().optional(),
68
+ description: utils_validation_1.Joi.string().optional(),
69
+ image: utils_validation_1.Joi.string().optional(),
70
+ keywords: [utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string())],
71
+ }),
72
+ },
73
+ {
74
+ is: utils_validation_1.Joi.required(),
75
+ then: utils_validation_1.Joi.forbidden().messages({
76
+ 'any.unknown': 'Unknown sidebar category link type "{.type}".',
77
+ }),
78
+ },
79
+ ],
80
+ });
81
+ const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
82
+ type: 'category',
83
+ label: utils_validation_1.Joi.string()
84
+ .required()
85
+ .messages({ 'any.unknown': '"label" must be a string' }),
86
+ items: utils_validation_1.Joi.array()
87
+ .required()
88
+ .messages({ 'any.unknown': '"items" must be an array' }),
89
+ // TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
90
+ // .items(Joi.link('#sidebarItemSchema')),
91
+ link: sidebarItemCategoryLinkSchema,
92
+ collapsed: utils_validation_1.Joi.boolean().messages({
93
+ 'any.unknown': '"collapsed" must be a boolean',
94
+ }),
95
+ collapsible: utils_validation_1.Joi.boolean().messages({
96
+ 'any.unknown': '"collapsible" must be a boolean',
97
+ }),
98
+ description: utils_validation_1.Joi.string().optional().messages({
99
+ 'any.unknown': '"description" must be a string',
100
+ }),
101
+ });
102
+ const sidebarItemSchema = utils_validation_1.Joi.object().when('.type', {
103
+ switch: [
104
+ { is: 'link', then: sidebarItemLinkSchema },
105
+ {
106
+ is: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
107
+ then: sidebarItemDocSchema,
108
+ },
109
+ { is: 'html', then: sidebarItemHtmlSchema },
110
+ { is: 'autogenerated', then: sidebarItemAutogeneratedSchema },
111
+ { is: 'category', then: sidebarItemCategorySchema },
112
+ {
113
+ is: utils_validation_1.Joi.any().required(),
114
+ then: utils_validation_1.Joi.forbidden().messages({
115
+ 'any.unknown': 'Unknown sidebar item type "{.type}".',
116
+ }),
117
+ },
118
+ ],
119
+ });
120
+ // .id('sidebarItemSchema');
121
+ function validateSidebarItem(item) {
122
+ // TODO: remove once with proper Joi support
123
+ // Because we can't use Joi to validate nested items (see above), we do it
124
+ // manually
125
+ utils_validation_1.Joi.assert(item, sidebarItemSchema);
126
+ if (item.type === 'category') {
127
+ item.items.forEach(validateSidebarItem);
128
+ }
129
+ }
130
+ function validateSidebars(sidebars) {
131
+ Object.values(sidebars).forEach((sidebar) => {
132
+ sidebar.forEach(validateSidebarItem);
133
+ });
134
+ }
135
+ const categoryMetadataFileSchema = utils_validation_1.Joi.object({
136
+ key: utils_validation_1.Joi.string(),
137
+ label: utils_validation_1.Joi.string(),
138
+ description: utils_validation_1.Joi.string(),
139
+ position: utils_validation_1.Joi.number(),
140
+ collapsed: utils_validation_1.Joi.boolean(),
141
+ collapsible: utils_validation_1.Joi.boolean(),
142
+ className: utils_validation_1.Joi.string(),
143
+ link: sidebarItemCategoryLinkSchema,
144
+ customProps: utils_validation_1.Joi.object().unknown(),
145
+ });
146
+ function validateCategoryMetadataFile(unsafeContent) {
147
+ const { error, value } = categoryMetadataFileSchema.validate(unsafeContent);
148
+ if (error) {
149
+ throw error;
150
+ }
151
+ return value;
152
+ }
package/lib/slug.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { NumberPrefixParser, DocMetadataBase } from '@docusaurus/plugin-content-docs';
8
+ export default function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
9
+ baseID: string;
10
+ frontMatterSlug?: string;
11
+ source: DocMetadataBase['source'];
12
+ sourceDirName: DocMetadataBase['sourceDirName'];
13
+ stripDirNumberPrefixes?: boolean;
14
+ numberPrefixParser?: NumberPrefixParser;
15
+ }): string;
package/lib/slug.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.default = getSlug;
10
+ const utils_1 = require("@docusaurus/utils");
11
+ const utils_common_1 = require("@docusaurus/utils-common");
12
+ const numberPrefix_1 = require("./numberPrefix");
13
+ const docs_1 = require("./docs");
14
+ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes = true, numberPrefixParser = numberPrefix_1.DefaultNumberPrefixParser, }) {
15
+ function getDirNameSlug() {
16
+ const dirNameStripped = stripDirNumberPrefixes
17
+ ? (0, numberPrefix_1.stripPathNumberPrefixes)(sourceDirName, numberPrefixParser)
18
+ : sourceDirName;
19
+ const resolveDirname = sourceDirName === '.'
20
+ ? '/'
21
+ : (0, utils_common_1.addLeadingSlash)((0, utils_common_1.addTrailingSlash)(dirNameStripped));
22
+ return resolveDirname;
23
+ }
24
+ function computeSlug() {
25
+ if (frontMatterSlug?.startsWith('/')) {
26
+ return frontMatterSlug;
27
+ }
28
+ const dirNameSlug = getDirNameSlug();
29
+ if (!frontMatterSlug &&
30
+ (0, docs_1.isCategoryIndex)((0, docs_1.toCategoryIndexMatcherParam)({ source, sourceDirName }))) {
31
+ return dirNameSlug;
32
+ }
33
+ const baseSlug = frontMatterSlug ?? baseID;
34
+ return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
35
+ }
36
+ function ensureValidSlug(slug) {
37
+ if (!(0, utils_1.isValidPathname)(slug)) {
38
+ throw new Error(`We couldn't compute a valid slug for document with ID "${baseID}" in "${sourceDirName}" directory.
39
+ The slug we computed looks invalid: ${slug}.
40
+ Maybe your slug front matter is incorrect or there are special characters in the file path?
41
+ By using front matter to set a custom slug, you should be able to fix this error:
42
+
43
+ ---
44
+ slug: /my/customDocPath
45
+ ---
46
+ `);
47
+ }
48
+ return slug;
49
+ }
50
+ return ensureValidSlug(computeSlug());
51
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { LoadedContent } from '@docusaurus/plugin-content-docs';
8
+ import type { TranslationFile } from '@docusaurus/types';
9
+ export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFile[];
10
+ export declare function translateLoadedContent(loadedContent: LoadedContent, translationFiles: TranslationFile[]): LoadedContent;