@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,122 @@
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
+
8
+ import _ from 'lodash';
9
+ import combinePromises from 'combine-promises';
10
+ import {DefaultSidebarItemsGenerator} from './generator';
11
+ import {validateSidebars} from './validation';
12
+ import {isCategoryIndex} from '../docs';
13
+ import type {
14
+ DocMetadataBase,
15
+ VersionMetadata,
16
+ } from '@docusaurus/plugin-content-docs';
17
+ import type {
18
+ NormalizedSidebarItem,
19
+ NormalizedSidebar,
20
+ NormalizedSidebars,
21
+ SidebarItemsGeneratorDoc,
22
+ SidebarItemsGeneratorVersion,
23
+ SidebarItemAutogenerated,
24
+ ProcessedSidebarItem,
25
+ ProcessedSidebar,
26
+ ProcessedSidebars,
27
+ SidebarProcessorParams,
28
+ CategoryMetadataFile,
29
+ } from './types';
30
+
31
+ function toSidebarItemsGeneratorDoc(
32
+ doc: DocMetadataBase,
33
+ ): SidebarItemsGeneratorDoc {
34
+ return _.pick(doc, [
35
+ 'id',
36
+ 'title',
37
+ 'frontMatter',
38
+ 'source',
39
+ 'sourceDirName',
40
+ 'sidebarPosition',
41
+ ]);
42
+ }
43
+
44
+ function toSidebarItemsGeneratorVersion(
45
+ version: VersionMetadata,
46
+ ): SidebarItemsGeneratorVersion {
47
+ return _.pick(version, ['versionName', 'contentPath']);
48
+ }
49
+
50
+ // Handle the generation of autogenerated sidebar items and other
51
+ // post-processing checks
52
+ async function processSidebar(
53
+ unprocessedSidebar: NormalizedSidebar,
54
+ categoriesMetadata: {[filePath: string]: CategoryMetadataFile},
55
+ params: SidebarProcessorParams,
56
+ ): Promise<ProcessedSidebar> {
57
+ const {sidebarItemsGenerator, numberPrefixParser, docs, version} = params;
58
+
59
+ // Just a minor lazy transformation optimization
60
+ const getSidebarItemsGeneratorDocsAndVersion = _.memoize(() => ({
61
+ docs: docs.map(toSidebarItemsGeneratorDoc),
62
+ version: toSidebarItemsGeneratorVersion(version),
63
+ }));
64
+
65
+ async function processAutoGeneratedItem(
66
+ item: SidebarItemAutogenerated,
67
+ ): Promise<ProcessedSidebarItem[]> {
68
+ const generatedItems = await sidebarItemsGenerator({
69
+ item,
70
+ numberPrefixParser,
71
+ defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
72
+ isCategoryIndex,
73
+ ...getSidebarItemsGeneratorDocsAndVersion(),
74
+ categoriesMetadata,
75
+ });
76
+ // Process again... weird but sidebar item generated might generate some
77
+ // auto-generated items?
78
+ // TODO repeatedly process & unwrap autogenerated items until there are no
79
+ // more autogenerated items, or when loop count (e.g. 10) is reached
80
+ return processItems(generatedItems);
81
+ }
82
+
83
+ async function processItem(
84
+ item: NormalizedSidebarItem,
85
+ ): Promise<ProcessedSidebarItem[]> {
86
+ if (item.type === 'category') {
87
+ return [
88
+ {
89
+ ...item,
90
+ items: (await Promise.all(item.items.map(processItem))).flat(),
91
+ },
92
+ ];
93
+ }
94
+ if (item.type === 'autogenerated') {
95
+ return processAutoGeneratedItem(item);
96
+ }
97
+ return [item];
98
+ }
99
+
100
+ async function processItems(
101
+ items: NormalizedSidebarItem[],
102
+ ): Promise<ProcessedSidebarItem[]> {
103
+ return (await Promise.all(items.map(processItem))).flat();
104
+ }
105
+
106
+ const processedSidebar = await processItems(unprocessedSidebar);
107
+ return processedSidebar;
108
+ }
109
+
110
+ export async function processSidebars(
111
+ unprocessedSidebars: NormalizedSidebars,
112
+ categoriesMetadata: {[filePath: string]: CategoryMetadataFile},
113
+ params: SidebarProcessorParams,
114
+ ): Promise<ProcessedSidebars> {
115
+ const processedSidebars = await combinePromises(
116
+ _.mapValues(unprocessedSidebars, (unprocessedSidebar) =>
117
+ processSidebar(unprocessedSidebar, categoriesMetadata, params),
118
+ ),
119
+ );
120
+ validateSidebars(processedSidebars);
121
+ return processedSidebars;
122
+ }
@@ -0,0 +1,293 @@
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
+
8
+ import type {Optional, Required} from 'utility-types';
9
+ import type {
10
+ NumberPrefixParser,
11
+ SidebarOptions,
12
+ CategoryIndexMatcher,
13
+ DocMetadataBase,
14
+ VersionMetadata,
15
+ } from '@docusaurus/plugin-content-docs';
16
+ import type {Slugger} from '@docusaurus/utils';
17
+
18
+ // Makes all properties visible when hovering over the type
19
+ type Expand<T extends {[x: string]: unknown}> = {[P in keyof T]: T[P]};
20
+
21
+ export type SidebarItemBase = {
22
+ key?: string;
23
+ className?: string;
24
+ customProps?: {[key: string]: unknown};
25
+ };
26
+
27
+ export type SidebarItemDoc = SidebarItemBase & {
28
+ type: 'doc' | 'ref';
29
+ label?: string;
30
+ id: string;
31
+ /**
32
+ * This is an internal marker set during the sidebar normalization process.
33
+ * Docs with labels defined in the config need to be translated with JSON.
34
+ * Otherwise, it's preferable to translate the MDX doc title or front matter.
35
+ */
36
+ translatable?: true;
37
+ };
38
+
39
+ export type SidebarItemHtml = SidebarItemBase & {
40
+ type: 'html';
41
+ value: string;
42
+ defaultStyle?: boolean;
43
+ };
44
+
45
+ export type SidebarItemLink = SidebarItemBase & {
46
+ type: 'link';
47
+ href: string;
48
+ label: string;
49
+ autoAddBaseUrl?: boolean;
50
+ description?: string;
51
+ };
52
+
53
+ export type SidebarItemAutogenerated = SidebarItemBase & {
54
+ type: 'autogenerated';
55
+ dirName: string;
56
+ };
57
+
58
+ type SidebarItemCategoryBase = SidebarItemBase & {
59
+ type: 'category';
60
+ label: string;
61
+ collapsed: boolean;
62
+ collapsible: boolean;
63
+ description?: string;
64
+ };
65
+
66
+ export type SidebarItemCategoryLinkDoc = {type: 'doc'; id: string};
67
+
68
+ export type SidebarItemCategoryLinkGeneratedIndexConfig = {
69
+ type: 'generated-index';
70
+ slug?: string;
71
+ title?: string;
72
+ description?: string;
73
+ image?: string;
74
+ keywords?: string | readonly string[];
75
+ };
76
+ export type SidebarItemCategoryLinkGeneratedIndex = {
77
+ type: 'generated-index';
78
+ slug: string;
79
+ permalink: string;
80
+ title?: string;
81
+ description?: string;
82
+ image?: string;
83
+ keywords?: string | readonly string[];
84
+ };
85
+
86
+ export type SidebarItemCategoryLinkConfig =
87
+ | SidebarItemCategoryLinkDoc
88
+ | SidebarItemCategoryLinkGeneratedIndexConfig;
89
+
90
+ export type SidebarItemCategoryLink =
91
+ | SidebarItemCategoryLinkDoc
92
+ | SidebarItemCategoryLinkGeneratedIndex;
93
+
94
+ // The user-given configuration in sidebars.js, before normalization
95
+ export type SidebarItemCategoryConfig = Expand<
96
+ Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
97
+ items: SidebarCategoriesShorthand | SidebarItemConfig[];
98
+ link?: SidebarItemCategoryLinkConfig;
99
+ }
100
+ >;
101
+
102
+ export type SidebarCategoriesShorthand = {
103
+ [sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
104
+ };
105
+
106
+ export type SidebarItemConfig =
107
+ | Omit<SidebarItemDoc, 'translatable'>
108
+ | SidebarItemHtml
109
+ | SidebarItemLink
110
+ | SidebarItemAutogenerated
111
+ | SidebarItemCategoryConfig
112
+ | string
113
+ | SidebarCategoriesShorthand;
114
+
115
+ export type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
116
+ export type SidebarsConfig = {
117
+ [sidebarId: string]: SidebarConfig;
118
+ };
119
+
120
+ // Normalized but still has 'autogenerated', which will be handled in processing
121
+ export type NormalizedSidebarItemCategory = Expand<
122
+ Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
123
+ items: NormalizedSidebarItem[];
124
+ link?: SidebarItemCategoryLinkConfig;
125
+ }
126
+ >;
127
+
128
+ export type NormalizedSidebarItem =
129
+ | SidebarItemDoc
130
+ | SidebarItemHtml
131
+ | SidebarItemLink
132
+ | NormalizedSidebarItemCategory
133
+ | SidebarItemAutogenerated;
134
+
135
+ export type NormalizedSidebar = NormalizedSidebarItem[];
136
+ export type NormalizedSidebars = {
137
+ [sidebarId: string]: NormalizedSidebar;
138
+ };
139
+
140
+ export type ProcessedSidebarItemCategory = Expand<
141
+ Optional<SidebarItemCategoryBase, 'collapsed' | 'collapsible'> & {
142
+ items: ProcessedSidebarItem[];
143
+ link?: SidebarItemCategoryLinkConfig;
144
+ }
145
+ >;
146
+ export type ProcessedSidebarItem =
147
+ | SidebarItemDoc
148
+ | SidebarItemHtml
149
+ | SidebarItemLink
150
+ | ProcessedSidebarItemCategory;
151
+ export type ProcessedSidebar = ProcessedSidebarItem[];
152
+ export type ProcessedSidebars = {
153
+ [sidebarId: string]: ProcessedSidebar;
154
+ };
155
+
156
+ export type SidebarItemCategory = Expand<
157
+ SidebarItemCategoryBase & {
158
+ items: SidebarItem[];
159
+ link?: SidebarItemCategoryLink;
160
+ }
161
+ >;
162
+
163
+ export type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
164
+
165
+ export type SidebarItemCategoryWithGeneratedIndex =
166
+ SidebarItemCategoryWithLink & {link: SidebarItemCategoryLinkGeneratedIndex};
167
+
168
+ export type SidebarItem =
169
+ | SidebarItemDoc
170
+ | SidebarItemHtml
171
+ | SidebarItemLink
172
+ | SidebarItemCategory;
173
+
174
+ // A sidebar item that is part of the previous/next ordered navigation
175
+ export type SidebarNavigationItem =
176
+ | SidebarItemDoc
177
+ | SidebarItemCategoryWithLink;
178
+
179
+ export type Sidebar = SidebarItem[];
180
+ export type SidebarItemType = SidebarItem['type'];
181
+ export type Sidebars = {
182
+ [sidebarId: string]: Sidebar;
183
+ };
184
+
185
+ // Doc links have been resolved to URLs, ready to be passed to the theme
186
+ export type PropSidebarItemCategory = Expand<
187
+ SidebarItemCategoryBase & {
188
+ items: PropSidebarItem[];
189
+ href?: string;
190
+
191
+ // Weird name => it would have been more convenient to have link.unlisted
192
+ // Note it is the category link that is unlisted, not the category itself
193
+ // We want to prevent users from clicking on an unlisted category link
194
+ // We can't use "href: undefined" otherwise sidebar item is not highlighted
195
+ linkUnlisted?: boolean;
196
+ }
197
+ >;
198
+
199
+ export type PropSidebarItemLink = SidebarItemLink & {
200
+ docId?: string;
201
+ unlisted?: boolean;
202
+ };
203
+
204
+ export type PropSidebarItemHtml = SidebarItemHtml;
205
+
206
+ export type PropSidebarItem =
207
+ | PropSidebarItemLink
208
+ | PropSidebarItemCategory
209
+ | PropSidebarItemHtml;
210
+ export type PropSidebar = PropSidebarItem[];
211
+ export type PropSidebars = {
212
+ [sidebarId: string]: PropSidebar;
213
+ };
214
+
215
+ export type PropSidebarBreadcrumbsItem =
216
+ | PropSidebarItemLink
217
+ | PropSidebarItemCategory;
218
+
219
+ export type CategoryMetadataFile = {
220
+ key?: string;
221
+ label?: string;
222
+ position?: number;
223
+ description?: string;
224
+ collapsed?: boolean;
225
+ collapsible?: boolean;
226
+ className?: string;
227
+ link?: SidebarItemCategoryLinkConfig | null;
228
+ customProps?: {[key: string]: unknown};
229
+
230
+ // TODO should we allow "items" here? how would this work? would an
231
+ // "autogenerated" type be allowed?
232
+ // This mkdocs plugin do something like that: https://github.com/lukasgeiter/mkdocs-awesome-pages-plugin/
233
+ // cf comment: https://github.com/facebook/docusaurus/issues/3464#issuecomment-784765199
234
+ };
235
+
236
+ // Reduce API surface for options.sidebarItemsGenerator
237
+ // The user-provided generator fn should receive only a subset of metadata
238
+ // A change to any of these metadata can be considered as a breaking change
239
+ export type SidebarItemsGeneratorDoc = Pick<
240
+ DocMetadataBase,
241
+ | 'id'
242
+ | 'title'
243
+ | 'frontMatter'
244
+ | 'source'
245
+ | 'sourceDirName'
246
+ | 'sidebarPosition'
247
+ >;
248
+ export type SidebarItemsGeneratorVersion = Pick<
249
+ VersionMetadata,
250
+ 'versionName' | 'contentPath'
251
+ >;
252
+
253
+ export type SidebarItemsGeneratorArgs = {
254
+ /** The sidebar item with type "autogenerated" to be transformed. */
255
+ item: SidebarItemAutogenerated;
256
+ /** Useful metadata for the version this sidebar belongs to. */
257
+ version: SidebarItemsGeneratorVersion;
258
+ /** All the docs of that version (unfiltered). */
259
+ docs: SidebarItemsGeneratorDoc[];
260
+ /** Number prefix parser configured for this plugin. */
261
+ numberPrefixParser: NumberPrefixParser;
262
+ /** The default category index matcher which you can override. */
263
+ isCategoryIndex: CategoryIndexMatcher;
264
+ /**
265
+ * Key is the path relative to the doc content directory, value is the
266
+ * category metadata file's content.
267
+ */
268
+ categoriesMetadata: {[filePath: string]: CategoryMetadataFile};
269
+ };
270
+ export type SidebarItemsGenerator = (
271
+ generatorArgs: SidebarItemsGeneratorArgs,
272
+ ) => NormalizedSidebar | Promise<NormalizedSidebar>;
273
+
274
+ export type SidebarItemsGeneratorOption = (
275
+ generatorArgs: {
276
+ /**
277
+ * Useful to re-use/enhance the default sidebar generation logic from
278
+ * Docusaurus.
279
+ * @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
280
+ */
281
+ defaultSidebarItemsGenerator: SidebarItemsGenerator;
282
+ } & SidebarItemsGeneratorArgs,
283
+ ) => NormalizedSidebar | Promise<NormalizedSidebar>;
284
+
285
+ export type SidebarProcessorParams = {
286
+ sidebarItemsGenerator: SidebarItemsGeneratorOption;
287
+ numberPrefixParser: NumberPrefixParser;
288
+ docs: DocMetadataBase[];
289
+ drafts: DocMetadataBase[];
290
+ version: VersionMetadata;
291
+ categoryLabelSlugger: Slugger;
292
+ sidebarOptions: SidebarOptions;
293
+ };