@docusaurus/plugin-content-docs 2.0.0-beta.16 → 2.0.0-beta.19
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.
- package/lib/categoryGeneratedIndex.d.ts +1 -1
- package/lib/categoryGeneratedIndex.js +5 -7
- package/lib/cli.d.ts +3 -2
- package/lib/cli.js +49 -41
- package/lib/client/docsClientUtils.d.ts +8 -5
- package/lib/client/docsClientUtils.js +13 -15
- package/lib/client/index.d.ts +12 -9
- package/lib/client/index.js +30 -33
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +8 -15
- package/lib/docs.js +34 -39
- package/lib/{docFrontMatter.d.ts → frontMatter.d.ts} +4 -2
- package/lib/{docFrontMatter.js → frontMatter.js} +3 -0
- package/lib/globalData.d.ts +3 -7
- package/lib/globalData.js +9 -13
- package/lib/index.d.ts +1 -2
- package/lib/index.js +33 -26
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +14 -5
- package/lib/markdown/index.js +1 -1
- package/lib/markdown/linkify.js +5 -2
- package/lib/numberPrefix.js +16 -22
- package/lib/options.d.ts +3 -5
- package/lib/options.js +6 -5
- package/lib/props.d.ts +3 -3
- package/lib/props.js +10 -10
- package/lib/routes.d.ts +5 -4
- package/lib/routes.js +10 -24
- package/lib/server-export.d.ts +2 -1
- package/lib/server-export.js +3 -4
- package/lib/sidebars/generator.js +63 -44
- package/lib/sidebars/index.js +20 -16
- package/lib/sidebars/normalization.js +3 -3
- package/lib/sidebars/postProcessor.js +18 -25
- package/lib/sidebars/processor.d.ts +3 -1
- package/lib/sidebars/processor.js +17 -6
- package/lib/sidebars/types.d.ts +31 -19
- package/lib/sidebars/utils.d.ts +17 -6
- package/lib/sidebars/utils.js +27 -37
- package/lib/sidebars/validation.d.ts +3 -1
- package/lib/sidebars/validation.js +1 -0
- package/lib/slug.d.ts +1 -2
- package/lib/slug.js +4 -5
- package/lib/tags.d.ts +2 -1
- package/lib/tags.js +2 -2
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +28 -81
- package/lib/types.d.ts +10 -95
- package/lib/versions/files.d.ts +44 -0
- package/lib/versions/files.js +142 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +155 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +14 -12
- package/src/categoryGeneratedIndex.ts +10 -9
- package/src/cli.ts +64 -69
- package/src/client/docsClientUtils.ts +14 -16
- package/src/client/index.ts +42 -43
- package/src/constants.ts +4 -2
- package/src/deps.d.ts +1 -1
- package/src/docs.ts +48 -51
- package/src/{docFrontMatter.ts → frontMatter.ts} +9 -6
- package/src/globalData.ts +15 -16
- package/src/index.ts +45 -40
- package/src/lastUpdate.ts +20 -8
- package/src/markdown/index.ts +1 -3
- package/src/markdown/linkify.ts +6 -3
- package/src/numberPrefix.ts +18 -28
- package/src/options.ts +6 -8
- package/src/plugin-content-docs.d.ts +457 -116
- package/src/props.ts +12 -9
- package/src/routes.ts +13 -39
- package/src/server-export.ts +1 -3
- package/src/sidebars/generator.ts +88 -59
- package/src/sidebars/index.ts +20 -15
- package/src/sidebars/normalization.ts +1 -1
- package/src/sidebars/postProcessor.ts +6 -11
- package/src/sidebars/processor.ts +27 -14
- package/src/sidebars/types.ts +25 -23
- package/src/sidebars/utils.ts +45 -46
- package/src/sidebars/validation.ts +4 -3
- package/src/slug.ts +7 -6
- package/src/tags.ts +3 -2
- package/src/translations.ts +32 -84
- package/src/types.ts +15 -107
- package/src/versions/files.ts +220 -0
- package/src/versions/index.ts +247 -0
- package/src/versions/validation.ts +113 -0
- package/lib/versions.d.ts +0 -41
- package/lib/versions.js +0 -329
- package/src/versions.ts +0 -606
package/src/versions.ts
DELETED
|
@@ -1,606 +0,0 @@
|
|
|
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 'path';
|
|
9
|
-
import fs from 'fs-extra';
|
|
10
|
-
import type {VersionMetadata} from './types';
|
|
11
|
-
import {
|
|
12
|
-
VERSIONS_JSON_FILE,
|
|
13
|
-
VERSIONED_DOCS_DIR,
|
|
14
|
-
VERSIONED_SIDEBARS_DIR,
|
|
15
|
-
CURRENT_VERSION_NAME,
|
|
16
|
-
} from './constants';
|
|
17
|
-
import type {
|
|
18
|
-
PluginOptions,
|
|
19
|
-
VersionBanner,
|
|
20
|
-
VersionOptions,
|
|
21
|
-
VersionsOptions,
|
|
22
|
-
} from '@docusaurus/plugin-content-docs';
|
|
23
|
-
|
|
24
|
-
import type {LoadContext} from '@docusaurus/types';
|
|
25
|
-
import {
|
|
26
|
-
getPluginI18nPath,
|
|
27
|
-
normalizeUrl,
|
|
28
|
-
posixPath,
|
|
29
|
-
DEFAULT_PLUGIN_ID,
|
|
30
|
-
} from '@docusaurus/utils';
|
|
31
|
-
import _ from 'lodash';
|
|
32
|
-
import {resolveSidebarPathOption} from './sidebars';
|
|
33
|
-
|
|
34
|
-
// retro-compatibility: no prefix for the default plugin id
|
|
35
|
-
function addPluginIdPrefix(fileOrDir: string, pluginId: string): string {
|
|
36
|
-
return pluginId === DEFAULT_PLUGIN_ID
|
|
37
|
-
? fileOrDir
|
|
38
|
-
: `${pluginId}_${fileOrDir}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getVersionedDocsDirPath(
|
|
42
|
-
siteDir: string,
|
|
43
|
-
pluginId: string,
|
|
44
|
-
): string {
|
|
45
|
-
return path.join(siteDir, addPluginIdPrefix(VERSIONED_DOCS_DIR, pluginId));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function getVersionedSidebarsDirPath(
|
|
49
|
-
siteDir: string,
|
|
50
|
-
pluginId: string,
|
|
51
|
-
): string {
|
|
52
|
-
return path.join(
|
|
53
|
-
siteDir,
|
|
54
|
-
addPluginIdPrefix(VERSIONED_SIDEBARS_DIR, pluginId),
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function getVersionsFilePath(siteDir: string, pluginId: string): string {
|
|
59
|
-
return path.join(siteDir, addPluginIdPrefix(VERSIONS_JSON_FILE, pluginId));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function ensureValidVersionString(version: unknown): asserts version is string {
|
|
63
|
-
if (typeof version !== 'string') {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Versions should be strings. Found type "${typeof version}" for version "${version}".`,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
// Should we forbid versions with special chars like / ?
|
|
69
|
-
if (version.trim().length === 0) {
|
|
70
|
-
throw new Error(`Invalid version "${version}".`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function ensureValidVersionArray(
|
|
75
|
-
versionArray: unknown,
|
|
76
|
-
): asserts versionArray is string[] {
|
|
77
|
-
if (!(versionArray instanceof Array)) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`The versions file should contain an array of versions! Found content: ${JSON.stringify(
|
|
80
|
-
versionArray,
|
|
81
|
-
)}`,
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
versionArray.forEach(ensureValidVersionString);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export async function readVersionsFile(
|
|
89
|
-
siteDir: string,
|
|
90
|
-
pluginId: string,
|
|
91
|
-
): Promise<string[] | null> {
|
|
92
|
-
const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
|
|
93
|
-
if (await fs.pathExists(versionsFilePath)) {
|
|
94
|
-
const content = JSON.parse(await fs.readFile(versionsFilePath, 'utf8'));
|
|
95
|
-
ensureValidVersionArray(content);
|
|
96
|
-
return content;
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export async function readVersionNames(
|
|
102
|
-
siteDir: string,
|
|
103
|
-
options: Pick<
|
|
104
|
-
PluginOptions,
|
|
105
|
-
'id' | 'disableVersioning' | 'includeCurrentVersion'
|
|
106
|
-
>,
|
|
107
|
-
): Promise<string[]> {
|
|
108
|
-
const versionFileContent = await readVersionsFile(siteDir, options.id);
|
|
109
|
-
|
|
110
|
-
if (!versionFileContent && options.disableVersioning) {
|
|
111
|
-
throw new Error(
|
|
112
|
-
`Docs: using "disableVersioning: ${options.disableVersioning}" option on a non-versioned site does not make sense.`,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const versions = options.disableVersioning ? [] : versionFileContent ?? [];
|
|
117
|
-
|
|
118
|
-
// We add the current version at the beginning, unless:
|
|
119
|
-
// - user don't want to; or
|
|
120
|
-
// - it's already been explicitly added to versions.json
|
|
121
|
-
if (
|
|
122
|
-
options.includeCurrentVersion &&
|
|
123
|
-
!versions.includes(CURRENT_VERSION_NAME)
|
|
124
|
-
) {
|
|
125
|
-
versions.unshift(CURRENT_VERSION_NAME);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (versions.length === 0) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
`It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion: ${options.includeCurrentVersion}", "disableVersioning: ${options.disableVersioning}".`,
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return versions;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function getDocsDirPathLocalized({
|
|
138
|
-
siteDir,
|
|
139
|
-
locale,
|
|
140
|
-
pluginId,
|
|
141
|
-
versionName,
|
|
142
|
-
}: {
|
|
143
|
-
siteDir: string;
|
|
144
|
-
locale: string;
|
|
145
|
-
pluginId: string;
|
|
146
|
-
versionName: string;
|
|
147
|
-
}) {
|
|
148
|
-
return getPluginI18nPath({
|
|
149
|
-
siteDir,
|
|
150
|
-
locale,
|
|
151
|
-
pluginName: 'docusaurus-plugin-content-docs',
|
|
152
|
-
pluginId,
|
|
153
|
-
subPaths: [
|
|
154
|
-
versionName === CURRENT_VERSION_NAME
|
|
155
|
-
? CURRENT_VERSION_NAME
|
|
156
|
-
: `version-${versionName}`,
|
|
157
|
-
],
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function getVersionMetadataPaths({
|
|
162
|
-
versionName,
|
|
163
|
-
context,
|
|
164
|
-
options,
|
|
165
|
-
}: {
|
|
166
|
-
versionName: string;
|
|
167
|
-
context: Pick<LoadContext, 'siteDir' | 'i18n'>;
|
|
168
|
-
options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath'>;
|
|
169
|
-
}): Pick<
|
|
170
|
-
VersionMetadata,
|
|
171
|
-
'contentPath' | 'contentPathLocalized' | 'sidebarFilePath'
|
|
172
|
-
> {
|
|
173
|
-
const isCurrentVersion = versionName === CURRENT_VERSION_NAME;
|
|
174
|
-
|
|
175
|
-
const contentPathLocalized = getDocsDirPathLocalized({
|
|
176
|
-
siteDir: context.siteDir,
|
|
177
|
-
locale: context.i18n.currentLocale,
|
|
178
|
-
pluginId: options.id,
|
|
179
|
-
versionName,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
if (isCurrentVersion) {
|
|
183
|
-
return {
|
|
184
|
-
contentPath: path.resolve(context.siteDir, options.path),
|
|
185
|
-
contentPathLocalized,
|
|
186
|
-
sidebarFilePath: resolveSidebarPathOption(
|
|
187
|
-
context.siteDir,
|
|
188
|
-
options.sidebarPath,
|
|
189
|
-
),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
contentPath: path.join(
|
|
195
|
-
getVersionedDocsDirPath(context.siteDir, options.id),
|
|
196
|
-
`version-${versionName}`,
|
|
197
|
-
),
|
|
198
|
-
contentPathLocalized,
|
|
199
|
-
sidebarFilePath: path.join(
|
|
200
|
-
getVersionedSidebarsDirPath(context.siteDir, options.id),
|
|
201
|
-
`version-${versionName}-sidebars.json`,
|
|
202
|
-
),
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function getVersionEditUrls({
|
|
207
|
-
contentPath,
|
|
208
|
-
contentPathLocalized,
|
|
209
|
-
context: {siteDir, i18n},
|
|
210
|
-
options: {id, path: currentVersionPath, editUrl, editCurrentVersion},
|
|
211
|
-
}: {
|
|
212
|
-
contentPath: string;
|
|
213
|
-
contentPathLocalized: string;
|
|
214
|
-
context: Pick<LoadContext, 'siteDir' | 'i18n'>;
|
|
215
|
-
options: Pick<
|
|
216
|
-
PluginOptions,
|
|
217
|
-
'id' | 'path' | 'editUrl' | 'editCurrentVersion'
|
|
218
|
-
>;
|
|
219
|
-
}): {versionEditUrl: string; versionEditUrlLocalized: string} | undefined {
|
|
220
|
-
if (!editUrl) {
|
|
221
|
-
return undefined;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// if the user is using the functional form of editUrl,
|
|
225
|
-
// he has total freedom and we can't compute a "version edit url"
|
|
226
|
-
if (typeof editUrl === 'function') {
|
|
227
|
-
return undefined;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const editDirPath = editCurrentVersion ? currentVersionPath : contentPath;
|
|
231
|
-
const editDirPathLocalized = editCurrentVersion
|
|
232
|
-
? getDocsDirPathLocalized({
|
|
233
|
-
siteDir,
|
|
234
|
-
locale: i18n.currentLocale,
|
|
235
|
-
versionName: CURRENT_VERSION_NAME,
|
|
236
|
-
pluginId: id,
|
|
237
|
-
})
|
|
238
|
-
: contentPathLocalized;
|
|
239
|
-
|
|
240
|
-
const versionPathSegment = posixPath(
|
|
241
|
-
path.relative(siteDir, path.resolve(siteDir, editDirPath)),
|
|
242
|
-
);
|
|
243
|
-
const versionPathSegmentLocalized = posixPath(
|
|
244
|
-
path.relative(siteDir, path.resolve(siteDir, editDirPathLocalized)),
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
const versionEditUrl = normalizeUrl([editUrl, versionPathSegment]);
|
|
248
|
-
|
|
249
|
-
const versionEditUrlLocalized = normalizeUrl([
|
|
250
|
-
editUrl,
|
|
251
|
-
versionPathSegmentLocalized,
|
|
252
|
-
]);
|
|
253
|
-
|
|
254
|
-
return {
|
|
255
|
-
versionEditUrl,
|
|
256
|
-
versionEditUrlLocalized,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function getDefaultVersionBanner({
|
|
261
|
-
versionName,
|
|
262
|
-
versionNames,
|
|
263
|
-
lastVersionName,
|
|
264
|
-
}: {
|
|
265
|
-
versionName: string;
|
|
266
|
-
versionNames: string[];
|
|
267
|
-
lastVersionName: string;
|
|
268
|
-
}): VersionBanner | null {
|
|
269
|
-
// Current version: good, no banner
|
|
270
|
-
if (versionName === lastVersionName) {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
// Upcoming versions: unreleased banner
|
|
274
|
-
if (
|
|
275
|
-
versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)
|
|
276
|
-
) {
|
|
277
|
-
return 'unreleased';
|
|
278
|
-
}
|
|
279
|
-
// Older versions: display unmaintained banner
|
|
280
|
-
return 'unmaintained';
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export function getVersionBanner({
|
|
284
|
-
versionName,
|
|
285
|
-
versionNames,
|
|
286
|
-
lastVersionName,
|
|
287
|
-
options,
|
|
288
|
-
}: {
|
|
289
|
-
versionName: string;
|
|
290
|
-
versionNames: string[];
|
|
291
|
-
lastVersionName: string;
|
|
292
|
-
options: Pick<PluginOptions, 'versions'>;
|
|
293
|
-
}): VersionBanner | null {
|
|
294
|
-
const versionBannerOption = options.versions[versionName]?.banner;
|
|
295
|
-
if (versionBannerOption) {
|
|
296
|
-
return versionBannerOption === 'none' ? null : versionBannerOption;
|
|
297
|
-
}
|
|
298
|
-
return getDefaultVersionBanner({
|
|
299
|
-
versionName,
|
|
300
|
-
versionNames,
|
|
301
|
-
lastVersionName,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export function getVersionBadge({
|
|
306
|
-
versionName,
|
|
307
|
-
versionNames,
|
|
308
|
-
options,
|
|
309
|
-
}: {
|
|
310
|
-
versionName: string;
|
|
311
|
-
versionNames: string[];
|
|
312
|
-
options: Pick<PluginOptions, 'versions'>;
|
|
313
|
-
}): boolean {
|
|
314
|
-
const versionBadgeOption = options.versions[versionName]?.badge;
|
|
315
|
-
// If site is not versioned or only one version is included
|
|
316
|
-
// we don't show the version badge by default
|
|
317
|
-
// See https://github.com/facebook/docusaurus/issues/3362
|
|
318
|
-
const versionBadgeDefault = versionNames.length !== 1;
|
|
319
|
-
return versionBadgeOption ?? versionBadgeDefault;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function getVersionClassName({
|
|
323
|
-
versionName,
|
|
324
|
-
options,
|
|
325
|
-
}: {
|
|
326
|
-
versionName: string;
|
|
327
|
-
options: Pick<PluginOptions, 'versions'>;
|
|
328
|
-
}): string {
|
|
329
|
-
const versionClassNameOption = options.versions[versionName]?.className;
|
|
330
|
-
const versionClassNameDefault = `docs-version-${versionName}`;
|
|
331
|
-
return versionClassNameOption ?? versionClassNameDefault;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function createVersionMetadata({
|
|
335
|
-
versionName,
|
|
336
|
-
versionNames,
|
|
337
|
-
lastVersionName,
|
|
338
|
-
context,
|
|
339
|
-
options,
|
|
340
|
-
}: {
|
|
341
|
-
versionName: string;
|
|
342
|
-
versionNames: string[];
|
|
343
|
-
lastVersionName: string;
|
|
344
|
-
context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
|
|
345
|
-
options: Pick<
|
|
346
|
-
PluginOptions,
|
|
347
|
-
| 'id'
|
|
348
|
-
| 'path'
|
|
349
|
-
| 'sidebarPath'
|
|
350
|
-
| 'routeBasePath'
|
|
351
|
-
| 'tagsBasePath'
|
|
352
|
-
| 'versions'
|
|
353
|
-
| 'editUrl'
|
|
354
|
-
| 'editCurrentVersion'
|
|
355
|
-
>;
|
|
356
|
-
}): VersionMetadata {
|
|
357
|
-
const {sidebarFilePath, contentPath, contentPathLocalized} =
|
|
358
|
-
getVersionMetadataPaths({versionName, context, options});
|
|
359
|
-
|
|
360
|
-
const isLast = versionName === lastVersionName;
|
|
361
|
-
|
|
362
|
-
// retro-compatible values
|
|
363
|
-
const defaultVersionLabel =
|
|
364
|
-
versionName === CURRENT_VERSION_NAME ? 'Next' : versionName;
|
|
365
|
-
function getDefaultVersionPathPart() {
|
|
366
|
-
if (isLast) {
|
|
367
|
-
return '';
|
|
368
|
-
}
|
|
369
|
-
return versionName === CURRENT_VERSION_NAME ? 'next' : versionName;
|
|
370
|
-
}
|
|
371
|
-
const defaultVersionPathPart = getDefaultVersionPathPart();
|
|
372
|
-
|
|
373
|
-
const versionOptions: VersionOptions = options.versions[versionName] ?? {};
|
|
374
|
-
|
|
375
|
-
const versionLabel = versionOptions.label ?? defaultVersionLabel;
|
|
376
|
-
const versionPathPart = versionOptions.path ?? defaultVersionPathPart;
|
|
377
|
-
|
|
378
|
-
const versionPath = normalizeUrl([
|
|
379
|
-
context.baseUrl,
|
|
380
|
-
options.routeBasePath,
|
|
381
|
-
versionPathPart,
|
|
382
|
-
]);
|
|
383
|
-
|
|
384
|
-
const versionEditUrls = getVersionEditUrls({
|
|
385
|
-
contentPath,
|
|
386
|
-
contentPathLocalized,
|
|
387
|
-
context,
|
|
388
|
-
options,
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
// Because /docs/:route` should always be after `/docs/versionName/:route`.
|
|
392
|
-
const routePriority = versionPathPart === '' ? -1 : undefined;
|
|
393
|
-
|
|
394
|
-
// the path that will be used to refer the docs tags
|
|
395
|
-
// example below will be using /docs/tags
|
|
396
|
-
const tagsPath = normalizeUrl([versionPath, options.tagsBasePath]);
|
|
397
|
-
|
|
398
|
-
return {
|
|
399
|
-
versionName,
|
|
400
|
-
versionLabel,
|
|
401
|
-
versionPath,
|
|
402
|
-
tagsPath,
|
|
403
|
-
versionEditUrl: versionEditUrls?.versionEditUrl,
|
|
404
|
-
versionEditUrlLocalized: versionEditUrls?.versionEditUrlLocalized,
|
|
405
|
-
versionBanner: getVersionBanner({
|
|
406
|
-
versionName,
|
|
407
|
-
versionNames,
|
|
408
|
-
lastVersionName,
|
|
409
|
-
options,
|
|
410
|
-
}),
|
|
411
|
-
versionBadge: getVersionBadge({versionName, versionNames, options}),
|
|
412
|
-
versionClassName: getVersionClassName({versionName, options}),
|
|
413
|
-
isLast,
|
|
414
|
-
routePriority,
|
|
415
|
-
sidebarFilePath,
|
|
416
|
-
contentPath,
|
|
417
|
-
contentPathLocalized,
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
async function checkVersionMetadataPaths({
|
|
422
|
-
versionMetadata,
|
|
423
|
-
context,
|
|
424
|
-
}: {
|
|
425
|
-
versionMetadata: VersionMetadata;
|
|
426
|
-
context: Pick<LoadContext, 'siteDir'>;
|
|
427
|
-
}) {
|
|
428
|
-
const {versionName, contentPath, sidebarFilePath} = versionMetadata;
|
|
429
|
-
const {siteDir} = context;
|
|
430
|
-
const isCurrentVersion = versionName === CURRENT_VERSION_NAME;
|
|
431
|
-
|
|
432
|
-
if (!(await fs.pathExists(contentPath))) {
|
|
433
|
-
throw new Error(
|
|
434
|
-
`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path.relative(
|
|
435
|
-
siteDir,
|
|
436
|
-
contentPath,
|
|
437
|
-
)}.`,
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// If the current version defines a path to a sidebar file that does not
|
|
442
|
-
// exist, we throw! Note: for versioned sidebars, the file may not exist (as
|
|
443
|
-
// we prefer to not create it rather than to create an empty file)
|
|
444
|
-
// See https://github.com/facebook/docusaurus/issues/3366
|
|
445
|
-
// See https://github.com/facebook/docusaurus/pull/4775
|
|
446
|
-
if (
|
|
447
|
-
isCurrentVersion &&
|
|
448
|
-
typeof sidebarFilePath === 'string' &&
|
|
449
|
-
!(await fs.pathExists(sidebarFilePath))
|
|
450
|
-
) {
|
|
451
|
-
throw new Error(`The path to the sidebar file does not exist at "${path.relative(
|
|
452
|
-
siteDir,
|
|
453
|
-
sidebarFilePath,
|
|
454
|
-
)}".
|
|
455
|
-
Please set the docs "sidebarPath" field in your config file to:
|
|
456
|
-
- a sidebars path that exists
|
|
457
|
-
- false: to disable the sidebar
|
|
458
|
-
- undefined: for Docusaurus to generate it automatically`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// TODO for retrocompatibility with existing behavior
|
|
463
|
-
// We should make this configurable
|
|
464
|
-
// "last version" is not a very good concept nor api surface
|
|
465
|
-
function getDefaultLastVersionName(versionNames: string[]) {
|
|
466
|
-
if (versionNames.length === 1) {
|
|
467
|
-
return versionNames[0];
|
|
468
|
-
}
|
|
469
|
-
return versionNames.filter(
|
|
470
|
-
(versionName) => versionName !== CURRENT_VERSION_NAME,
|
|
471
|
-
)[0];
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
function checkVersionsOptions(
|
|
475
|
-
availableVersionNames: string[],
|
|
476
|
-
options: VersionsOptions,
|
|
477
|
-
) {
|
|
478
|
-
const availableVersionNamesMsg = `Available version names are: ${availableVersionNames.join(
|
|
479
|
-
', ',
|
|
480
|
-
)}`;
|
|
481
|
-
if (
|
|
482
|
-
options.lastVersion &&
|
|
483
|
-
!availableVersionNames.includes(options.lastVersion)
|
|
484
|
-
) {
|
|
485
|
-
throw new Error(
|
|
486
|
-
`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`,
|
|
487
|
-
);
|
|
488
|
-
}
|
|
489
|
-
const unknownVersionConfigNames = _.difference(
|
|
490
|
-
Object.keys(options.versions),
|
|
491
|
-
availableVersionNames,
|
|
492
|
-
);
|
|
493
|
-
if (unknownVersionConfigNames.length > 0) {
|
|
494
|
-
throw new Error(
|
|
495
|
-
`Invalid docs option "versions": unknown versions (${unknownVersionConfigNames.join(
|
|
496
|
-
',',
|
|
497
|
-
)}) found. ${availableVersionNamesMsg}`,
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
if (options.onlyIncludeVersions) {
|
|
502
|
-
if (options.onlyIncludeVersions.length === 0) {
|
|
503
|
-
throw new Error(
|
|
504
|
-
`Invalid docs option "onlyIncludeVersions": an empty array is not allowed, at least one version is needed.`,
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
const unknownOnlyIncludeVersionNames = _.difference(
|
|
508
|
-
options.onlyIncludeVersions,
|
|
509
|
-
availableVersionNames,
|
|
510
|
-
);
|
|
511
|
-
if (unknownOnlyIncludeVersionNames.length > 0) {
|
|
512
|
-
throw new Error(
|
|
513
|
-
`Invalid docs option "onlyIncludeVersions": unknown versions (${unknownOnlyIncludeVersionNames.join(
|
|
514
|
-
',',
|
|
515
|
-
)}) found. ${availableVersionNamesMsg}`,
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
if (
|
|
519
|
-
options.lastVersion &&
|
|
520
|
-
!options.onlyIncludeVersions.includes(options.lastVersion)
|
|
521
|
-
) {
|
|
522
|
-
throw new Error(
|
|
523
|
-
`Invalid docs option "lastVersion": if you use both the "onlyIncludeVersions" and "lastVersion" options, then "lastVersion" must be present in the provided "onlyIncludeVersions" array.`,
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Filter versions according to provided options.
|
|
531
|
-
* Note: we preserve the order in which versions are provided;
|
|
532
|
-
* the order of the onlyIncludeVersions array does not matter
|
|
533
|
-
*/
|
|
534
|
-
export function filterVersions(
|
|
535
|
-
versionNamesUnfiltered: string[],
|
|
536
|
-
options: Pick<PluginOptions, 'onlyIncludeVersions'>,
|
|
537
|
-
): string[] {
|
|
538
|
-
if (options.onlyIncludeVersions) {
|
|
539
|
-
return versionNamesUnfiltered.filter((name) =>
|
|
540
|
-
(options.onlyIncludeVersions || []).includes(name),
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
return versionNamesUnfiltered;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
export async function readVersionsMetadata({
|
|
547
|
-
context,
|
|
548
|
-
options,
|
|
549
|
-
}: {
|
|
550
|
-
context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
|
|
551
|
-
options: Pick<
|
|
552
|
-
PluginOptions,
|
|
553
|
-
| 'id'
|
|
554
|
-
| 'path'
|
|
555
|
-
| 'sidebarPath'
|
|
556
|
-
| 'routeBasePath'
|
|
557
|
-
| 'tagsBasePath'
|
|
558
|
-
| 'includeCurrentVersion'
|
|
559
|
-
| 'disableVersioning'
|
|
560
|
-
| 'lastVersion'
|
|
561
|
-
| 'versions'
|
|
562
|
-
| 'onlyIncludeVersions'
|
|
563
|
-
| 'editUrl'
|
|
564
|
-
| 'editCurrentVersion'
|
|
565
|
-
>;
|
|
566
|
-
}): Promise<VersionMetadata[]> {
|
|
567
|
-
const versionNamesUnfiltered = await readVersionNames(
|
|
568
|
-
context.siteDir,
|
|
569
|
-
options,
|
|
570
|
-
);
|
|
571
|
-
|
|
572
|
-
checkVersionsOptions(versionNamesUnfiltered, options);
|
|
573
|
-
|
|
574
|
-
const versionNames = filterVersions(versionNamesUnfiltered, options);
|
|
575
|
-
|
|
576
|
-
const lastVersionName =
|
|
577
|
-
options.lastVersion ?? getDefaultLastVersionName(versionNames);
|
|
578
|
-
|
|
579
|
-
const versionsMetadata = versionNames.map((versionName) =>
|
|
580
|
-
createVersionMetadata({
|
|
581
|
-
versionName,
|
|
582
|
-
versionNames,
|
|
583
|
-
lastVersionName,
|
|
584
|
-
context,
|
|
585
|
-
options,
|
|
586
|
-
}),
|
|
587
|
-
);
|
|
588
|
-
await Promise.all(
|
|
589
|
-
versionsMetadata.map((versionMetadata) =>
|
|
590
|
-
checkVersionMetadataPaths({versionMetadata, context}),
|
|
591
|
-
),
|
|
592
|
-
);
|
|
593
|
-
return versionsMetadata;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
// order matter!
|
|
597
|
-
// Read in priority the localized path, then the unlocalized one
|
|
598
|
-
// We want the localized doc to "override" the unlocalized one
|
|
599
|
-
export function getDocsDirPaths(
|
|
600
|
-
versionMetadata: Pick<
|
|
601
|
-
VersionMetadata,
|
|
602
|
-
'contentPath' | 'contentPathLocalized'
|
|
603
|
-
>,
|
|
604
|
-
): [string, string] {
|
|
605
|
-
return [versionMetadata.contentPathLocalized, versionMetadata.contentPath];
|
|
606
|
-
}
|