@docusaurus/plugin-content-docs 3.3.2 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/categoryGeneratedIndex.d.ts +0 -1
- package/lib/categoryGeneratedIndex.js +1 -2
- package/lib/cli.d.ts +0 -1
- package/lib/cli.js +1 -2
- package/lib/client/doc.d.ts +29 -0
- package/lib/client/doc.js +47 -0
- package/lib/client/docSidebarItemsExpandedState.d.ts +30 -0
- package/lib/client/docSidebarItemsExpandedState.js +27 -0
- package/lib/client/docsClientUtils.js +16 -8
- package/lib/client/docsPreferredVersion.d.ts +29 -0
- package/lib/client/docsPreferredVersion.js +124 -0
- package/lib/client/docsSearch.d.ts +19 -0
- package/lib/client/docsSearch.js +39 -0
- package/lib/{markdown/linkify.d.ts → client/docsSearch.test.d.ts} +1 -2
- package/lib/client/docsSearch.test.js +12 -0
- package/lib/client/docsSidebar.d.ts +25 -0
- package/lib/client/docsSidebar.js +29 -0
- package/lib/client/docsUtils.d.ts +106 -0
- package/lib/client/docsUtils.js +273 -0
- package/lib/client/docsVersion.d.ts +19 -0
- package/lib/client/docsVersion.js +25 -0
- package/lib/client/index.d.ts +8 -0
- package/lib/client/index.js +8 -0
- package/lib/docs.d.ts +2 -1
- package/lib/docs.js +17 -10
- package/lib/frontMatter.d.ts +0 -1
- package/lib/frontMatter.js +2 -2
- package/lib/globalData.js +1 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +85 -55
- package/lib/numberPrefix.d.ts +0 -1
- package/lib/numberPrefix.js +3 -3
- package/lib/options.d.ts +0 -1
- package/lib/options.js +13 -2
- package/lib/props.d.ts +0 -1
- package/lib/props.js +7 -6
- package/lib/routes.d.ts +0 -1
- package/lib/routes.js +23 -7
- package/lib/sidebars/generator.js +3 -0
- package/lib/sidebars/index.d.ts +0 -1
- package/lib/sidebars/index.js +4 -4
- package/lib/sidebars/normalization.js +2 -3
- package/lib/sidebars/postProcessor.js +1 -2
- package/lib/sidebars/processor.js +1 -2
- package/lib/sidebars/types.d.ts +1 -1
- package/lib/sidebars/utils.d.ts +0 -1
- package/lib/sidebars/utils.js +13 -14
- package/lib/sidebars/validation.js +3 -3
- package/lib/slug.d.ts +0 -1
- package/lib/slug.js +1 -1
- package/lib/translations.d.ts +0 -1
- package/lib/translations.js +2 -3
- package/lib/types.d.ts +3 -14
- package/lib/versions/files.d.ts +0 -1
- package/lib/versions/files.js +7 -8
- package/lib/versions/index.d.ts +1 -1
- package/lib/versions/index.js +15 -8
- package/lib/versions/validation.d.ts +0 -1
- package/lib/versions/validation.js +3 -4
- package/package.json +11 -10
- package/src/client/doc.tsx +71 -0
- package/src/client/docSidebarItemsExpandedState.tsx +55 -0
- package/src/client/docsClientUtils.ts +17 -8
- package/src/client/docsPreferredVersion.tsx +248 -0
- package/src/client/docsSearch.test.ts +14 -0
- package/src/client/docsSearch.ts +57 -0
- package/src/client/docsSidebar.tsx +50 -0
- package/src/client/docsUtils.tsx +415 -0
- package/src/client/docsVersion.tsx +36 -0
- package/src/client/index.ts +39 -0
- package/src/docs.ts +14 -2
- package/src/index.ts +116 -73
- package/src/options.ts +12 -0
- package/src/plugin-content-docs.d.ts +4 -3
- package/src/props.ts +2 -0
- package/src/routes.ts +23 -4
- package/src/sidebars/generator.ts +3 -0
- package/src/sidebars/postProcessor.ts +1 -0
- package/src/sidebars/types.ts +1 -0
- package/src/sidebars/validation.ts +1 -0
- package/src/types.ts +2 -16
- package/src/versions/index.ts +18 -1
- package/lib/markdown/index.d.ts +0 -9
- package/lib/markdown/index.js +0 -16
- package/lib/markdown/linkify.js +0 -34
- package/lib/tags.d.ts +0 -10
- package/lib/tags.js +0 -28
- package/src/markdown/index.ts +0 -20
- package/src/markdown/linkify.ts +0 -47
- package/src/tags.ts +0 -27
package/lib/sidebars/utils.js
CHANGED
|
@@ -6,14 +6,25 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.isCategoriesShorthand = isCategoriesShorthand;
|
|
10
|
+
exports.transformSidebarItems = transformSidebarItems;
|
|
11
|
+
exports.collectSidebarDocItems = collectSidebarDocItems;
|
|
12
|
+
exports.collectSidebarCategories = collectSidebarCategories;
|
|
13
|
+
exports.collectSidebarLinks = collectSidebarLinks;
|
|
14
|
+
exports.collectSidebarRefs = collectSidebarRefs;
|
|
15
|
+
exports.collectSidebarDocIds = collectSidebarDocIds;
|
|
16
|
+
exports.collectSidebarNavigation = collectSidebarNavigation;
|
|
17
|
+
exports.collectSidebarsDocIds = collectSidebarsDocIds;
|
|
18
|
+
exports.collectSidebarsNavigations = collectSidebarsNavigations;
|
|
19
|
+
exports.createSidebarsUtils = createSidebarsUtils;
|
|
20
|
+
exports.toDocNavigationLink = toDocNavigationLink;
|
|
21
|
+
exports.toNavigationLink = toNavigationLink;
|
|
10
22
|
const tslib_1 = require("tslib");
|
|
11
23
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
24
|
const utils_1 = require("@docusaurus/utils");
|
|
13
25
|
function isCategoriesShorthand(item) {
|
|
14
26
|
return typeof item === 'object' && !item.type;
|
|
15
27
|
}
|
|
16
|
-
exports.isCategoriesShorthand = isCategoriesShorthand;
|
|
17
28
|
function transformSidebarItems(sidebar, updateFn) {
|
|
18
29
|
function transformRecursive(item) {
|
|
19
30
|
if (item.type === 'category') {
|
|
@@ -26,7 +37,6 @@ function transformSidebarItems(sidebar, updateFn) {
|
|
|
26
37
|
}
|
|
27
38
|
return sidebar.map(transformRecursive);
|
|
28
39
|
}
|
|
29
|
-
exports.transformSidebarItems = transformSidebarItems;
|
|
30
40
|
/**
|
|
31
41
|
* Flatten sidebar items into a single flat array (containing categories/docs on
|
|
32
42
|
* the same level). Order matters (useful for next/prev nav), top categories
|
|
@@ -46,19 +56,15 @@ function collectSidebarItemsOfType(type, sidebar) {
|
|
|
46
56
|
function collectSidebarDocItems(sidebar) {
|
|
47
57
|
return collectSidebarItemsOfType('doc', sidebar);
|
|
48
58
|
}
|
|
49
|
-
exports.collectSidebarDocItems = collectSidebarDocItems;
|
|
50
59
|
function collectSidebarCategories(sidebar) {
|
|
51
60
|
return collectSidebarItemsOfType('category', sidebar);
|
|
52
61
|
}
|
|
53
|
-
exports.collectSidebarCategories = collectSidebarCategories;
|
|
54
62
|
function collectSidebarLinks(sidebar) {
|
|
55
63
|
return collectSidebarItemsOfType('link', sidebar);
|
|
56
64
|
}
|
|
57
|
-
exports.collectSidebarLinks = collectSidebarLinks;
|
|
58
65
|
function collectSidebarRefs(sidebar) {
|
|
59
66
|
return collectSidebarItemsOfType('ref', sidebar);
|
|
60
67
|
}
|
|
61
|
-
exports.collectSidebarRefs = collectSidebarRefs;
|
|
62
68
|
// /!\ docId order matters for navigation!
|
|
63
69
|
function collectSidebarDocIds(sidebar) {
|
|
64
70
|
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
@@ -71,7 +77,6 @@ function collectSidebarDocIds(sidebar) {
|
|
|
71
77
|
return [];
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
|
-
exports.collectSidebarDocIds = collectSidebarDocIds;
|
|
75
80
|
function collectSidebarNavigation(sidebar) {
|
|
76
81
|
return flattenSidebarItems(sidebar).flatMap((item) => {
|
|
77
82
|
if (item.type === 'category' && item.link) {
|
|
@@ -83,15 +88,12 @@ function collectSidebarNavigation(sidebar) {
|
|
|
83
88
|
return [];
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
|
-
exports.collectSidebarNavigation = collectSidebarNavigation;
|
|
87
91
|
function collectSidebarsDocIds(sidebars) {
|
|
88
92
|
return lodash_1.default.mapValues(sidebars, collectSidebarDocIds);
|
|
89
93
|
}
|
|
90
|
-
exports.collectSidebarsDocIds = collectSidebarsDocIds;
|
|
91
94
|
function collectSidebarsNavigations(sidebars) {
|
|
92
95
|
return lodash_1.default.mapValues(sidebars, collectSidebarNavigation);
|
|
93
96
|
}
|
|
94
|
-
exports.collectSidebarsNavigations = collectSidebarsNavigations;
|
|
95
97
|
function createSidebarsUtils(sidebars) {
|
|
96
98
|
const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
|
|
97
99
|
const sidebarNameToNavigationItems = collectSidebarsNavigations(sidebars);
|
|
@@ -293,7 +295,6 @@ Available document ids are:
|
|
|
293
295
|
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
|
294
296
|
};
|
|
295
297
|
}
|
|
296
|
-
exports.createSidebarsUtils = createSidebarsUtils;
|
|
297
298
|
function toDocNavigationLink(doc, options) {
|
|
298
299
|
const { title, permalink, frontMatter: { pagination_label: paginationLabel, sidebar_label: sidebarLabel, }, } = doc;
|
|
299
300
|
return {
|
|
@@ -301,7 +302,6 @@ function toDocNavigationLink(doc, options) {
|
|
|
301
302
|
permalink,
|
|
302
303
|
};
|
|
303
304
|
}
|
|
304
|
-
exports.toDocNavigationLink = toDocNavigationLink;
|
|
305
305
|
function toNavigationLink(navigationItem, docsById) {
|
|
306
306
|
function getDocById(docId) {
|
|
307
307
|
const doc = docsById[docId];
|
|
@@ -325,4 +325,3 @@ function toNavigationLink(navigationItem, docsById) {
|
|
|
325
325
|
sidebarItemLabel: navigationItem?.label,
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
|
-
exports.toNavigationLink = toNavigationLink;
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.validateSidebars = validateSidebars;
|
|
10
|
+
exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
|
|
10
11
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
12
|
// NOTE: we don't add any default values during validation on purpose!
|
|
12
13
|
// Config types are exposed to users for typechecking and we use the same type
|
|
@@ -130,9 +131,9 @@ function validateSidebars(sidebars) {
|
|
|
130
131
|
sidebar.forEach(validateSidebarItem);
|
|
131
132
|
});
|
|
132
133
|
}
|
|
133
|
-
exports.validateSidebars = validateSidebars;
|
|
134
134
|
const categoryMetadataFileSchema = utils_validation_1.Joi.object({
|
|
135
135
|
label: utils_validation_1.Joi.string(),
|
|
136
|
+
description: utils_validation_1.Joi.string(),
|
|
136
137
|
position: utils_validation_1.Joi.number(),
|
|
137
138
|
collapsed: utils_validation_1.Joi.boolean(),
|
|
138
139
|
collapsible: utils_validation_1.Joi.boolean(),
|
|
@@ -147,4 +148,3 @@ function validateCategoryMetadataFile(unsafeContent) {
|
|
|
147
148
|
}
|
|
148
149
|
return value;
|
|
149
150
|
}
|
|
150
|
-
exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
|
package/lib/slug.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
/// <reference path="../src/plugin-content-docs.d.ts" />
|
|
8
7
|
import type { NumberPrefixParser, DocMetadataBase } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
export default function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumberPrefixes, numberPrefixParser, }: {
|
|
10
9
|
baseID: string;
|
package/lib/slug.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = getSlug;
|
|
9
10
|
const utils_1 = require("@docusaurus/utils");
|
|
10
11
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
11
12
|
const numberPrefix_1 = require("./numberPrefix");
|
|
@@ -48,4 +49,3 @@ slug: /my/customDocPath
|
|
|
48
49
|
}
|
|
49
50
|
return ensureValidSlug(computeSlug());
|
|
50
51
|
}
|
|
51
|
-
exports.default = getSlug;
|
package/lib/translations.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
/// <reference path="../src/plugin-content-docs.d.ts" />
|
|
8
7
|
import type { LoadedContent } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
import type { TranslationFile } from '@docusaurus/types';
|
|
10
9
|
export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFile[];
|
package/lib/translations.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
10
|
+
exports.translateLoadedContent = translateLoadedContent;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
13
|
const utils_1 = require("@docusaurus/utils");
|
|
@@ -158,11 +159,9 @@ function translateVersions(versions, translationFiles) {
|
|
|
158
159
|
function getLoadedContentTranslationFiles(loadedContent) {
|
|
159
160
|
return getVersionsTranslationFiles(loadedContent.loadedVersions);
|
|
160
161
|
}
|
|
161
|
-
exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
|
|
162
162
|
function translateLoadedContent(loadedContent, translationFiles) {
|
|
163
163
|
const translationFilesMap = lodash_1.default.keyBy(translationFiles, (f) => f.path);
|
|
164
164
|
return {
|
|
165
165
|
loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
-
exports.translateLoadedContent = translateLoadedContent;
|
package/lib/types.d.ts
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import type {
|
|
9
|
-
import type { VersionMetadata, LoadedVersion, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
|
|
7
|
+
import type { TagMetadata } from '@docusaurus/utils';
|
|
8
|
+
import type { LoadedVersion, CategoryGeneratedIndexMetadata } from '@docusaurus/plugin-content-docs';
|
|
10
9
|
import type { SidebarsUtils } from './sidebars/utils';
|
|
11
10
|
export type DocFile = {
|
|
12
11
|
contentPath: string;
|
|
@@ -14,10 +13,7 @@ export type DocFile = {
|
|
|
14
13
|
source: string;
|
|
15
14
|
content: string;
|
|
16
15
|
};
|
|
17
|
-
export type
|
|
18
|
-
[source: string]: string;
|
|
19
|
-
};
|
|
20
|
-
export type VersionTag = Tag & {
|
|
16
|
+
export type VersionTag = TagMetadata & {
|
|
21
17
|
/** All doc ids having this tag. */
|
|
22
18
|
docIds: string[];
|
|
23
19
|
unlisted: boolean;
|
|
@@ -29,10 +25,3 @@ export type FullVersion = LoadedVersion & {
|
|
|
29
25
|
sidebarsUtils: SidebarsUtils;
|
|
30
26
|
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
|
|
31
27
|
};
|
|
32
|
-
export type DocBrokenMarkdownLink = BrokenMarkdownLink<VersionMetadata>;
|
|
33
|
-
export type DocsMarkdownOption = {
|
|
34
|
-
versionsMetadata: VersionMetadata[];
|
|
35
|
-
siteDir: string;
|
|
36
|
-
sourceToPermalink: SourceToPermalink;
|
|
37
|
-
onBrokenMarkdownLink: (brokenMarkdownLink: DocBrokenMarkdownLink) => void;
|
|
38
|
-
};
|
package/lib/versions/files.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
/// <reference path="../../src/plugin-content-docs.d.ts" />
|
|
8
7
|
import type { PluginOptions, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
import type { VersionContext } from './index';
|
|
10
9
|
/** `[siteDir]/community_versioned_docs/version-1.0.0` */
|
package/lib/versions/files.js
CHANGED
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.getVersionDocsDirPath = getVersionDocsDirPath;
|
|
10
|
+
exports.getVersionSidebarsPath = getVersionSidebarsPath;
|
|
11
|
+
exports.getDocsDirPathLocalized = getDocsDirPathLocalized;
|
|
12
|
+
exports.getVersionsFilePath = getVersionsFilePath;
|
|
13
|
+
exports.readVersionsFile = readVersionsFile;
|
|
14
|
+
exports.readVersionNames = readVersionNames;
|
|
15
|
+
exports.getVersionMetadataPaths = getVersionMetadataPaths;
|
|
10
16
|
const tslib_1 = require("tslib");
|
|
11
17
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
18
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
@@ -23,12 +29,10 @@ function addPluginIdPrefix(fileOrDir, pluginId) {
|
|
|
23
29
|
function getVersionDocsDirPath(siteDir, pluginId, versionName) {
|
|
24
30
|
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_DOCS_DIR, pluginId), `version-${versionName}`);
|
|
25
31
|
}
|
|
26
|
-
exports.getVersionDocsDirPath = getVersionDocsDirPath;
|
|
27
32
|
/** `[siteDir]/community_versioned_sidebars/version-1.0.0-sidebars.json` */
|
|
28
33
|
function getVersionSidebarsPath(siteDir, pluginId, versionName) {
|
|
29
34
|
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONED_SIDEBARS_DIR, pluginId), `version-${versionName}-sidebars.json`);
|
|
30
35
|
}
|
|
31
|
-
exports.getVersionSidebarsPath = getVersionSidebarsPath;
|
|
32
36
|
function getDocsDirPathLocalized({ localizationDir, pluginId, versionName, }) {
|
|
33
37
|
return (0, utils_1.getPluginI18nPath)({
|
|
34
38
|
localizationDir,
|
|
@@ -41,12 +45,10 @@ function getDocsDirPathLocalized({ localizationDir, pluginId, versionName, }) {
|
|
|
41
45
|
],
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
|
-
exports.getDocsDirPathLocalized = getDocsDirPathLocalized;
|
|
45
48
|
/** `community` => `[siteDir]/community_versions.json` */
|
|
46
49
|
function getVersionsFilePath(siteDir, pluginId) {
|
|
47
50
|
return path_1.default.join(siteDir, addPluginIdPrefix(constants_1.VERSIONS_JSON_FILE, pluginId));
|
|
48
51
|
}
|
|
49
|
-
exports.getVersionsFilePath = getVersionsFilePath;
|
|
50
52
|
/**
|
|
51
53
|
* Reads the plugin's respective `versions.json` file, and returns its content.
|
|
52
54
|
*
|
|
@@ -62,7 +64,6 @@ async function readVersionsFile(siteDir, pluginId) {
|
|
|
62
64
|
}
|
|
63
65
|
return null;
|
|
64
66
|
}
|
|
65
|
-
exports.readVersionsFile = readVersionsFile;
|
|
66
67
|
/**
|
|
67
68
|
* Reads the `versions.json` file, and returns an ordered list of version names.
|
|
68
69
|
*
|
|
@@ -98,7 +99,6 @@ async function readVersionNames(siteDir, options) {
|
|
|
98
99
|
}
|
|
99
100
|
return versions;
|
|
100
101
|
}
|
|
101
|
-
exports.readVersionNames = readVersionNames;
|
|
102
102
|
/**
|
|
103
103
|
* Gets the path-related version metadata.
|
|
104
104
|
*
|
|
@@ -138,4 +138,3 @@ Please set the docs "sidebarPath" field in your config file to:
|
|
|
138
138
|
}
|
|
139
139
|
return { contentPath, contentPathLocalized, sidebarFilePath };
|
|
140
140
|
}
|
|
141
|
-
exports.getVersionMetadataPaths = getVersionMetadataPaths;
|
package/lib/versions/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
/// <reference path="../../src/plugin-content-docs.d.ts" />
|
|
8
7
|
import type { FullVersion } from '../types';
|
|
9
8
|
import type { LoadContext } from '@docusaurus/types';
|
|
10
9
|
import type { LoadedVersion, PluginOptions, VersionBanner, VersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
@@ -38,3 +37,4 @@ export declare function readVersionsMetadata({ context, options, }: {
|
|
|
38
37
|
options: PluginOptions;
|
|
39
38
|
}): Promise<VersionMetadata[]>;
|
|
40
39
|
export declare function toFullVersion(version: LoadedVersion): FullVersion;
|
|
40
|
+
export declare function getVersionFromSourceFilePath(filePath: string, versionsMetadata: VersionMetadata[]): VersionMetadata;
|
package/lib/versions/index.js
CHANGED
|
@@ -6,7 +6,14 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.getDefaultVersionBanner = getDefaultVersionBanner;
|
|
10
|
+
exports.getVersionBanner = getVersionBanner;
|
|
11
|
+
exports.getVersionBadge = getVersionBadge;
|
|
12
|
+
exports.getVersionNoIndex = getVersionNoIndex;
|
|
13
|
+
exports.filterVersions = filterVersions;
|
|
14
|
+
exports.readVersionsMetadata = readVersionsMetadata;
|
|
15
|
+
exports.toFullVersion = toFullVersion;
|
|
16
|
+
exports.getVersionFromSourceFilePath = getVersionFromSourceFilePath;
|
|
10
17
|
const tslib_1 = require("tslib");
|
|
11
18
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
19
|
const utils_1 = require("@docusaurus/utils");
|
|
@@ -55,7 +62,6 @@ function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }
|
|
|
55
62
|
// Older versions: display unmaintained banner
|
|
56
63
|
return 'unmaintained';
|
|
57
64
|
}
|
|
58
|
-
exports.getDefaultVersionBanner = getDefaultVersionBanner;
|
|
59
65
|
function getVersionBanner(context) {
|
|
60
66
|
const { versionName, options } = context;
|
|
61
67
|
const versionBannerOption = options.versions[versionName]?.banner;
|
|
@@ -64,7 +70,6 @@ function getVersionBanner(context) {
|
|
|
64
70
|
}
|
|
65
71
|
return getDefaultVersionBanner(context);
|
|
66
72
|
}
|
|
67
|
-
exports.getVersionBanner = getVersionBanner;
|
|
68
73
|
function getVersionBadge({ versionName, versionNames, options, }) {
|
|
69
74
|
// If site is not versioned or only one version is included
|
|
70
75
|
// we don't show the version badge by default
|
|
@@ -72,11 +77,9 @@ function getVersionBadge({ versionName, versionNames, options, }) {
|
|
|
72
77
|
const defaultVersionBadge = versionNames.length !== 1;
|
|
73
78
|
return options.versions[versionName]?.badge ?? defaultVersionBadge;
|
|
74
79
|
}
|
|
75
|
-
exports.getVersionBadge = getVersionBadge;
|
|
76
80
|
function getVersionNoIndex({ versionName, options, }) {
|
|
77
81
|
return options.versions[versionName]?.noIndex ?? false;
|
|
78
82
|
}
|
|
79
|
-
exports.getVersionNoIndex = getVersionNoIndex;
|
|
80
83
|
function getVersionClassName({ versionName, options, }) {
|
|
81
84
|
const defaultVersionClassName = `docs-version-${versionName}`;
|
|
82
85
|
return options.versions[versionName]?.className ?? defaultVersionClassName;
|
|
@@ -138,7 +141,6 @@ function filterVersions(versionNamesUnfiltered, options) {
|
|
|
138
141
|
}
|
|
139
142
|
return versionNamesUnfiltered;
|
|
140
143
|
}
|
|
141
|
-
exports.filterVersions = filterVersions;
|
|
142
144
|
function getLastVersionName({ versionNames, options, }) {
|
|
143
145
|
return (options.lastVersion ??
|
|
144
146
|
versionNames.find((name) => name !== constants_1.CURRENT_VERSION_NAME) ??
|
|
@@ -158,7 +160,6 @@ async function readVersionsMetadata({ context, options, }) {
|
|
|
158
160
|
})));
|
|
159
161
|
return versionsMetadata;
|
|
160
162
|
}
|
|
161
|
-
exports.readVersionsMetadata = readVersionsMetadata;
|
|
162
163
|
function toFullVersion(version) {
|
|
163
164
|
const sidebarsUtils = (0, utils_2.createSidebarsUtils)(version.sidebars);
|
|
164
165
|
return {
|
|
@@ -170,4 +171,10 @@ function toFullVersion(version) {
|
|
|
170
171
|
}),
|
|
171
172
|
};
|
|
172
173
|
}
|
|
173
|
-
|
|
174
|
+
function getVersionFromSourceFilePath(filePath, versionsMetadata) {
|
|
175
|
+
const versionFound = versionsMetadata.find((version) => (0, utils_1.getContentPathList)(version).some((docsDirPath) => filePath.startsWith(docsDirPath)));
|
|
176
|
+
if (!versionFound) {
|
|
177
|
+
throw new Error(`Unexpected error: file at "${filePath}" does not belong to any docs version!`);
|
|
178
|
+
}
|
|
179
|
+
return versionFound;
|
|
180
|
+
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
/// <reference path="../../src/plugin-content-docs.d.ts" />
|
|
8
7
|
import type { VersionsOptions } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
export declare function validateVersionName(name: unknown): asserts name is string;
|
|
10
9
|
export declare function validateVersionNames(names: unknown): asserts names is string[];
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.validateVersionName = validateVersionName;
|
|
10
|
+
exports.validateVersionNames = validateVersionNames;
|
|
11
|
+
exports.validateVersionsOptions = validateVersionsOptions;
|
|
10
12
|
const tslib_1 = require("tslib");
|
|
11
13
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
14
|
function validateVersionName(name) {
|
|
@@ -29,14 +31,12 @@ function validateVersionName(name) {
|
|
|
29
31
|
}
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
|
-
exports.validateVersionName = validateVersionName;
|
|
33
34
|
function validateVersionNames(names) {
|
|
34
35
|
if (!Array.isArray(names)) {
|
|
35
36
|
throw new Error(`The versions file should contain an array of version names! Found content: ${JSON.stringify(names)}`);
|
|
36
37
|
}
|
|
37
38
|
names.forEach(validateVersionName);
|
|
38
39
|
}
|
|
39
|
-
exports.validateVersionNames = validateVersionNames;
|
|
40
40
|
/**
|
|
41
41
|
* @throws Throws for one of the following invalid options:
|
|
42
42
|
* - `lastVersion` is non-existent
|
|
@@ -68,4 +68,3 @@ function validateVersionsOptions(availableVersionNames, options) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
exports.validateVersionsOptions = validateVersionsOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,14 +35,15 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@docusaurus/core": "3.
|
|
39
|
-
"@docusaurus/logger": "3.
|
|
40
|
-
"@docusaurus/mdx-loader": "3.
|
|
41
|
-
"@docusaurus/module-type-aliases": "3.
|
|
42
|
-
"@docusaurus/
|
|
43
|
-
"@docusaurus/
|
|
44
|
-
"@docusaurus/utils
|
|
45
|
-
"@docusaurus/utils-
|
|
38
|
+
"@docusaurus/core": "3.5.0",
|
|
39
|
+
"@docusaurus/logger": "3.5.0",
|
|
40
|
+
"@docusaurus/mdx-loader": "3.5.0",
|
|
41
|
+
"@docusaurus/module-type-aliases": "3.5.0",
|
|
42
|
+
"@docusaurus/theme-common": "3.5.0",
|
|
43
|
+
"@docusaurus/types": "3.5.0",
|
|
44
|
+
"@docusaurus/utils": "3.5.0",
|
|
45
|
+
"@docusaurus/utils-common": "3.5.0",
|
|
46
|
+
"@docusaurus/utils-validation": "3.5.0",
|
|
46
47
|
"@types/react-router-config": "^5.0.7",
|
|
47
48
|
"combine-promises": "^1.1.0",
|
|
48
49
|
"fs-extra": "^11.1.1",
|
|
@@ -66,5 +67,5 @@
|
|
|
66
67
|
"engines": {
|
|
67
68
|
"node": ">=18.0"
|
|
68
69
|
},
|
|
69
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "cb5829f3c34b26d798b869e38ee25073488140bd"
|
|
70
71
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 React, {useMemo, type ReactNode, useContext} from 'react';
|
|
9
|
+
import {ReactContextError} from '@docusaurus/theme-common/internal';
|
|
10
|
+
import type {PropDocContent} from '@docusaurus/plugin-content-docs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The React context value returned by the `useDoc()` hook.
|
|
14
|
+
* It contains useful data related to the currently browsed doc.
|
|
15
|
+
*/
|
|
16
|
+
export type DocContextValue = Pick<
|
|
17
|
+
PropDocContent,
|
|
18
|
+
'metadata' | 'frontMatter' | 'toc' | 'assets' | 'contentTitle'
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
const Context = React.createContext<DocContextValue | null>(null);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Note: we don't use `PropDoc` as context value on purpose. Metadata is
|
|
25
|
+
* currently stored inside the MDX component, but we may want to change that in
|
|
26
|
+
* the future. This layer is a good opportunity to decouple storage from
|
|
27
|
+
* consuming API, potentially allowing us to provide metadata as both props and
|
|
28
|
+
* route context without duplicating the chunks in the future.
|
|
29
|
+
*/
|
|
30
|
+
function useContextValue(content: PropDocContent): DocContextValue {
|
|
31
|
+
return useMemo(
|
|
32
|
+
() => ({
|
|
33
|
+
metadata: content.metadata,
|
|
34
|
+
frontMatter: content.frontMatter,
|
|
35
|
+
assets: content.assets,
|
|
36
|
+
contentTitle: content.contentTitle,
|
|
37
|
+
toc: content.toc,
|
|
38
|
+
}),
|
|
39
|
+
[content],
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* This is a very thin layer around the `content` received from the MDX loader.
|
|
45
|
+
* It provides metadata about the doc to the children tree.
|
|
46
|
+
*/
|
|
47
|
+
export function DocProvider({
|
|
48
|
+
children,
|
|
49
|
+
content,
|
|
50
|
+
}: {
|
|
51
|
+
children: ReactNode;
|
|
52
|
+
content: PropDocContent;
|
|
53
|
+
}): JSX.Element {
|
|
54
|
+
const contextValue = useContextValue(content);
|
|
55
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the data of the currently browsed doc. Gives access to the doc's MDX
|
|
60
|
+
* Component, front matter, metadata, TOC, etc. When swizzling a low-level
|
|
61
|
+
* component (e.g. the "Edit this page" link) and you need some extra metadata,
|
|
62
|
+
* you don't have to drill the props all the way through the component tree:
|
|
63
|
+
* simply use this hook instead.
|
|
64
|
+
*/
|
|
65
|
+
export function useDoc(): DocContextValue {
|
|
66
|
+
const doc = useContext(Context);
|
|
67
|
+
if (doc === null) {
|
|
68
|
+
throw new ReactContextError('DocProvider');
|
|
69
|
+
}
|
|
70
|
+
return doc;
|
|
71
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 React, {type ReactNode, useMemo, useState, useContext} from 'react';
|
|
9
|
+
import {ReactContextError} from '@docusaurus/theme-common/internal';
|
|
10
|
+
|
|
11
|
+
type ContextValue = {
|
|
12
|
+
/**
|
|
13
|
+
* The item that the user last opened, `null` when there's none open. On
|
|
14
|
+
* initial render, it will always be `null`, which doesn't necessarily mean
|
|
15
|
+
* there's no category open (can have 0, 1, or many being initially open).
|
|
16
|
+
*/
|
|
17
|
+
expandedItem: number | null;
|
|
18
|
+
/**
|
|
19
|
+
* Set the currently expanded item, when the user opens one. Set the value to
|
|
20
|
+
* `null` when the user closes an open category.
|
|
21
|
+
*/
|
|
22
|
+
setExpandedItem: (a: number | null) => void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const EmptyContext: unique symbol = Symbol('EmptyContext');
|
|
26
|
+
const Context = React.createContext<ContextValue | typeof EmptyContext>(
|
|
27
|
+
EmptyContext,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Should be used to wrap one sidebar category level. This provider syncs the
|
|
32
|
+
* expanded states of all sibling categories, and categories can choose to
|
|
33
|
+
* collapse itself if another one is expanded.
|
|
34
|
+
*/
|
|
35
|
+
export function DocSidebarItemsExpandedStateProvider({
|
|
36
|
+
children,
|
|
37
|
+
}: {
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
}): JSX.Element {
|
|
40
|
+
const [expandedItem, setExpandedItem] = useState<number | null>(null);
|
|
41
|
+
const contextValue = useMemo(
|
|
42
|
+
() => ({expandedItem, setExpandedItem}),
|
|
43
|
+
[expandedItem],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useDocSidebarItemsExpandedState(): ContextValue {
|
|
50
|
+
const value = useContext(Context);
|
|
51
|
+
if (value === EmptyContext) {
|
|
52
|
+
throw new ReactContextError('DocSidebarItemsExpandedStateProvider');
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
@@ -63,14 +63,23 @@ export function getActiveVersion(
|
|
|
63
63
|
data: GlobalPluginData,
|
|
64
64
|
pathname: string,
|
|
65
65
|
): GlobalVersion | undefined {
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
// Sort paths so that a match-all version like /docs/* is matched last
|
|
67
|
+
// Otherwise /docs/* would match /docs/1.0.0/* routes
|
|
68
|
+
// This is simplified but similar to the core sortRoutes() logic
|
|
69
|
+
const sortedVersions = [...data.versions].sort((a, b) => {
|
|
70
|
+
if (a.path === b.path) {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
if (a.path.includes(b.path)) {
|
|
74
|
+
return -1;
|
|
75
|
+
}
|
|
76
|
+
if (b.path.includes(a.path)) {
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
return 0;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return sortedVersions.find(
|
|
74
83
|
(version) =>
|
|
75
84
|
!!matchPath(pathname, {
|
|
76
85
|
path: version.path,
|