@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
package/src/index.ts ADDED
@@ -0,0 +1,289 @@
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 path from 'node:path';
9
+ import {
10
+ normalizeUrl,
11
+ docuHash,
12
+ aliasedSitePath,
13
+ getContentPathList,
14
+ posixPath,
15
+ addTrailingPathSeparator,
16
+ resolveMarkdownLinkPathname,
17
+ DEFAULT_PLUGIN_ID,
18
+ } from '@docusaurus/utils';
19
+ import {createAbsoluteFilePathMatcher} from '@docusaurus/glob';
20
+ import {getTagsFilePathsToWatch} from '@docusaurus/utils-validation';
21
+ import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
22
+ import {fs} from '@docusaurus/fs';
23
+ import {resolveSidebarPathOption} from './sidebars';
24
+ import {CategoryMetadataFilenamePattern} from './sidebars/generator';
25
+ import {type DocEnv} from './docs';
26
+ import {
27
+ getVersionFromSourceFilePath,
28
+ readVersionsMetadata,
29
+ toFullVersion,
30
+ } from './versions/version';
31
+ import cliDocs from './cli';
32
+ import {VERSIONS_JSON_FILE} from './constants';
33
+ import {toGlobalDataVersion} from './globalData';
34
+ import {
35
+ translateLoadedContent,
36
+ getLoadedContentTranslationFiles,
37
+ } from './translations';
38
+ import {createAllRoutes} from './routes';
39
+
40
+ import {createContentHelpers} from './contentHelpers';
41
+ import {loadVersion} from './versions/loadVersion';
42
+ import type {
43
+ PluginOptions,
44
+ VersionMetadata,
45
+ DocFrontMatter,
46
+ LoadedContent,
47
+ } from '@docusaurus/plugin-content-docs';
48
+ import type {LoadContext, Plugin} from '@docusaurus/types';
49
+ import type {FullVersion} from './types';
50
+ import type {RuleSetRule} from 'webpack';
51
+
52
+ // MDX loader is not 100% deterministic, leading to cache invalidation issue
53
+ // This permits to invalidate the MDX loader cache entries when content changes
54
+ // Problem documented here: https://github.com/facebook/docusaurus/pull/10934
55
+ // TODO this is not a perfect solution, find better?
56
+ async function createMdxLoaderDependencyFile({
57
+ dataDir,
58
+ options,
59
+ versionsMetadata,
60
+ }: {
61
+ dataDir: string;
62
+ options: PluginOptions;
63
+ versionsMetadata: VersionMetadata[];
64
+ }): Promise<string | undefined> {
65
+ // Disabled for unit tests, the side effect produces infinite watch loops
66
+ // TODO find a better way :/
67
+ if (process.env.NODE_ENV === 'test') {
68
+ return undefined;
69
+ }
70
+
71
+ const filePath = path.join(dataDir, '__mdx-loader-dependency.json');
72
+ // the cache is invalidated whenever this file content changes
73
+ const fileContent = {
74
+ options,
75
+ versionsMetadata,
76
+ };
77
+ await fs.mkdir(dataDir, {recursive: true});
78
+ await fs.writeFile(filePath, JSON.stringify(fileContent));
79
+ return filePath;
80
+ }
81
+
82
+ export default async function pluginContentDocs(
83
+ context: LoadContext,
84
+ options: PluginOptions,
85
+ ): Promise<Plugin<LoadedContent>> {
86
+ const {siteDir, generatedFilesDir, baseUrl, siteConfig} = context;
87
+ // Mutate options to resolve sidebar path according to siteDir
88
+ options.sidebarPath = resolveSidebarPathOption(siteDir, options.sidebarPath);
89
+
90
+ const versionsMetadata = await readVersionsMetadata({context, options});
91
+
92
+ const pluginId = options.id;
93
+
94
+ const pluginDataDirRoot = path.join(
95
+ generatedFilesDir,
96
+ 'docusaurus-plugin-content-docs',
97
+ );
98
+ const dataDir = path.join(pluginDataDirRoot, pluginId);
99
+ // TODO Docusaurus v4 breaking change
100
+ // module aliasing should be automatic
101
+ // we should never find local absolute FS paths in the codegen registry
102
+ const aliasedSource = (source: string) =>
103
+ `~docs/${posixPath(path.relative(pluginDataDirRoot, source))}`;
104
+
105
+ // TODO env should be injected into all plugins
106
+ const env = process.env.NODE_ENV as DocEnv;
107
+
108
+ const contentHelpers = createContentHelpers();
109
+
110
+ const mdxLoaderDependency = await createMdxLoaderDependencyFile({
111
+ dataDir,
112
+ options,
113
+ versionsMetadata,
114
+ });
115
+
116
+ function createDocsMDXLoaderRule(): RuleSetRule {
117
+ const {
118
+ rehypePlugins,
119
+ remarkPlugins,
120
+ recmaPlugins,
121
+ beforeDefaultRehypePlugins,
122
+ beforeDefaultRemarkPlugins,
123
+ } = options;
124
+ const contentDirs = versionsMetadata
125
+ .flatMap(getContentPathList)
126
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
127
+ .map(addTrailingPathSeparator);
128
+
129
+ return createMDXLoaderRule({
130
+ include: contentDirs,
131
+ options: {
132
+ dependencies: [mdxLoaderDependency].filter(
133
+ (d): d is string => typeof d === 'string',
134
+ ),
135
+ admonitions: options.admonitions,
136
+ remarkPlugins,
137
+ rehypePlugins,
138
+ recmaPlugins,
139
+ beforeDefaultRehypePlugins,
140
+ beforeDefaultRemarkPlugins,
141
+ staticDirs: siteConfig.staticDirectories.map((dir) =>
142
+ path.resolve(siteDir, dir),
143
+ ),
144
+ siteDir,
145
+ isMDXPartial: createAbsoluteFilePathMatcher(
146
+ options.exclude,
147
+ contentDirs,
148
+ ),
149
+ metadataPath: (mdxPath: string) => {
150
+ // Note that metadataPath must be the same/in-sync as
151
+ // the path from createData for each MDX.
152
+ const aliasedPath = aliasedSitePath(mdxPath, siteDir);
153
+ return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
154
+ },
155
+ // createAssets converts relative paths to require() calls
156
+ createAssets: ({frontMatter}: {frontMatter: DocFrontMatter}) => ({
157
+ image: frontMatter.image,
158
+ }),
159
+ markdownConfig: siteConfig.markdown,
160
+ resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
161
+ const version = getVersionFromSourceFilePath(
162
+ sourceFilePath,
163
+ versionsMetadata,
164
+ );
165
+ return resolveMarkdownLinkPathname(linkPathname, {
166
+ sourceFilePath,
167
+ sourceToPermalink: contentHelpers.sourceToPermalink,
168
+ siteDir,
169
+ contentPaths: version,
170
+ });
171
+ },
172
+ },
173
+ });
174
+ }
175
+
176
+ const docsMDXLoaderRule = createDocsMDXLoaderRule();
177
+
178
+ return {
179
+ name: 'docusaurus-plugin-content-docs',
180
+
181
+ extendCli(cli) {
182
+ const isDefaultPluginId = pluginId === DEFAULT_PLUGIN_ID;
183
+
184
+ // Need to create one distinct command per plugin instance
185
+ // otherwise 2 instances would try to execute the command!
186
+ const command = isDefaultPluginId
187
+ ? 'docs:version'
188
+ : `docs:version:${pluginId}`;
189
+ const commandDescription = isDefaultPluginId
190
+ ? 'Tag a new docs version'
191
+ : `Tag a new docs version (${pluginId})`;
192
+
193
+ cli
194
+ .command(command)
195
+ .arguments('<version>')
196
+ .description(commandDescription)
197
+ .action((version: unknown) =>
198
+ cliDocs.cliDocsVersionCommand(version, options, context),
199
+ );
200
+ },
201
+
202
+ getTranslationFiles({content}) {
203
+ return getLoadedContentTranslationFiles(content);
204
+ },
205
+
206
+ getPathsToWatch() {
207
+ function getVersionPathsToWatch(version: VersionMetadata): string[] {
208
+ const result = [
209
+ ...options.include.flatMap((pattern) =>
210
+ getContentPathList(version).map(
211
+ (docsDirPath) => `${docsDirPath}/${pattern}`,
212
+ ),
213
+ ),
214
+ ...getTagsFilePathsToWatch({
215
+ contentPaths: version,
216
+ tags: options.tags,
217
+ }),
218
+ `${version.contentPath}/**/${CategoryMetadataFilenamePattern}`,
219
+ ];
220
+ if (typeof version.sidebarFilePath === 'string') {
221
+ result.unshift(version.sidebarFilePath);
222
+ }
223
+ return result;
224
+ }
225
+
226
+ return versionsMetadata.flatMap(getVersionPathsToWatch);
227
+ },
228
+
229
+ async loadContent() {
230
+ return {
231
+ loadedVersions: await Promise.all(
232
+ versionsMetadata.map((versionMetadata) =>
233
+ loadVersion({
234
+ context,
235
+ options,
236
+ env,
237
+ versionMetadata,
238
+ }),
239
+ ),
240
+ ),
241
+ };
242
+ },
243
+
244
+ translateContent({content, translationFiles}) {
245
+ return translateLoadedContent(content, translationFiles);
246
+ },
247
+
248
+ async contentLoaded({content, actions}) {
249
+ contentHelpers.updateContent(content);
250
+
251
+ const versions: FullVersion[] = content.loadedVersions.map(toFullVersion);
252
+
253
+ await createAllRoutes({
254
+ baseUrl,
255
+ versions,
256
+ options,
257
+ actions,
258
+ aliasedSource,
259
+ });
260
+
261
+ actions.setGlobalData({
262
+ path: normalizeUrl([baseUrl, options.routeBasePath]),
263
+ versions: versions.map(toGlobalDataVersion),
264
+ breadcrumbs: options.breadcrumbs,
265
+ });
266
+ },
267
+
268
+ configureWebpack() {
269
+ return {
270
+ ignoreWarnings: [
271
+ // Suppress warnings about non-existing of versions file.
272
+ (e) =>
273
+ e.message.includes("Can't resolve") &&
274
+ e.message.includes(VERSIONS_JSON_FILE),
275
+ ],
276
+ resolve: {
277
+ alias: {
278
+ '~docs': pluginDataDirRoot,
279
+ },
280
+ },
281
+ module: {
282
+ rules: [docsMDXLoaderRule],
283
+ },
284
+ };
285
+ },
286
+ };
287
+ }
288
+
289
+ export {validateOptions} from './options';
@@ -0,0 +1,62 @@
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 {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
9
+
10
+ // Best-effort to avoid parsing some patterns as number prefix
11
+ // ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
12
+ // ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
13
+ // Both of them would look like 7.0-foo or 2021-11-foo
14
+ // note: we could try to parse float numbers in filenames, but that is probably
15
+ // not worth it, as a version such as "8.0" can be interpreted as either a
16
+ // version or a float. User can configure her own NumberPrefixParser if she
17
+ // wants 8.0 to be interpreted as a float
18
+ const ignoredPrefixPattern = /^\d+[-_.]\d+/;
19
+
20
+ const numberPrefixPattern =
21
+ /^(?<numberPrefix>\d+)\s*[-_.]+\s*(?<suffix>[^-_.\s].*)$/;
22
+
23
+ // 0-myDoc => {filename: myDoc, numberPrefix: 0}
24
+ // 003 - myDoc => {filename: myDoc, numberPrefix: 3}
25
+ export const DefaultNumberPrefixParser: NumberPrefixParser = (
26
+ filename: string,
27
+ ) => {
28
+ if (ignoredPrefixPattern.test(filename)) {
29
+ return {filename, numberPrefix: undefined};
30
+ }
31
+ const match = numberPrefixPattern.exec(filename);
32
+ if (!match) {
33
+ return {filename, numberPrefix: undefined};
34
+ }
35
+ return {
36
+ filename: match.groups!.suffix!,
37
+ numberPrefix: parseInt(match.groups!.numberPrefix!, 10),
38
+ };
39
+ };
40
+
41
+ export const DisabledNumberPrefixParser: NumberPrefixParser = (
42
+ filename: string,
43
+ ) => ({filename, numberPrefix: undefined});
44
+
45
+ // 0-myDoc => myDoc
46
+ export function stripNumberPrefix(
47
+ str: string,
48
+ parser: NumberPrefixParser,
49
+ ): string {
50
+ return parser(str).filename;
51
+ }
52
+
53
+ // 0-myFolder/0-mySubfolder/0-myDoc => myFolder/mySubfolder/myDoc
54
+ export function stripPathNumberPrefixes(
55
+ path: string,
56
+ parser: NumberPrefixParser,
57
+ ): string {
58
+ return path
59
+ .split('/')
60
+ .map((segment) => stripNumberPrefix(segment, parser))
61
+ .join('/');
62
+ }
package/src/options.ts ADDED
@@ -0,0 +1,185 @@
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 logger from '@docusaurus/logger';
9
+ import {
10
+ Joi,
11
+ RemarkPluginsSchema,
12
+ RehypePluginsSchema,
13
+ RecmaPluginsSchema,
14
+ AdmonitionsSchema,
15
+ RouteBasePathSchema,
16
+ URISchema,
17
+ } from '@docusaurus/utils-validation';
18
+ import {GlobExcludeDefault} from '@docusaurus/glob';
19
+ import {DefaultSidebarItemsGenerator} from './sidebars/generator';
20
+ import {
21
+ DefaultNumberPrefixParser,
22
+ DisabledNumberPrefixParser,
23
+ } from './numberPrefix';
24
+ import type {OptionValidationContext} from '@docusaurus/types';
25
+ import type {PluginOptions, Options} from '@docusaurus/plugin-content-docs';
26
+
27
+ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
28
+ path: 'docs', // Path to data on filesystem, relative to site dir.
29
+ routeBasePath: 'docs', // URL Route.
30
+ tagsBasePath: 'tags', // URL Tags Route.
31
+ include: ['**/*.{md,mdx}'], // Extensions to include.
32
+ exclude: GlobExcludeDefault,
33
+ sidebarItemsGenerator: DefaultSidebarItemsGenerator,
34
+ numberPrefixParser: DefaultNumberPrefixParser,
35
+ docsRootComponent: '@theme/DocsRoot',
36
+ docVersionRootComponent: '@theme/DocVersionRoot',
37
+ docRootComponent: '@theme/DocRoot',
38
+ docItemComponent: '@theme/DocItem',
39
+ docTagDocListComponent: '@theme/DocTagDocListPage',
40
+ docTagsListComponent: '@theme/DocTagsListPage',
41
+ docCategoryGeneratedIndexComponent: '@theme/DocCategoryGeneratedIndexPage',
42
+ remarkPlugins: [],
43
+ rehypePlugins: [],
44
+ recmaPlugins: [],
45
+ beforeDefaultRemarkPlugins: [],
46
+ beforeDefaultRehypePlugins: [],
47
+ showLastUpdateTime: false,
48
+ showLastUpdateAuthor: false,
49
+ admonitions: true,
50
+ includeCurrentVersion: true,
51
+ disableVersioning: false,
52
+ lastVersion: undefined,
53
+ versions: {},
54
+ editCurrentVersion: false,
55
+ editLocalizedFiles: false,
56
+ sidebarCollapsible: true,
57
+ sidebarCollapsed: true,
58
+ breadcrumbs: true,
59
+ onInlineTags: 'warn',
60
+ tags: undefined,
61
+ };
62
+
63
+ const VersionOptionsSchema = Joi.object({
64
+ path: Joi.string().allow('').optional(),
65
+ label: Joi.string().optional(),
66
+ banner: Joi.string().equal('none', 'unreleased', 'unmaintained').optional(),
67
+ badge: Joi.boolean().optional(),
68
+ className: Joi.string().optional(),
69
+ noIndex: Joi.boolean().optional(),
70
+ });
71
+
72
+ const VersionsOptionsSchema = Joi.object()
73
+ .pattern(Joi.string().required(), VersionOptionsSchema)
74
+ .default(DEFAULT_OPTIONS.versions);
75
+
76
+ const OptionsSchema = Joi.object<PluginOptions>({
77
+ path: Joi.string().default(DEFAULT_OPTIONS.path),
78
+ editUrl: Joi.alternatives().try(URISchema, Joi.function()),
79
+ editCurrentVersion: Joi.boolean().default(DEFAULT_OPTIONS.editCurrentVersion),
80
+ editLocalizedFiles: Joi.boolean().default(DEFAULT_OPTIONS.editLocalizedFiles),
81
+ routeBasePath: RouteBasePathSchema.default(DEFAULT_OPTIONS.routeBasePath),
82
+ tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
83
+ // @ts-expect-error: deprecated
84
+ homePageId: Joi.any().forbidden().messages({
85
+ 'any.unknown':
86
+ 'The docs plugin option homePageId is not supported anymore. To make a doc the "home", please add "slug: /" in its front matter. See: https://docusaurus.io/docs/next/docs-introduction#home-page-docs',
87
+ }),
88
+
89
+ include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
90
+ exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
91
+ sidebarPath: Joi.alternatives().try(
92
+ Joi.boolean().invalid(true),
93
+ Joi.string(),
94
+ ),
95
+ sidebarItemsGenerator: Joi.function().default(
96
+ () => DEFAULT_OPTIONS.sidebarItemsGenerator,
97
+ ),
98
+ sidebarCollapsible: Joi.boolean().default(DEFAULT_OPTIONS.sidebarCollapsible),
99
+ sidebarCollapsed: Joi.boolean().default(DEFAULT_OPTIONS.sidebarCollapsed),
100
+ numberPrefixParser: Joi.alternatives()
101
+ .try(
102
+ Joi.function(),
103
+ // Convert boolean values to functions
104
+ Joi.alternatives().conditional(Joi.boolean(), {
105
+ then: Joi.custom((val: boolean) =>
106
+ val ? DefaultNumberPrefixParser : DisabledNumberPrefixParser,
107
+ ),
108
+ }),
109
+ )
110
+ .default(() => DEFAULT_OPTIONS.numberPrefixParser),
111
+ docsRootComponent: Joi.string().default(DEFAULT_OPTIONS.docsRootComponent),
112
+ docVersionRootComponent: Joi.string().default(
113
+ DEFAULT_OPTIONS.docVersionRootComponent,
114
+ ),
115
+ docRootComponent: Joi.string().default(DEFAULT_OPTIONS.docRootComponent),
116
+ docItemComponent: Joi.string().default(DEFAULT_OPTIONS.docItemComponent),
117
+ docTagsListComponent: Joi.string().default(
118
+ DEFAULT_OPTIONS.docTagsListComponent,
119
+ ),
120
+ docTagDocListComponent: Joi.string().default(
121
+ DEFAULT_OPTIONS.docTagDocListComponent,
122
+ ),
123
+ docCategoryGeneratedIndexComponent: Joi.string().default(
124
+ DEFAULT_OPTIONS.docCategoryGeneratedIndexComponent,
125
+ ),
126
+ remarkPlugins: RemarkPluginsSchema.default(DEFAULT_OPTIONS.remarkPlugins),
127
+ rehypePlugins: RehypePluginsSchema.default(DEFAULT_OPTIONS.rehypePlugins),
128
+ recmaPlugins: RecmaPluginsSchema.default(DEFAULT_OPTIONS.recmaPlugins),
129
+ beforeDefaultRemarkPlugins: RemarkPluginsSchema.default(
130
+ DEFAULT_OPTIONS.beforeDefaultRemarkPlugins,
131
+ ),
132
+ beforeDefaultRehypePlugins: RehypePluginsSchema.default(
133
+ DEFAULT_OPTIONS.beforeDefaultRehypePlugins,
134
+ ),
135
+ admonitions: AdmonitionsSchema.default(DEFAULT_OPTIONS.admonitions),
136
+ showLastUpdateTime: Joi.bool().default(DEFAULT_OPTIONS.showLastUpdateTime),
137
+ showLastUpdateAuthor: Joi.bool().default(
138
+ DEFAULT_OPTIONS.showLastUpdateAuthor,
139
+ ),
140
+ includeCurrentVersion: Joi.bool().default(
141
+ DEFAULT_OPTIONS.includeCurrentVersion,
142
+ ),
143
+ onlyIncludeVersions: Joi.array().items(Joi.string().required()).optional(),
144
+ disableVersioning: Joi.bool().default(DEFAULT_OPTIONS.disableVersioning),
145
+ lastVersion: Joi.string().optional(),
146
+ versions: VersionsOptionsSchema,
147
+ breadcrumbs: Joi.bool().default(DEFAULT_OPTIONS.breadcrumbs),
148
+ onInlineTags: Joi.string()
149
+ .equal('ignore', 'log', 'warn', 'throw')
150
+ .default(DEFAULT_OPTIONS.onInlineTags),
151
+ tags: Joi.string()
152
+ .disallow('')
153
+ .allow(null, false)
154
+ .default(() => DEFAULT_OPTIONS.tags),
155
+ });
156
+
157
+ export function validateOptions({
158
+ validate,
159
+ options: userOptions,
160
+ }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
161
+ let options = userOptions;
162
+
163
+ if (options.sidebarCollapsible === false) {
164
+ // When sidebarCollapsible=false and sidebarCollapsed=undefined, we don't
165
+ // want to have the inconsistency warning. We let options.sidebarCollapsible
166
+ // become the default value for options.sidebarCollapsed
167
+ if (typeof options.sidebarCollapsed === 'undefined') {
168
+ options = {
169
+ ...options,
170
+ sidebarCollapsed: false,
171
+ };
172
+ }
173
+ if (options.sidebarCollapsed) {
174
+ logger.warn`The docs plugin config is inconsistent. It does not make sense to use code=${'sidebarCollapsible: false'} and code=${'sidebarCollapsed: true'} at the same time. code=${'sidebarCollapsed: true'} will be ignored.`;
175
+ options = {
176
+ ...options,
177
+ sidebarCollapsed: false,
178
+ };
179
+ }
180
+ }
181
+
182
+ const normalizedOptions = validate(OptionsSchema, options);
183
+
184
+ return normalizedOptions;
185
+ }