@docusaurus/plugin-content-docs 2.0.0-beta.ff31de0ff → 2.0.1
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 +62 -72
- package/lib/client/docsClientUtils.d.ts +9 -28
- package/lib/client/docsClientUtils.js +35 -51
- package/lib/client/index.d.ts +81 -0
- package/lib/client/index.js +67 -0
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +35 -8
- package/lib/docs.js +211 -78
- package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js → lib/frontMatter.d.ts} +4 -10
- package/lib/frontMatter.js +53 -0
- package/lib/globalData.d.ts +3 -3
- package/lib/globalData.js +35 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +137 -146
- 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 +7 -4
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/numberPrefix.js +16 -21
- package/lib/options.d.ts +3 -5
- package/lib/options.js +57 -29
- package/lib/props.d.ts +7 -2
- package/lib/props.js +87 -16
- 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 +25 -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 +59 -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 +183 -0
- package/{types.d.ts → lib/sidebars/types.js} +2 -7
- package/lib/sidebars/utils.d.ts +55 -0
- package/lib/sidebars/utils.js +259 -0
- package/lib/sidebars/validation.d.ts +11 -0
- package/lib/sidebars/validation.js +143 -0
- package/lib/slug.d.ts +5 -4
- package/lib/slug.js +29 -19
- 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 +100 -93
- package/lib/types.d.ts +13 -172
- package/lib/versions/files.d.ts +50 -0
- package/lib/versions/files.js +141 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +154 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +44 -29
- package/src/categoryGeneratedIndex.ts +60 -0
- package/src/cli.ts +94 -114
- package/src/client/docsClientUtils.ts +47 -84
- package/src/client/index.ts +158 -0
- package/src/constants.ts +4 -2
- package/src/docs.ts +294 -78
- package/src/frontMatter.ts +63 -0
- package/src/globalData.ts +57 -7
- package/src/index.ts +200 -204
- package/src/lastUpdate.ts +27 -34
- package/src/markdown/index.ts +10 -16
- package/src/markdown/linkify.ts +8 -5
- package/src/numberPrefix.ts +19 -26
- package/src/options.ts +61 -43
- package/src/plugin-content-docs.d.ts +575 -78
- package/src/props.ts +128 -23
- package/src/routes.ts +159 -0
- package/src/server-export.ts +26 -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 +91 -0
- package/src/sidebars/postProcessor.ts +112 -0
- package/src/sidebars/processor.ts +123 -0
- package/src/sidebars/types.ts +280 -0
- package/src/sidebars/utils.ts +393 -0
- package/src/sidebars/validation.ts +179 -0
- package/src/slug.ts +42 -23
- package/src/tags.ts +20 -0
- package/src/translations.ts +155 -124
- package/src/types.ts +17 -234
- package/src/versions/files.ts +216 -0
- package/src/versions/index.ts +246 -0
- package/src/versions/validation.ts +115 -0
- package/lib/.tsbuildinfo +0 -4673
- package/lib/docFrontMatter.d.ts +0 -21
- package/lib/docFrontMatter.js +0 -33
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -42
- package/lib/sidebars.js +0 -309
- package/lib/theme/hooks/useDocs.d.ts +0 -20
- package/lib/theme/hooks/useDocs.js +0 -72
- package/lib/versions.d.ts +0 -16
- package/lib/versions.js +0 -287
- 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 -67
- package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -52
- 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/docusaurus.config.js +0 -14
- package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
- 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 -1907
- 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 -204
- package/src/__tests__/docs.test.ts +0 -875
- package/src/__tests__/index.test.ts +0 -1831
- package/src/__tests__/lastUpdate.test.ts +0 -68
- package/src/__tests__/numberPrefix.test.ts +0 -199
- package/src/__tests__/options.test.ts +0 -232
- package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
- package/src/__tests__/sidebars.test.ts +0 -638
- package/src/__tests__/slug.test.ts +0 -109
- package/src/__tests__/translations.test.ts +0 -159
- package/src/__tests__/versions.test.ts +0 -718
- package/src/client/__tests__/docsClientUtils.test.ts +0 -372
- package/src/docFrontMatter.ts +0 -53
- 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 -489
- package/src/theme/hooks/useDocs.ts +0 -99
- package/src/versions.ts +0 -511
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,141 @@
|
|
|
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.getVersionMetadataPaths = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
const validation_1 = require("./validation");
|
|
16
|
+
/** Add a prefix like `community_version-1.0.0`. No-op for default instance. */
|
|
17
|
+
function addPluginIdPrefix(fileOrDir, pluginId) {
|
|
18
|
+
return pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
19
|
+
? fileOrDir
|
|
20
|
+
: `${pluginId}_${fileOrDir}`;
|
|
21
|
+
}
|
|
22
|
+
/** `[siteDir]/community_versioned_docs/version-1.0.0` */
|
|
23
|
+
function getVersionDocsDirPath(siteDir, pluginId, versionName) {
|
|
24
|
+
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_DOCS_DIR, pluginId), `version-${versionName}`);
|
|
25
|
+
}
|
|
26
|
+
exports.getVersionDocsDirPath = getVersionDocsDirPath;
|
|
27
|
+
/** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
|
|
28
|
+
function getVersionSidebarsPath(siteDir, pluginId, versionName) {
|
|
29
|
+
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_SIDEBARS_DIR, pluginId), `version-${versionName}-sidebars.json`);
|
|
30
|
+
}
|
|
31
|
+
exports.getVersionSidebarsPath = getVersionSidebarsPath;
|
|
32
|
+
function getDocsDirPathLocalized({ localizationDir, pluginId, versionName, }) {
|
|
33
|
+
return (0, utils_1.getPluginI18nPath)({
|
|
34
|
+
localizationDir,
|
|
35
|
+
pluginName: 'docusaurus-plugin-content-docs',
|
|
36
|
+
pluginId,
|
|
37
|
+
subPaths: [
|
|
38
|
+
versionName === constants_1.CURRENT_VERSION_NAME
|
|
39
|
+
? constants_1.CURRENT_VERSION_NAME
|
|
40
|
+
: `version-${versionName}`,
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.getDocsDirPathLocalized = getDocsDirPathLocalized;
|
|
45
|
+
/** `community` => `[siteDir]/community_versions.json` */
|
|
46
|
+
function getVersionsFilePath(siteDir, pluginId) {
|
|
47
|
+
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONS_JSON_FILE, pluginId));
|
|
48
|
+
}
|
|
49
|
+
exports.getVersionsFilePath = getVersionsFilePath;
|
|
50
|
+
/**
|
|
51
|
+
* Reads the plugin's respective `versions.json` file, and returns its content.
|
|
52
|
+
*
|
|
53
|
+
* @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
|
|
54
|
+
* array of valid version names.
|
|
55
|
+
*/
|
|
56
|
+
async function readVersionsFile(siteDir, pluginId) {
|
|
57
|
+
const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
|
|
58
|
+
if (await fs_extra_1.default.pathExists(versionsFilePath)) {
|
|
59
|
+
const content = await fs_extra_1.default.readJSON(versionsFilePath);
|
|
60
|
+
(0, validation_1.validateVersionNames)(content);
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
exports.readVersionsFile = readVersionsFile;
|
|
66
|
+
/**
|
|
67
|
+
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
68
|
+
*
|
|
69
|
+
* - If `disableVersioning` is turned on, it will return `["current"]` (requires
|
|
70
|
+
* `includeCurrentVersion` to be true);
|
|
71
|
+
* - If `includeCurrentVersion` is turned on, "current" will be inserted at the
|
|
72
|
+
* beginning, if not already there.
|
|
73
|
+
*
|
|
74
|
+
* You need to use {@link filterVersions} after this.
|
|
75
|
+
*
|
|
76
|
+
* @throws Throws an error if `disableVersioning: true` but `versions.json`
|
|
77
|
+
* doesn't exist (i.e. site is not versioned)
|
|
78
|
+
* @throws Throws an error if versions list is empty (empty `versions.json` or
|
|
79
|
+
* `disableVersioning` is true, and not including current version)
|
|
80
|
+
*/
|
|
81
|
+
async function readVersionNames(siteDir, options) {
|
|
82
|
+
const versionFileContent = await readVersionsFile(siteDir, options.id);
|
|
83
|
+
if (!versionFileContent && options.disableVersioning) {
|
|
84
|
+
throw new Error(`Docs: using "disableVersioning: true" option on a non-versioned site does not make sense.`);
|
|
85
|
+
}
|
|
86
|
+
const versions = options.disableVersioning ? [] : versionFileContent ?? [];
|
|
87
|
+
// We add the current version at the beginning, unless:
|
|
88
|
+
// - user don't want to; or
|
|
89
|
+
// - it's already been explicitly added to versions.json
|
|
90
|
+
if (options.includeCurrentVersion &&
|
|
91
|
+
!versions.includes(constants_1.CURRENT_VERSION_NAME)) {
|
|
92
|
+
versions.unshift(constants_1.CURRENT_VERSION_NAME);
|
|
93
|
+
}
|
|
94
|
+
if (versions.length === 0) {
|
|
95
|
+
throw new Error(`It is not possible to use docs without any version. No version is included because you have requested to not include ${path_1.default.resolve(options.path)} through "includeCurrentVersion: false", while ${options.disableVersioning
|
|
96
|
+
? 'versioning is disabled with "disableVersioning: true"'
|
|
97
|
+
: `the versions file is empty/non-existent`}.`);
|
|
98
|
+
}
|
|
99
|
+
return versions;
|
|
100
|
+
}
|
|
101
|
+
exports.readVersionNames = readVersionNames;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the path-related version metadata.
|
|
104
|
+
*
|
|
105
|
+
* @throws Throws if the resolved docs folder or sidebars file doesn't exist.
|
|
106
|
+
* Does not throw if a versioned sidebar is missing (since we don't create empty
|
|
107
|
+
* files).
|
|
108
|
+
*/
|
|
109
|
+
async function getVersionMetadataPaths({ versionName, context, options, }) {
|
|
110
|
+
const isCurrent = versionName === constants_1.CURRENT_VERSION_NAME;
|
|
111
|
+
const contentPathLocalized = getDocsDirPathLocalized({
|
|
112
|
+
localizationDir: context.localizationDir,
|
|
113
|
+
pluginId: options.id,
|
|
114
|
+
versionName,
|
|
115
|
+
});
|
|
116
|
+
const contentPath = isCurrent
|
|
117
|
+
? path_1.default.resolve(context.siteDir, options.path)
|
|
118
|
+
: getVersionDocsDirPath(context.siteDir, options.id, versionName);
|
|
119
|
+
const sidebarFilePath = isCurrent
|
|
120
|
+
? options.sidebarPath
|
|
121
|
+
: getVersionSidebarsPath(context.siteDir, options.id, versionName);
|
|
122
|
+
if (!(await fs_extra_1.default.pathExists(contentPath))) {
|
|
123
|
+
throw new Error(`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path_1.default.relative(context.siteDir, contentPath)}.`);
|
|
124
|
+
}
|
|
125
|
+
// If the current version defines a path to a sidebar file that does not
|
|
126
|
+
// exist, we throw! Note: for versioned sidebars, the file may not exist (as
|
|
127
|
+
// we prefer to not create it rather than to create an empty file)
|
|
128
|
+
// See https://github.com/facebook/docusaurus/issues/3366
|
|
129
|
+
// See https://github.com/facebook/docusaurus/pull/4775
|
|
130
|
+
if (versionName === constants_1.CURRENT_VERSION_NAME &&
|
|
131
|
+
typeof sidebarFilePath === 'string' &&
|
|
132
|
+
!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
|
|
133
|
+
throw new Error(`The path to the sidebar file does not exist at "${path_1.default.relative(context.siteDir, sidebarFilePath)}".
|
|
134
|
+
Please set the docs "sidebarPath" field in your config file to:
|
|
135
|
+
- a sidebars path that exists
|
|
136
|
+
- false: to disable the sidebar
|
|
137
|
+
- undefined: for Docusaurus to generate it automatically`);
|
|
138
|
+
}
|
|
139
|
+
return { contentPath, contentPathLocalized, sidebarFilePath };
|
|
140
|
+
}
|
|
141
|
+
exports.getVersionMetadataPaths = getVersionMetadataPaths;
|
|
@@ -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,154 @@
|
|
|
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
|
+
localizationDir: context.localizationDir,
|
|
26
|
+
versionName: constants_1.CURRENT_VERSION_NAME,
|
|
27
|
+
pluginId: options.id,
|
|
28
|
+
})
|
|
29
|
+
: contentPathLocalized;
|
|
30
|
+
const versionPathSegment = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPath)));
|
|
31
|
+
const versionPathSegmentLocalized = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPathLocalized)));
|
|
32
|
+
const editUrl = (0, utils_1.normalizeUrl)([options.editUrl, versionPathSegment]);
|
|
33
|
+
const editUrlLocalized = (0, utils_1.normalizeUrl)([
|
|
34
|
+
options.editUrl,
|
|
35
|
+
versionPathSegmentLocalized,
|
|
36
|
+
]);
|
|
37
|
+
return { editUrl, editUrlLocalized };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The default version banner depends on the version's relative position to the
|
|
41
|
+
* latest version. More recent ones are "unreleased", and older ones are
|
|
42
|
+
* "unmaintained".
|
|
43
|
+
*/
|
|
44
|
+
function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }) {
|
|
45
|
+
// Current version: good, no banner
|
|
46
|
+
if (versionName === lastVersionName) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// Upcoming versions: unreleased banner
|
|
50
|
+
if (versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)) {
|
|
51
|
+
return 'unreleased';
|
|
52
|
+
}
|
|
53
|
+
// Older versions: display unmaintained banner
|
|
54
|
+
return 'unmaintained';
|
|
55
|
+
}
|
|
56
|
+
exports.getDefaultVersionBanner = getDefaultVersionBanner;
|
|
57
|
+
function getVersionBanner(context) {
|
|
58
|
+
const { versionName, options } = context;
|
|
59
|
+
const versionBannerOption = options.versions[versionName]?.banner;
|
|
60
|
+
if (versionBannerOption) {
|
|
61
|
+
return versionBannerOption === 'none' ? null : versionBannerOption;
|
|
62
|
+
}
|
|
63
|
+
return getDefaultVersionBanner(context);
|
|
64
|
+
}
|
|
65
|
+
exports.getVersionBanner = getVersionBanner;
|
|
66
|
+
function getVersionBadge({ versionName, versionNames, options, }) {
|
|
67
|
+
// If site is not versioned or only one version is included
|
|
68
|
+
// we don't show the version badge by default
|
|
69
|
+
// See https://github.com/facebook/docusaurus/issues/3362
|
|
70
|
+
const defaultVersionBadge = versionNames.length !== 1;
|
|
71
|
+
return options.versions[versionName]?.badge ?? defaultVersionBadge;
|
|
72
|
+
}
|
|
73
|
+
exports.getVersionBadge = getVersionBadge;
|
|
74
|
+
function getVersionClassName({ versionName, options, }) {
|
|
75
|
+
const defaultVersionClassName = `docs-version-${versionName}`;
|
|
76
|
+
return options.versions[versionName]?.className ?? defaultVersionClassName;
|
|
77
|
+
}
|
|
78
|
+
function getVersionLabel({ versionName, options, }) {
|
|
79
|
+
const defaultVersionLabel = versionName === constants_1.CURRENT_VERSION_NAME ? 'Next' : versionName;
|
|
80
|
+
return options.versions[versionName]?.label ?? defaultVersionLabel;
|
|
81
|
+
}
|
|
82
|
+
function getVersionPathPart({ versionName, options, lastVersionName, }) {
|
|
83
|
+
function getDefaultVersionPathPart() {
|
|
84
|
+
if (versionName === lastVersionName) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
return versionName === constants_1.CURRENT_VERSION_NAME ? 'next' : versionName;
|
|
88
|
+
}
|
|
89
|
+
return options.versions[versionName]?.path ?? getDefaultVersionPathPart();
|
|
90
|
+
}
|
|
91
|
+
async function createVersionMetadata(context) {
|
|
92
|
+
const { versionName, lastVersionName, options, context: loadContext } = context;
|
|
93
|
+
const { sidebarFilePath, contentPath, contentPathLocalized } = await (0, files_1.getVersionMetadataPaths)(context);
|
|
94
|
+
const versionPathPart = getVersionPathPart(context);
|
|
95
|
+
const routePath = (0, utils_1.normalizeUrl)([
|
|
96
|
+
loadContext.baseUrl,
|
|
97
|
+
options.routeBasePath,
|
|
98
|
+
versionPathPart,
|
|
99
|
+
]);
|
|
100
|
+
const versionEditUrls = getVersionEditUrls({
|
|
101
|
+
contentPath,
|
|
102
|
+
contentPathLocalized,
|
|
103
|
+
context: loadContext,
|
|
104
|
+
options,
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
versionName,
|
|
108
|
+
label: getVersionLabel(context),
|
|
109
|
+
banner: getVersionBanner(context),
|
|
110
|
+
badge: getVersionBadge(context),
|
|
111
|
+
className: getVersionClassName(context),
|
|
112
|
+
path: routePath,
|
|
113
|
+
tagsPath: (0, utils_1.normalizeUrl)([routePath, options.tagsBasePath]),
|
|
114
|
+
...versionEditUrls,
|
|
115
|
+
isLast: versionName === lastVersionName,
|
|
116
|
+
routePriority: versionPathPart === '' ? -1 : undefined,
|
|
117
|
+
sidebarFilePath,
|
|
118
|
+
contentPath,
|
|
119
|
+
contentPathLocalized,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Filter versions according to provided options (i.e. `onlyIncludeVersions`).
|
|
124
|
+
*
|
|
125
|
+
* Note: we preserve the order in which versions are provided; the order of the
|
|
126
|
+
* `onlyIncludeVersions` array does not matter
|
|
127
|
+
*/
|
|
128
|
+
function filterVersions(versionNamesUnfiltered, options) {
|
|
129
|
+
if (options.onlyIncludeVersions) {
|
|
130
|
+
return versionNamesUnfiltered.filter((name) => options.onlyIncludeVersions.includes(name));
|
|
131
|
+
}
|
|
132
|
+
return versionNamesUnfiltered;
|
|
133
|
+
}
|
|
134
|
+
exports.filterVersions = filterVersions;
|
|
135
|
+
function getLastVersionName({ versionNames, options, }) {
|
|
136
|
+
return (options.lastVersion ??
|
|
137
|
+
versionNames.find((name) => name !== constants_1.CURRENT_VERSION_NAME) ??
|
|
138
|
+
constants_1.CURRENT_VERSION_NAME);
|
|
139
|
+
}
|
|
140
|
+
async function readVersionsMetadata({ context, options, }) {
|
|
141
|
+
const allVersionNames = await (0, files_1.readVersionNames)(context.siteDir, options);
|
|
142
|
+
(0, validation_1.validateVersionsOptions)(allVersionNames, options);
|
|
143
|
+
const versionNames = filterVersions(allVersionNames, options);
|
|
144
|
+
const lastVersionName = getLastVersionName({ versionNames, options });
|
|
145
|
+
const versionsMetadata = await Promise.all(versionNames.map((versionName) => createVersionMetadata({
|
|
146
|
+
versionName,
|
|
147
|
+
versionNames,
|
|
148
|
+
lastVersionName,
|
|
149
|
+
context,
|
|
150
|
+
options,
|
|
151
|
+
})));
|
|
152
|
+
return versionsMetadata;
|
|
153
|
+
}
|
|
154
|
+
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,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
"./src/*": "./src/*",
|
|
9
|
+
"./client": {
|
|
10
|
+
"type": "./lib/client/index.d.ts",
|
|
11
|
+
"default": "./lib/client/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./server": {
|
|
14
|
+
"type": "./lib/server-export.d.ts",
|
|
15
|
+
"default": "./lib/server-export.js"
|
|
16
|
+
},
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./src/plugin-content-docs.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
6
22
|
"types": "src/plugin-content-docs.d.ts",
|
|
7
23
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"watch": "tsc --watch"
|
|
24
|
+
"build": "tsc --build",
|
|
25
|
+
"watch": "tsc --build --watch"
|
|
10
26
|
},
|
|
11
27
|
"publishConfig": {
|
|
12
28
|
"access": "public"
|
|
@@ -17,40 +33,39 @@
|
|
|
17
33
|
"directory": "packages/docusaurus-plugin-content-docs"
|
|
18
34
|
},
|
|
19
35
|
"license": "MIT",
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.ff31de0ff",
|
|
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
36
|
"dependencies": {
|
|
28
|
-
"@docusaurus/core": "2.0.
|
|
29
|
-
"@docusaurus/
|
|
30
|
-
"@docusaurus/
|
|
31
|
-
"@docusaurus/
|
|
32
|
-
"@docusaurus/
|
|
33
|
-
"
|
|
37
|
+
"@docusaurus/core": "2.0.1",
|
|
38
|
+
"@docusaurus/logger": "2.0.1",
|
|
39
|
+
"@docusaurus/mdx-loader": "2.0.1",
|
|
40
|
+
"@docusaurus/module-type-aliases": "2.0.1",
|
|
41
|
+
"@docusaurus/types": "2.0.1",
|
|
42
|
+
"@docusaurus/utils": "2.0.1",
|
|
43
|
+
"@docusaurus/utils-validation": "2.0.1",
|
|
44
|
+
"@types/react-router-config": "^5.0.6",
|
|
34
45
|
"combine-promises": "^1.1.0",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"loader-utils": "^1.2.3",
|
|
41
|
-
"lodash": "^4.17.20",
|
|
42
|
-
"remark-admonitions": "^1.2.1",
|
|
43
|
-
"shelljs": "^0.8.4",
|
|
44
|
-
"tslib": "^2.2.0",
|
|
46
|
+
"fs-extra": "^10.1.0",
|
|
47
|
+
"import-fresh": "^3.3.0",
|
|
48
|
+
"js-yaml": "^4.1.0",
|
|
49
|
+
"lodash": "^4.17.21",
|
|
50
|
+
"tslib": "^2.4.0",
|
|
45
51
|
"utility-types": "^3.10.0",
|
|
46
|
-
"webpack": "^5.
|
|
52
|
+
"webpack": "^5.73.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@docusaurus/types": "2.0.0-beta.21",
|
|
56
|
+
"@types/js-yaml": "^4.0.5",
|
|
57
|
+
"@types/picomatch": "^2.3.0",
|
|
58
|
+
"commander": "^5.1.0",
|
|
59
|
+
"escape-string-regexp": "^4.0.0",
|
|
60
|
+
"picomatch": "^2.3.1",
|
|
61
|
+
"shelljs": "^0.8.5"
|
|
47
62
|
},
|
|
48
63
|
"peerDependencies": {
|
|
49
64
|
"react": "^16.8.4 || ^17.0.0",
|
|
50
65
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
51
66
|
},
|
|
52
67
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
68
|
+
"node": ">=16.14"
|
|
54
69
|
},
|
|
55
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "1ddee1c29cabf9bb52e4d78af6ebfaaabb1bc1f9"
|
|
56
71
|
}
|
|
@@ -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
|
+
}
|