@docusaurus/plugin-content-docs 2.0.0-beta.14 → 2.0.0-beta.15
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 +2 -2
- package/lib/categoryGeneratedIndex.js +2 -0
- package/lib/cli.d.ts +1 -1
- package/lib/client/docsClientUtils.d.ts +3 -22
- package/lib/client/docsClientUtils.js +5 -1
- package/lib/{theme/hooks/useDocs.d.ts → client/globalDataHooks.d.ts} +1 -2
- package/lib/{theme/hooks/useDocs.js → client/globalDataHooks.js} +2 -1
- package/lib/client/index.d.ts +7 -0
- package/lib/client/index.js +10 -0
- package/lib/docFrontMatter.js +1 -0
- package/lib/docs.d.ts +19 -6
- package/lib/docs.js +37 -17
- package/lib/globalData.d.ts +5 -1
- package/lib/globalData.js +34 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.js +2 -8
- package/lib/lastUpdate.js +2 -2
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/linkify.d.ts +1 -1
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/options.d.ts +1 -1
- package/lib/routes.d.ts +4 -3
- package/lib/routes.js +6 -3
- package/lib/sidebars/generator.js +12 -14
- package/lib/sidebars/index.d.ts +3 -2
- package/lib/sidebars/processor.d.ts +3 -2
- package/lib/sidebars/processor.js +2 -0
- package/lib/sidebars/types.d.ts +8 -3
- package/lib/sidebars/utils.d.ts +12 -4
- package/lib/sidebars/utils.js +48 -3
- package/lib/sidebars/validation.d.ts +1 -1
- package/lib/sidebars/validation.js +4 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +8 -7
- package/lib/translations.js +1 -1
- package/lib/types.d.ts +7 -78
- package/lib/versions.d.ts +3 -2
- package/lib/versions.js +27 -32
- package/package.json +14 -12
- package/src/categoryGeneratedIndex.ts +5 -3
- package/src/cli.ts +4 -1
- package/src/client/docsClientUtils.ts +22 -35
- package/src/{theme/hooks/useDocs.ts → client/globalDataHooks.ts} +6 -2
- package/src/client/index.ts +8 -0
- package/src/docFrontMatter.ts +2 -1
- package/src/docs.ts +62 -29
- package/src/globalData.ts +49 -3
- package/src/index.ts +9 -15
- package/src/lastUpdate.ts +2 -2
- package/src/markdown/index.ts +1 -1
- package/src/markdown/linkify.ts +1 -1
- package/src/numberPrefix.ts +1 -1
- package/src/options.ts +1 -1
- package/src/plugin-content-docs.d.ts +128 -18
- package/src/routes.ts +19 -5
- package/src/sidebars/generator.ts +25 -20
- package/src/sidebars/index.ts +3 -2
- package/src/sidebars/normalization.ts +2 -1
- package/src/sidebars/processor.ts +8 -7
- package/src/sidebars/types.ts +9 -5
- package/src/sidebars/utils.ts +76 -8
- package/src/sidebars/validation.ts +6 -1
- package/src/slug.ts +15 -11
- package/src/translations.ts +2 -2
- package/src/types.ts +12 -98
- package/src/versions.ts +51 -47
package/src/versions.ts
CHANGED
|
@@ -7,19 +7,19 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
|
-
import type {
|
|
11
|
-
PluginOptions,
|
|
12
|
-
VersionBanner,
|
|
13
|
-
VersionMetadata,
|
|
14
|
-
VersionOptions,
|
|
15
|
-
VersionsOptions,
|
|
16
|
-
} from './types';
|
|
10
|
+
import type {VersionMetadata} from './types';
|
|
17
11
|
import {
|
|
18
12
|
VERSIONS_JSON_FILE,
|
|
19
13
|
VERSIONED_DOCS_DIR,
|
|
20
14
|
VERSIONED_SIDEBARS_DIR,
|
|
21
15
|
CURRENT_VERSION_NAME,
|
|
22
16
|
} from './constants';
|
|
17
|
+
import type {
|
|
18
|
+
PluginOptions,
|
|
19
|
+
VersionBanner,
|
|
20
|
+
VersionOptions,
|
|
21
|
+
VersionsOptions,
|
|
22
|
+
} from '@docusaurus/plugin-content-docs';
|
|
23
23
|
|
|
24
24
|
import type {LoadContext} from '@docusaurus/types';
|
|
25
25
|
import {
|
|
@@ -87,11 +87,13 @@ function ensureValidVersionArray(
|
|
|
87
87
|
versionArray.forEach(ensureValidVersionString);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
async function readVersionsFile(
|
|
91
|
+
siteDir: string,
|
|
92
|
+
pluginId: string,
|
|
93
|
+
): Promise<string[] | null> {
|
|
92
94
|
const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
|
|
93
|
-
if (fs.
|
|
94
|
-
const content = JSON.parse(fs.
|
|
95
|
+
if (await fs.pathExists(versionsFilePath)) {
|
|
96
|
+
const content = JSON.parse(await fs.readFile(versionsFilePath, 'utf8'));
|
|
95
97
|
ensureValidVersionArray(content);
|
|
96
98
|
return content;
|
|
97
99
|
} else {
|
|
@@ -99,27 +101,26 @@ function readVersionsFile(siteDir: string, pluginId: string): string[] | null {
|
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
function readVersionNames(
|
|
104
|
+
async function readVersionNames(
|
|
104
105
|
siteDir: string,
|
|
105
106
|
options: Pick<
|
|
106
107
|
PluginOptions,
|
|
107
108
|
'id' | 'disableVersioning' | 'includeCurrentVersion'
|
|
108
109
|
>,
|
|
109
|
-
): string[] {
|
|
110
|
-
const versionFileContent = readVersionsFile(siteDir, options.id);
|
|
110
|
+
): Promise<string[]> {
|
|
111
|
+
const versionFileContent = await readVersionsFile(siteDir, options.id);
|
|
111
112
|
|
|
112
113
|
if (!versionFileContent && options.disableVersioning) {
|
|
113
114
|
throw new Error(
|
|
114
|
-
`Docs: using "disableVersioning
|
|
115
|
+
`Docs: using "disableVersioning: ${options.disableVersioning}" option on a non-versioned site does not make sense.`,
|
|
115
116
|
);
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
const versions = options.disableVersioning ? [] : versionFileContent ?? [];
|
|
119
120
|
|
|
120
|
-
// We add the current version at the beginning, unless
|
|
121
|
-
// - user don't want to
|
|
122
|
-
// - it's been explicitly added to versions.json
|
|
121
|
+
// We add the current version at the beginning, unless:
|
|
122
|
+
// - user don't want to; or
|
|
123
|
+
// - it's already been explicitly added to versions.json
|
|
123
124
|
if (
|
|
124
125
|
options.includeCurrentVersion &&
|
|
125
126
|
!versions.includes(CURRENT_VERSION_NAME)
|
|
@@ -129,7 +130,7 @@ function readVersionNames(
|
|
|
129
130
|
|
|
130
131
|
if (versions.length === 0) {
|
|
131
132
|
throw new Error(
|
|
132
|
-
`It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion
|
|
133
|
+
`It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion: ${options.includeCurrentVersion}", "disableVersioning: ${options.disableVersioning}".`,
|
|
133
134
|
);
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -174,13 +175,6 @@ function getVersionMetadataPaths({
|
|
|
174
175
|
> {
|
|
175
176
|
const isCurrentVersion = versionName === CURRENT_VERSION_NAME;
|
|
176
177
|
|
|
177
|
-
const contentPath = isCurrentVersion
|
|
178
|
-
? path.resolve(context.siteDir, options.path)
|
|
179
|
-
: path.join(
|
|
180
|
-
getVersionedDocsDirPath(context.siteDir, options.id),
|
|
181
|
-
`version-${versionName}`,
|
|
182
|
-
);
|
|
183
|
-
|
|
184
178
|
const contentPathLocalized = getDocsDirPathLocalized({
|
|
185
179
|
siteDir: context.siteDir,
|
|
186
180
|
locale: context.i18n.currentLocale,
|
|
@@ -188,21 +182,27 @@ function getVersionMetadataPaths({
|
|
|
188
182
|
versionName,
|
|
189
183
|
});
|
|
190
184
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
)
|
|
199
|
-
}
|
|
185
|
+
if (isCurrentVersion) {
|
|
186
|
+
return {
|
|
187
|
+
contentPath: path.resolve(context.siteDir, options.path),
|
|
188
|
+
contentPathLocalized,
|
|
189
|
+
sidebarFilePath: resolveSidebarPathOption(
|
|
190
|
+
context.siteDir,
|
|
191
|
+
options.sidebarPath,
|
|
192
|
+
),
|
|
193
|
+
};
|
|
200
194
|
}
|
|
201
195
|
|
|
202
196
|
return {
|
|
203
|
-
contentPath
|
|
197
|
+
contentPath: path.join(
|
|
198
|
+
getVersionedDocsDirPath(context.siteDir, options.id),
|
|
199
|
+
`version-${versionName}`,
|
|
200
|
+
),
|
|
204
201
|
contentPathLocalized,
|
|
205
|
-
sidebarFilePath:
|
|
202
|
+
sidebarFilePath: path.join(
|
|
203
|
+
getVersionedSidebarsDirPath(context.siteDir, options.id),
|
|
204
|
+
`version-${versionName}-sidebars.json`,
|
|
205
|
+
),
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
208
|
|
|
@@ -459,7 +459,7 @@ function checkVersionMetadataPaths({
|
|
|
459
459
|
Please set the docs "sidebarPath" field in your config file to:
|
|
460
460
|
- a sidebars path that exists
|
|
461
461
|
- false: to disable the sidebar
|
|
462
|
-
- undefined: for Docusaurus
|
|
462
|
+
- undefined: for Docusaurus to generate it automatically`);
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
|
|
@@ -488,7 +488,7 @@ function checkVersionsOptions(
|
|
|
488
488
|
!availableVersionNames.includes(options.lastVersion)
|
|
489
489
|
) {
|
|
490
490
|
throw new Error(
|
|
491
|
-
`Docs option lastVersion
|
|
491
|
+
`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`,
|
|
492
492
|
);
|
|
493
493
|
}
|
|
494
494
|
const unknownVersionConfigNames = difference(
|
|
@@ -531,9 +531,11 @@ function checkVersionsOptions(
|
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
534
|
+
/**
|
|
535
|
+
* Filter versions according to provided options.
|
|
536
|
+
* Note: we preserve the order in which versions are provided;
|
|
537
|
+
* the order of the onlyIncludeVersions array does not matter
|
|
538
|
+
*/
|
|
537
539
|
function filterVersions(
|
|
538
540
|
versionNamesUnfiltered: string[],
|
|
539
541
|
options: Pick<PluginOptions, 'onlyIncludeVersions'>,
|
|
@@ -547,8 +549,7 @@ function filterVersions(
|
|
|
547
549
|
}
|
|
548
550
|
}
|
|
549
551
|
|
|
550
|
-
|
|
551
|
-
export function readVersionsMetadata({
|
|
552
|
+
export async function readVersionsMetadata({
|
|
552
553
|
context,
|
|
553
554
|
options,
|
|
554
555
|
}: {
|
|
@@ -568,8 +569,11 @@ export function readVersionsMetadata({
|
|
|
568
569
|
| 'editUrl'
|
|
569
570
|
| 'editCurrentVersion'
|
|
570
571
|
>;
|
|
571
|
-
}): VersionMetadata[] {
|
|
572
|
-
const versionNamesUnfiltered = readVersionNames(
|
|
572
|
+
}): Promise<VersionMetadata[]> {
|
|
573
|
+
const versionNamesUnfiltered = await readVersionNames(
|
|
574
|
+
context.siteDir,
|
|
575
|
+
options,
|
|
576
|
+
);
|
|
573
577
|
|
|
574
578
|
checkVersionsOptions(versionNamesUnfiltered, options);
|
|
575
579
|
|