@docusaurus/plugin-content-docs 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.21
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 +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.d.ts +3 -2
- package/lib/cli.js +58 -72
- package/lib/client/docsClientUtils.d.ts +9 -28
- package/lib/client/docsClientUtils.js +34 -43
- package/lib/client/index.d.ts +22 -0
- package/lib/client/index.js +59 -0
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +32 -3
- package/lib/docs.js +164 -63
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
- package/lib/{docFrontMatter.js → frontMatter.js} +12 -3
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +123 -149
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +22 -26
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.d.ts +1 -1
- package/lib/markdown/linkify.js +6 -3
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +16 -21
- package/lib/options.d.ts +3 -5
- package/lib/options.js +54 -13
- package/lib/props.d.ts +7 -2
- package/lib/props.js +70 -14
- package/lib/routes.d.ts +29 -0
- package/lib/routes.js +96 -0
- package/lib/server-export.d.ts +9 -0
- package/lib/server-export.js +22 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
- package/lib/sidebars/generator.js +209 -0
- package/lib/sidebars/index.d.ts +13 -0
- package/lib/sidebars/index.js +92 -0
- package/lib/sidebars/normalization.d.ts +13 -0
- package/lib/sidebars/normalization.js +55 -0
- package/lib/sidebars/postProcessor.d.ts +11 -0
- package/lib/sidebars/postProcessor.js +81 -0
- package/lib/sidebars/processor.d.ts +10 -0
- package/lib/sidebars/processor.js +79 -0
- package/lib/sidebars/types.d.ts +178 -0
- package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
- package/lib/sidebars/utils.d.ts +54 -0
- package/lib/sidebars/utils.js +255 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +142 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +28 -18
- package/{src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js → lib/tags.d.ts} +3 -14
- package/lib/tags.js +21 -0
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +83 -93
- package/lib/types.d.ts +13 -184
- package/lib/versions/files.d.ts +51 -0
- package/lib/versions/files.js +143 -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 +34 -29
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +85 -114
- package/src/client/docsClientUtils.ts +44 -71
- package/src/client/index.ts +106 -0
- package/src/constants.ts +4 -2
- package/{types.d.ts → src/deps.d.ts} +1 -1
- package/src/docs.ts +228 -65
- package/src/{docFrontMatter.ts → frontMatter.ts} +20 -10
- package/src/globalData.ts +57 -7
- package/src/index.ts +179 -216
- package/src/lastUpdate.ts +26 -37
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +7 -4
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +59 -18
- package/src/plugin-content-docs.d.ts +642 -89
- package/src/props.ts +103 -21
- package/src/routes.ts +159 -0
- package/src/server-export.ts +22 -0
- package/src/sidebars/README.md +10 -0
- package/src/sidebars/generator.ts +292 -0
- package/src/sidebars/index.ts +118 -0
- package/src/sidebars/normalization.ts +85 -0
- package/src/sidebars/postProcessor.ts +112 -0
- package/src/sidebars/processor.ts +123 -0
- package/src/sidebars/types.ts +275 -0
- package/src/sidebars/utils.ts +390 -0
- package/src/sidebars/validation.ts +178 -0
- package/src/slug.ts +41 -22
- package/src/tags.ts +20 -0
- package/src/translations.ts +129 -123
- package/src/types.ts +18 -249
- package/src/versions/files.ts +220 -0
- package/src/versions/index.ts +247 -0
- package/src/versions/validation.ts +115 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -320
- package/lib/theme/hooks/useDocs.d.ts +0 -20
- package/lib/theme/hooks/useDocs.js +0 -75
- package/lib/versions.d.ts +0 -16
- package/lib/versions.js +0 -319
- package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
- package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
- package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
- package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
- package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
- package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
- package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
- package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
- package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
- package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
- package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js +0 -16
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
- package/src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
- package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
- package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
- package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
- package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
- package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
- package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
- package/src/__tests__/cli.test.ts +0 -333
- package/src/__tests__/docFrontMatter.test.ts +0 -244
- package/src/__tests__/docs.test.ts +0 -878
- package/src/__tests__/index.test.ts +0 -1871
- package/src/__tests__/lastUpdate.test.ts +0 -69
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -231
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -741
- package/src/client/__tests__/docsClientUtils.test.ts +0 -371
- package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
- package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
- package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
- package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
- package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
- package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
- package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
- package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
- package/src/markdown/__tests__/linkify.test.ts +0 -190
- package/src/sidebarItemsGenerator.ts +0 -307
- package/src/sidebars.ts +0 -522
- package/src/theme/hooks/useDocs.ts +0 -103
- package/src/versions.ts +0 -572
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,36 @@
|
|
|
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 { PluginOptions, VersionBanner, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
|
+
export declare type VersionContext = {
|
|
10
|
+
/** The version name to get banner of. */
|
|
11
|
+
versionName: string;
|
|
12
|
+
/** All versions, ordered from newest to oldest. */
|
|
13
|
+
versionNames: string[];
|
|
14
|
+
lastVersionName: string;
|
|
15
|
+
context: LoadContext;
|
|
16
|
+
options: PluginOptions;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The default version banner depends on the version's relative position to the
|
|
20
|
+
* latest version. More recent ones are "unreleased", and older ones are
|
|
21
|
+
* "unmaintained".
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }: VersionContext): VersionBanner | null;
|
|
24
|
+
export declare function getVersionBanner(context: VersionContext): VersionMetadata['banner'];
|
|
25
|
+
export declare function getVersionBadge({ versionName, versionNames, options, }: VersionContext): VersionMetadata['badge'];
|
|
26
|
+
/**
|
|
27
|
+
* Filter versions according to provided options (i.e. `onlyIncludeVersions`).
|
|
28
|
+
*
|
|
29
|
+
* Note: we preserve the order in which versions are provided; the order of the
|
|
30
|
+
* `onlyIncludeVersions` array does not matter
|
|
31
|
+
*/
|
|
32
|
+
export declare function filterVersions(versionNamesUnfiltered: string[], options: PluginOptions): string[];
|
|
33
|
+
export declare function readVersionsMetadata({ context, options, }: {
|
|
34
|
+
context: LoadContext;
|
|
35
|
+
options: PluginOptions;
|
|
36
|
+
}): Promise<VersionMetadata[]>;
|
|
@@ -0,0 +1,155 @@
|
|
|
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.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
const validation_1 = require("./validation");
|
|
15
|
+
const files_1 = require("./files");
|
|
16
|
+
function getVersionEditUrls({ contentPath, contentPathLocalized, context, options, }) {
|
|
17
|
+
// If the user is using the functional form of editUrl,
|
|
18
|
+
// she has total freedom and we can't compute a "version edit url"
|
|
19
|
+
if (!options.editUrl || typeof options.editUrl === 'function') {
|
|
20
|
+
return { editUrl: undefined, editUrlLocalized: undefined };
|
|
21
|
+
}
|
|
22
|
+
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
|
|
23
|
+
const editDirPathLocalized = options.editCurrentVersion
|
|
24
|
+
? (0, files_1.getDocsDirPathLocalized)({
|
|
25
|
+
siteDir: context.siteDir,
|
|
26
|
+
locale: context.i18n.currentLocale,
|
|
27
|
+
versionName: constants_1.CURRENT_VERSION_NAME,
|
|
28
|
+
pluginId: options.id,
|
|
29
|
+
})
|
|
30
|
+
: contentPathLocalized;
|
|
31
|
+
const versionPathSegment = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPath)));
|
|
32
|
+
const versionPathSegmentLocalized = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPathLocalized)));
|
|
33
|
+
const editUrl = (0, utils_1.normalizeUrl)([options.editUrl, versionPathSegment]);
|
|
34
|
+
const editUrlLocalized = (0, utils_1.normalizeUrl)([
|
|
35
|
+
options.editUrl,
|
|
36
|
+
versionPathSegmentLocalized,
|
|
37
|
+
]);
|
|
38
|
+
return { editUrl, editUrlLocalized };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The default version banner depends on the version's relative position to the
|
|
42
|
+
* latest version. More recent ones are "unreleased", and older ones are
|
|
43
|
+
* "unmaintained".
|
|
44
|
+
*/
|
|
45
|
+
function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }) {
|
|
46
|
+
// Current version: good, no banner
|
|
47
|
+
if (versionName === lastVersionName) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
// Upcoming versions: unreleased banner
|
|
51
|
+
if (versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)) {
|
|
52
|
+
return 'unreleased';
|
|
53
|
+
}
|
|
54
|
+
// Older versions: display unmaintained banner
|
|
55
|
+
return 'unmaintained';
|
|
56
|
+
}
|
|
57
|
+
exports.getDefaultVersionBanner = getDefaultVersionBanner;
|
|
58
|
+
function getVersionBanner(context) {
|
|
59
|
+
const { versionName, options } = context;
|
|
60
|
+
const versionBannerOption = options.versions[versionName]?.banner;
|
|
61
|
+
if (versionBannerOption) {
|
|
62
|
+
return versionBannerOption === 'none' ? null : versionBannerOption;
|
|
63
|
+
}
|
|
64
|
+
return getDefaultVersionBanner(context);
|
|
65
|
+
}
|
|
66
|
+
exports.getVersionBanner = getVersionBanner;
|
|
67
|
+
function getVersionBadge({ versionName, versionNames, options, }) {
|
|
68
|
+
// If site is not versioned or only one version is included
|
|
69
|
+
// we don't show the version badge by default
|
|
70
|
+
// See https://github.com/facebook/docusaurus/issues/3362
|
|
71
|
+
const defaultVersionBadge = versionNames.length !== 1;
|
|
72
|
+
return options.versions[versionName]?.badge ?? defaultVersionBadge;
|
|
73
|
+
}
|
|
74
|
+
exports.getVersionBadge = getVersionBadge;
|
|
75
|
+
function getVersionClassName({ versionName, options, }) {
|
|
76
|
+
const defaultVersionClassName = `docs-version-${versionName}`;
|
|
77
|
+
return options.versions[versionName]?.className ?? defaultVersionClassName;
|
|
78
|
+
}
|
|
79
|
+
function getVersionLabel({ versionName, options, }) {
|
|
80
|
+
const defaultVersionLabel = versionName === constants_1.CURRENT_VERSION_NAME ? 'Next' : versionName;
|
|
81
|
+
return options.versions[versionName]?.label ?? defaultVersionLabel;
|
|
82
|
+
}
|
|
83
|
+
function getVersionPathPart({ versionName, options, lastVersionName, }) {
|
|
84
|
+
function getDefaultVersionPathPart() {
|
|
85
|
+
if (versionName === lastVersionName) {
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
return versionName === constants_1.CURRENT_VERSION_NAME ? 'next' : versionName;
|
|
89
|
+
}
|
|
90
|
+
return options.versions[versionName]?.path ?? getDefaultVersionPathPart();
|
|
91
|
+
}
|
|
92
|
+
async function createVersionMetadata(context) {
|
|
93
|
+
const { versionName, lastVersionName, options, context: loadContext } = context;
|
|
94
|
+
const { sidebarFilePath, contentPath, contentPathLocalized } = await (0, files_1.getVersionMetadataPaths)(context);
|
|
95
|
+
const versionPathPart = getVersionPathPart(context);
|
|
96
|
+
const routePath = (0, utils_1.normalizeUrl)([
|
|
97
|
+
loadContext.baseUrl,
|
|
98
|
+
options.routeBasePath,
|
|
99
|
+
versionPathPart,
|
|
100
|
+
]);
|
|
101
|
+
const versionEditUrls = getVersionEditUrls({
|
|
102
|
+
contentPath,
|
|
103
|
+
contentPathLocalized,
|
|
104
|
+
context: loadContext,
|
|
105
|
+
options,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
versionName,
|
|
109
|
+
label: getVersionLabel(context),
|
|
110
|
+
banner: getVersionBanner(context),
|
|
111
|
+
badge: getVersionBadge(context),
|
|
112
|
+
className: getVersionClassName(context),
|
|
113
|
+
path: routePath,
|
|
114
|
+
tagsPath: (0, utils_1.normalizeUrl)([routePath, options.tagsBasePath]),
|
|
115
|
+
...versionEditUrls,
|
|
116
|
+
isLast: versionName === lastVersionName,
|
|
117
|
+
routePriority: versionPathPart === '' ? -1 : undefined,
|
|
118
|
+
sidebarFilePath,
|
|
119
|
+
contentPath,
|
|
120
|
+
contentPathLocalized,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Filter versions according to provided options (i.e. `onlyIncludeVersions`).
|
|
125
|
+
*
|
|
126
|
+
* Note: we preserve the order in which versions are provided; the order of the
|
|
127
|
+
* `onlyIncludeVersions` array does not matter
|
|
128
|
+
*/
|
|
129
|
+
function filterVersions(versionNamesUnfiltered, options) {
|
|
130
|
+
if (options.onlyIncludeVersions) {
|
|
131
|
+
return versionNamesUnfiltered.filter((name) => options.onlyIncludeVersions.includes(name));
|
|
132
|
+
}
|
|
133
|
+
return versionNamesUnfiltered;
|
|
134
|
+
}
|
|
135
|
+
exports.filterVersions = filterVersions;
|
|
136
|
+
function getLastVersionName({ versionNames, options, }) {
|
|
137
|
+
return (options.lastVersion ??
|
|
138
|
+
versionNames.find((name) => name !== constants_1.CURRENT_VERSION_NAME) ??
|
|
139
|
+
constants_1.CURRENT_VERSION_NAME);
|
|
140
|
+
}
|
|
141
|
+
async function readVersionsMetadata({ context, options, }) {
|
|
142
|
+
const allVersionNames = await (0, files_1.readVersionNames)(context.siteDir, options);
|
|
143
|
+
(0, validation_1.validateVersionsOptions)(allVersionNames, options);
|
|
144
|
+
const versionNames = filterVersions(allVersionNames, options);
|
|
145
|
+
const lastVersionName = getLastVersionName({ versionNames, options });
|
|
146
|
+
const versionsMetadata = await Promise.all(versionNames.map((versionName) => createVersionMetadata({
|
|
147
|
+
versionName,
|
|
148
|
+
versionNames,
|
|
149
|
+
lastVersionName,
|
|
150
|
+
context,
|
|
151
|
+
options,
|
|
152
|
+
})));
|
|
153
|
+
return versionsMetadata;
|
|
154
|
+
}
|
|
155
|
+
exports.readVersionsMetadata = readVersionsMetadata;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { VersionsOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
export declare function validateVersionName(name: unknown): asserts name is string;
|
|
9
|
+
export declare function validateVersionNames(names: unknown): asserts names is string[];
|
|
10
|
+
/**
|
|
11
|
+
* @throws Throws for one of the following invalid options:
|
|
12
|
+
* - `lastVersion` is non-existent
|
|
13
|
+
* - `versions` includes unknown keys
|
|
14
|
+
* - `onlyIncludeVersions` is empty, contains unknown names, or doesn't include
|
|
15
|
+
* `latestVersion` (if provided)
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateVersionsOptions(availableVersionNames: string[], options: VersionsOptions): void;
|
|
@@ -0,0 +1,71 @@
|
|
|
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.validateVersionsOptions = exports.validateVersionNames = exports.validateVersionName = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
function validateVersionName(name) {
|
|
13
|
+
if (typeof name !== 'string') {
|
|
14
|
+
throw new Error(`Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(name)}.`);
|
|
15
|
+
}
|
|
16
|
+
if (!name.trim()) {
|
|
17
|
+
throw new Error(`Invalid version name "${name}": version name must contain at least one non-whitespace character.`);
|
|
18
|
+
}
|
|
19
|
+
const errors = [
|
|
20
|
+
[/[/\\]/, 'should not include slash (/) or backslash (\\)'],
|
|
21
|
+
[/.{33,}/, 'cannot be longer than 32 characters'],
|
|
22
|
+
// eslint-disable-next-line no-control-regex
|
|
23
|
+
[/[<>:"|?*\x00-\x1F]/, 'should be a valid file path'],
|
|
24
|
+
[/^\.\.?$/, 'should not be "." or ".."'],
|
|
25
|
+
];
|
|
26
|
+
errors.forEach(([pattern, message]) => {
|
|
27
|
+
if (pattern.test(name)) {
|
|
28
|
+
throw new Error(`Invalid version name "${name}": version name ${message}.`);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.validateVersionName = validateVersionName;
|
|
33
|
+
function validateVersionNames(names) {
|
|
34
|
+
if (!Array.isArray(names)) {
|
|
35
|
+
throw new Error(`The versions file should contain an array of version names! Found content: ${JSON.stringify(names)}`);
|
|
36
|
+
}
|
|
37
|
+
names.forEach(validateVersionName);
|
|
38
|
+
}
|
|
39
|
+
exports.validateVersionNames = validateVersionNames;
|
|
40
|
+
/**
|
|
41
|
+
* @throws Throws for one of the following invalid options:
|
|
42
|
+
* - `lastVersion` is non-existent
|
|
43
|
+
* - `versions` includes unknown keys
|
|
44
|
+
* - `onlyIncludeVersions` is empty, contains unknown names, or doesn't include
|
|
45
|
+
* `latestVersion` (if provided)
|
|
46
|
+
*/
|
|
47
|
+
function validateVersionsOptions(availableVersionNames, options) {
|
|
48
|
+
const availableVersionNamesMsg = `Available version names are: ${availableVersionNames.join(', ')}`;
|
|
49
|
+
if (options.lastVersion &&
|
|
50
|
+
!availableVersionNames.includes(options.lastVersion)) {
|
|
51
|
+
throw new Error(`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
|
|
52
|
+
}
|
|
53
|
+
const unknownVersionConfigNames = lodash_1.default.difference(Object.keys(options.versions), availableVersionNames);
|
|
54
|
+
if (unknownVersionConfigNames.length > 0) {
|
|
55
|
+
throw new Error(`Invalid docs option "versions": unknown versions (${unknownVersionConfigNames.join(',')}) found. ${availableVersionNamesMsg}`);
|
|
56
|
+
}
|
|
57
|
+
if (options.onlyIncludeVersions) {
|
|
58
|
+
if (options.onlyIncludeVersions.length === 0) {
|
|
59
|
+
throw new Error(`Invalid docs option "onlyIncludeVersions": an empty array is not allowed, at least one version is needed.`);
|
|
60
|
+
}
|
|
61
|
+
const unknownOnlyIncludeVersionNames = lodash_1.default.difference(options.onlyIncludeVersions, availableVersionNames);
|
|
62
|
+
if (unknownOnlyIncludeVersionNames.length > 0) {
|
|
63
|
+
throw new Error(`Invalid docs option "onlyIncludeVersions": unknown versions (${unknownOnlyIncludeVersionNames.join(',')}) found. ${availableVersionNamesMsg}`);
|
|
64
|
+
}
|
|
65
|
+
if (options.lastVersion &&
|
|
66
|
+
!options.onlyIncludeVersions.includes(options.lastVersion)) {
|
|
67
|
+
throw new Error(`Invalid docs option "lastVersion": if you use both the "onlyIncludeVersions" and "lastVersion" options, then "lastVersion" must be present in the provided "onlyIncludeVersions" array.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.validateVersionsOptions = validateVersionsOptions;
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
"./src/*": "./src/*",
|
|
9
|
+
"./client": "./lib/client/index.js",
|
|
10
|
+
"./server": "./lib/server-export.js",
|
|
11
|
+
".": "./lib/index.js"
|
|
12
|
+
},
|
|
6
13
|
"types": "src/plugin-content-docs.d.ts",
|
|
7
14
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"watch": "tsc --watch"
|
|
15
|
+
"build": "tsc --build",
|
|
16
|
+
"watch": "tsc --build --watch"
|
|
10
17
|
},
|
|
11
18
|
"publishConfig": {
|
|
12
19
|
"access": "public"
|
|
@@ -17,41 +24,39 @@
|
|
|
17
24
|
"directory": "packages/docusaurus-plugin-content-docs"
|
|
18
25
|
},
|
|
19
26
|
"license": "MIT",
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.1ec2c95e3",
|
|
22
|
-
"@types/js-yaml": "^4.0.0",
|
|
23
|
-
"@types/picomatch": "^2.2.1",
|
|
24
|
-
"commander": "^5.1.0",
|
|
25
|
-
"picomatch": "^2.1.1"
|
|
26
|
-
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
29
|
-
"@docusaurus/
|
|
30
|
-
"@docusaurus/
|
|
31
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
32
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
33
|
-
"chalk": "^4.1.1",
|
|
28
|
+
"@docusaurus/core": "2.0.0-beta.21",
|
|
29
|
+
"@docusaurus/logger": "2.0.0-beta.21",
|
|
30
|
+
"@docusaurus/mdx-loader": "2.0.0-beta.21",
|
|
31
|
+
"@docusaurus/utils": "2.0.0-beta.21",
|
|
32
|
+
"@docusaurus/utils-validation": "2.0.0-beta.21",
|
|
34
33
|
"combine-promises": "^1.1.0",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"import-fresh": "^3.2.2",
|
|
40
|
-
"js-yaml": "^4.0.0",
|
|
41
|
-
"loader-utils": "^1.2.3",
|
|
42
|
-
"lodash": "^4.17.20",
|
|
34
|
+
"fs-extra": "^10.1.0",
|
|
35
|
+
"import-fresh": "^3.3.0",
|
|
36
|
+
"js-yaml": "^4.1.0",
|
|
37
|
+
"lodash": "^4.17.21",
|
|
43
38
|
"remark-admonitions": "^1.2.1",
|
|
44
|
-
"
|
|
45
|
-
"tslib": "^2.2.0",
|
|
39
|
+
"tslib": "^2.4.0",
|
|
46
40
|
"utility-types": "^3.10.0",
|
|
47
|
-
"webpack": "^5.
|
|
41
|
+
"webpack": "^5.72.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.21",
|
|
45
|
+
"@docusaurus/types": "2.0.0-beta.21",
|
|
46
|
+
"@types/js-yaml": "^4.0.5",
|
|
47
|
+
"@types/picomatch": "^2.3.0",
|
|
48
|
+
"commander": "^5.1.0",
|
|
49
|
+
"escape-string-regexp": "^4.0.0",
|
|
50
|
+
"picomatch": "^2.3.1",
|
|
51
|
+
"shelljs": "^0.8.5",
|
|
52
|
+
"utility-types": "^3.10.0"
|
|
48
53
|
},
|
|
49
54
|
"peerDependencies": {
|
|
50
55
|
"react": "^16.8.4 || ^17.0.0",
|
|
51
56
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
52
57
|
},
|
|
53
58
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
59
|
+
"node": ">=16.14"
|
|
55
60
|
},
|
|
56
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "69ac49fc6909517f13615ee40290c4bd00c39df4"
|
|
57
62
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 SidebarsUtils, toNavigationLink} from './sidebars/utils';
|
|
9
|
+
import {createDocsByIdIndex} from './docs';
|
|
10
|
+
import type {
|
|
11
|
+
CategoryGeneratedIndexMetadata,
|
|
12
|
+
DocMetadataBase,
|
|
13
|
+
} from '@docusaurus/plugin-content-docs';
|
|
14
|
+
import type {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
|
|
15
|
+
|
|
16
|
+
function getCategoryGeneratedIndexMetadata({
|
|
17
|
+
category,
|
|
18
|
+
sidebarsUtils,
|
|
19
|
+
docsById,
|
|
20
|
+
}: {
|
|
21
|
+
category: SidebarItemCategoryWithGeneratedIndex;
|
|
22
|
+
sidebarsUtils: SidebarsUtils;
|
|
23
|
+
docsById: {[docId: string]: DocMetadataBase};
|
|
24
|
+
}): CategoryGeneratedIndexMetadata {
|
|
25
|
+
const {sidebarName, previous, next} =
|
|
26
|
+
sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
|
27
|
+
return {
|
|
28
|
+
title: category.link.title ?? category.label,
|
|
29
|
+
description: category.link.description,
|
|
30
|
+
image: category.link.image,
|
|
31
|
+
keywords: category.link.keywords,
|
|
32
|
+
slug: category.link.slug,
|
|
33
|
+
permalink: category.link.permalink,
|
|
34
|
+
sidebar: sidebarName!,
|
|
35
|
+
navigation: {
|
|
36
|
+
previous: toNavigationLink(previous, docsById),
|
|
37
|
+
next: toNavigationLink(next, docsById),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getCategoryGeneratedIndexMetadataList({
|
|
43
|
+
docs,
|
|
44
|
+
sidebarsUtils,
|
|
45
|
+
}: {
|
|
46
|
+
sidebarsUtils: SidebarsUtils;
|
|
47
|
+
docs: DocMetadataBase[];
|
|
48
|
+
}): CategoryGeneratedIndexMetadata[] {
|
|
49
|
+
const docsById = createDocsByIdIndex(docs);
|
|
50
|
+
|
|
51
|
+
const categoryGeneratedIndexItems =
|
|
52
|
+
sidebarsUtils.getCategoryGeneratedIndexList();
|
|
53
|
+
return categoryGeneratedIndexItems.map((category) =>
|
|
54
|
+
getCategoryGeneratedIndexMetadata({
|
|
55
|
+
category,
|
|
56
|
+
sidebarsUtils,
|
|
57
|
+
docsById,
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -5,22 +5,24 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
getVersionsFilePath,
|
|
10
|
-
getVersionedDocsDirPath,
|
|
11
|
-
getVersionedSidebarsDirPath,
|
|
12
|
-
} from './versions';
|
|
13
8
|
import fs from 'fs-extra';
|
|
14
9
|
import path from 'path';
|
|
10
|
+
import logger from '@docusaurus/logger';
|
|
11
|
+
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
|
15
12
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
getVersionsFilePath,
|
|
14
|
+
getVersionDocsDirPath,
|
|
15
|
+
getVersionSidebarsPath,
|
|
16
|
+
getDocsDirPathLocalized,
|
|
17
|
+
readVersionsFile,
|
|
18
|
+
} from './versions/files';
|
|
19
|
+
import {validateVersionName} from './versions/validation';
|
|
20
|
+
import {loadSidebarsFileUnsafe} from './sidebars';
|
|
21
|
+
import {CURRENT_VERSION_NAME} from './constants';
|
|
22
|
+
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
23
|
+
import type {LoadContext} from '@docusaurus/types';
|
|
24
|
+
|
|
25
|
+
async function createVersionedSidebarFile({
|
|
24
26
|
siteDir,
|
|
25
27
|
pluginId,
|
|
26
28
|
sidebarPath,
|
|
@@ -32,107 +34,43 @@ function createVersionedSidebarFile({
|
|
|
32
34
|
version: string;
|
|
33
35
|
}) {
|
|
34
36
|
// Load current sidebar and create a new versioned sidebars file (if needed).
|
|
35
|
-
|
|
37
|
+
// Note: we don't need the sidebars file to be normalized: it's ok to let
|
|
38
|
+
// plugin option changes to impact older, versioned sidebars
|
|
39
|
+
// We don't validate here, assuming the user has already built the version
|
|
40
|
+
const sidebars = await loadSidebarsFileUnsafe(sidebarPath);
|
|
36
41
|
|
|
37
|
-
// Do not create a useless versioned sidebars file if sidebars file is empty
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
// Do not create a useless versioned sidebars file if sidebars file is empty
|
|
43
|
+
// or sidebars are disabled/false)
|
|
44
|
+
const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
|
|
40
45
|
|
|
41
46
|
if (shouldCreateVersionedSidebarFile) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const normalizeItem = (
|
|
46
|
-
item: UnprocessedSidebarItem,
|
|
47
|
-
): UnprocessedSidebarItem => {
|
|
48
|
-
switch (item.type) {
|
|
49
|
-
case 'category':
|
|
50
|
-
return {...item, items: item.items.map(normalizeItem)};
|
|
51
|
-
case 'ref':
|
|
52
|
-
case 'doc':
|
|
53
|
-
return {
|
|
54
|
-
type: item.type,
|
|
55
|
-
id: `version-${version}/${item.id}`,
|
|
56
|
-
};
|
|
57
|
-
default:
|
|
58
|
-
return item;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const versionedSidebar: UnprocessedSidebars = Object.entries(
|
|
63
|
-
loadedSidebars,
|
|
64
|
-
).reduce((acc: UnprocessedSidebars, [sidebarId, sidebarItems]) => {
|
|
65
|
-
const newVersionedSidebarId = `version-${version}/${sidebarId}`;
|
|
66
|
-
acc[newVersionedSidebarId] = sidebarItems.map(normalizeItem);
|
|
67
|
-
return acc;
|
|
68
|
-
}, {});
|
|
69
|
-
|
|
70
|
-
const versionedSidebarsDir = getVersionedSidebarsDirPath(siteDir, pluginId);
|
|
71
|
-
const newSidebarFile = path.join(
|
|
72
|
-
versionedSidebarsDir,
|
|
73
|
-
`version-${version}-sidebars.json`,
|
|
74
|
-
);
|
|
75
|
-
fs.ensureDirSync(path.dirname(newSidebarFile));
|
|
76
|
-
fs.writeFileSync(
|
|
77
|
-
newSidebarFile,
|
|
78
|
-
`${JSON.stringify(versionedSidebar, null, 2)}\n`,
|
|
47
|
+
await fs.outputFile(
|
|
48
|
+
getVersionSidebarsPath(siteDir, pluginId, version),
|
|
49
|
+
`${JSON.stringify(sidebars, null, 2)}\n`,
|
|
79
50
|
'utf8',
|
|
80
51
|
);
|
|
81
52
|
}
|
|
82
53
|
}
|
|
83
54
|
|
|
84
55
|
// Tests depend on non-default export for mocking.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
siteDir:
|
|
89
|
-
|
|
90
|
-
options: PathOptions,
|
|
91
|
-
): void {
|
|
56
|
+
export async function cliDocsVersionCommand(
|
|
57
|
+
version: unknown,
|
|
58
|
+
{id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
|
|
59
|
+
{siteDir, i18n}: LoadContext,
|
|
60
|
+
): Promise<void> {
|
|
92
61
|
// It wouldn't be very user-friendly to show a [default] log prefix,
|
|
93
62
|
// so we use [docs] instead of [default]
|
|
94
63
|
const pluginIdLogPrefix =
|
|
95
64
|
pluginId === DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
|
|
96
65
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
66
|
+
try {
|
|
67
|
+
validateVersionName(version);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
logger.info`${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
|
|
70
|
+
throw err;
|
|
101
71
|
}
|
|
102
72
|
|
|
103
|
-
|
|
104
|
-
throw new Error(
|
|
105
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (version.length > 32) {
|
|
110
|
-
throw new Error(
|
|
111
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Since we are going to create `version-${version}` folder, we need to make
|
|
116
|
-
// sure it's a valid pathname.
|
|
117
|
-
// eslint-disable-next-line no-control-regex
|
|
118
|
-
if (/[<>:"|?*\x00-\x1F]/g.test(version)) {
|
|
119
|
-
throw new Error(
|
|
120
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (/^\.\.?$/.test(version)) {
|
|
125
|
-
throw new Error(
|
|
126
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0.`,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Load existing versions.
|
|
131
|
-
let versions = [];
|
|
132
|
-
const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
|
|
133
|
-
if (fs.existsSync(versionsJSONFile)) {
|
|
134
|
-
versions = JSON.parse(fs.readFileSync(versionsJSONFile, 'utf8'));
|
|
135
|
-
}
|
|
73
|
+
const versions = (await readVersionsFile(siteDir, pluginId)) ?? [];
|
|
136
74
|
|
|
137
75
|
// Check if version already exists.
|
|
138
76
|
if (versions.includes(version)) {
|
|
@@ -141,30 +79,63 @@ export function cliDocsVersionCommand(
|
|
|
141
79
|
);
|
|
142
80
|
}
|
|
143
81
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// Copy docs files.
|
|
147
|
-
const docsDir = path.join(siteDir, docsPath);
|
|
148
|
-
|
|
149
|
-
if (fs.existsSync(docsDir) && fs.readdirSync(docsDir).length > 0) {
|
|
150
|
-
const versionedDir = getVersionedDocsDirPath(siteDir, pluginId);
|
|
151
|
-
const newVersionDir = path.join(versionedDir, `version-${version}`);
|
|
152
|
-
fs.copySync(docsDir, newVersionDir);
|
|
153
|
-
} else {
|
|
154
|
-
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
|
|
82
|
+
if (i18n.locales.length > 1) {
|
|
83
|
+
logger.info`Versioned docs will be created for the following locales: name=${i18n.locales}`;
|
|
155
84
|
}
|
|
156
85
|
|
|
157
|
-
|
|
86
|
+
await Promise.all(
|
|
87
|
+
i18n.locales.map(async (locale) => {
|
|
88
|
+
// Copy docs files.
|
|
89
|
+
const docsDir =
|
|
90
|
+
locale === i18n.defaultLocale
|
|
91
|
+
? path.resolve(siteDir, docsPath)
|
|
92
|
+
: getDocsDirPathLocalized({
|
|
93
|
+
siteDir,
|
|
94
|
+
locale,
|
|
95
|
+
pluginId,
|
|
96
|
+
versionName: CURRENT_VERSION_NAME,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
!(await fs.pathExists(docsDir)) ||
|
|
101
|
+
(await fs.readdir(docsDir)).length === 0
|
|
102
|
+
) {
|
|
103
|
+
if (locale === i18n.defaultLocale) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
logger.interpolate`${pluginIdLogPrefix}: no docs found in path=${docsDir}.`,
|
|
106
|
+
);
|
|
107
|
+
} else {
|
|
108
|
+
logger.warn`${pluginIdLogPrefix}: no docs found in path=${docsDir}. Skipping.`;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const newVersionDir =
|
|
114
|
+
locale === i18n.defaultLocale
|
|
115
|
+
? getVersionDocsDirPath(siteDir, pluginId, version)
|
|
116
|
+
: getDocsDirPathLocalized({
|
|
117
|
+
siteDir,
|
|
118
|
+
locale,
|
|
119
|
+
pluginId,
|
|
120
|
+
versionName: version,
|
|
121
|
+
});
|
|
122
|
+
await fs.copy(docsDir, newVersionDir);
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
await createVersionedSidebarFile({
|
|
158
127
|
siteDir,
|
|
159
128
|
pluginId,
|
|
160
129
|
version,
|
|
161
|
-
sidebarPath
|
|
130
|
+
sidebarPath,
|
|
162
131
|
});
|
|
163
132
|
|
|
164
133
|
// Update versions.json file.
|
|
165
134
|
versions.unshift(version);
|
|
166
|
-
fs.
|
|
167
|
-
|
|
135
|
+
await fs.outputFile(
|
|
136
|
+
getVersionsFilePath(siteDir, pluginId),
|
|
137
|
+
`${JSON.stringify(versions, null, 2)}\n`,
|
|
138
|
+
);
|
|
168
139
|
|
|
169
|
-
|
|
140
|
+
logger.success`name=${pluginIdLogPrefix}: version name=${version} created!`;
|
|
170
141
|
}
|