@docusaurus/plugin-content-docs 2.0.0-beta.16 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/categoryGeneratedIndex.d.ts +1 -1
- package/lib/categoryGeneratedIndex.js +5 -7
- package/lib/cli.d.ts +3 -2
- package/lib/cli.js +49 -41
- package/lib/client/docsClientUtils.d.ts +8 -5
- package/lib/client/docsClientUtils.js +13 -15
- package/lib/client/index.d.ts +12 -9
- package/lib/client/index.js +30 -33
- package/lib/constants.d.ts +4 -0
- package/lib/constants.js +4 -1
- package/lib/docs.d.ts +8 -15
- package/lib/docs.js +34 -39
- package/lib/{docFrontMatter.d.ts → frontMatter.d.ts} +4 -2
- package/lib/{docFrontMatter.js → frontMatter.js} +3 -0
- package/lib/globalData.d.ts +3 -7
- package/lib/globalData.js +9 -13
- package/lib/index.d.ts +1 -2
- package/lib/index.js +33 -26
- package/lib/lastUpdate.d.ts +4 -6
- package/lib/lastUpdate.js +14 -5
- package/lib/markdown/index.js +1 -1
- package/lib/markdown/linkify.js +5 -2
- package/lib/numberPrefix.js +16 -22
- package/lib/options.d.ts +3 -5
- package/lib/options.js +6 -5
- package/lib/props.d.ts +3 -3
- package/lib/props.js +10 -10
- package/lib/routes.d.ts +5 -4
- package/lib/routes.js +10 -24
- package/lib/server-export.d.ts +2 -1
- package/lib/server-export.js +3 -4
- package/lib/sidebars/generator.js +63 -44
- package/lib/sidebars/index.js +20 -16
- package/lib/sidebars/normalization.js +3 -3
- package/lib/sidebars/postProcessor.js +18 -25
- package/lib/sidebars/processor.d.ts +3 -1
- package/lib/sidebars/processor.js +17 -6
- package/lib/sidebars/types.d.ts +31 -19
- package/lib/sidebars/utils.d.ts +17 -6
- package/lib/sidebars/utils.js +27 -37
- package/lib/sidebars/validation.d.ts +3 -1
- package/lib/sidebars/validation.js +1 -0
- package/lib/slug.d.ts +1 -2
- package/lib/slug.js +4 -5
- package/lib/tags.d.ts +2 -1
- package/lib/tags.js +2 -2
- package/lib/translations.d.ts +3 -3
- package/lib/translations.js +28 -81
- package/lib/types.d.ts +10 -95
- package/lib/versions/files.d.ts +44 -0
- package/lib/versions/files.js +142 -0
- package/lib/versions/index.d.ts +36 -0
- package/lib/versions/index.js +155 -0
- package/lib/versions/validation.d.ts +17 -0
- package/lib/versions/validation.js +71 -0
- package/package.json +14 -12
- package/src/categoryGeneratedIndex.ts +10 -9
- package/src/cli.ts +64 -69
- package/src/client/docsClientUtils.ts +14 -16
- package/src/client/index.ts +42 -43
- package/src/constants.ts +4 -2
- package/src/deps.d.ts +1 -1
- package/src/docs.ts +48 -51
- package/src/{docFrontMatter.ts → frontMatter.ts} +9 -6
- package/src/globalData.ts +15 -16
- package/src/index.ts +45 -40
- package/src/lastUpdate.ts +20 -8
- package/src/markdown/index.ts +1 -3
- package/src/markdown/linkify.ts +6 -3
- package/src/numberPrefix.ts +18 -28
- package/src/options.ts +6 -8
- package/src/plugin-content-docs.d.ts +457 -116
- package/src/props.ts +12 -9
- package/src/routes.ts +13 -39
- package/src/server-export.ts +1 -3
- package/src/sidebars/generator.ts +88 -59
- package/src/sidebars/index.ts +20 -15
- package/src/sidebars/normalization.ts +1 -1
- package/src/sidebars/postProcessor.ts +6 -11
- package/src/sidebars/processor.ts +27 -14
- package/src/sidebars/types.ts +25 -23
- package/src/sidebars/utils.ts +45 -46
- package/src/sidebars/validation.ts +4 -3
- package/src/slug.ts +7 -6
- package/src/tags.ts +3 -2
- package/src/translations.ts +32 -84
- package/src/types.ts +15 -107
- package/src/versions/files.ts +220 -0
- package/src/versions/index.ts +247 -0
- package/src/versions/validation.ts +113 -0
- package/lib/versions.d.ts +0 -41
- package/lib/versions.js +0 -329
- package/src/versions.ts +0 -606
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
CategoryGeneratedIndexMetadata,
|
|
10
|
+
DocMetadataBase,
|
|
11
|
+
} from '@docusaurus/plugin-content-docs';
|
|
9
12
|
import type {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
|
|
10
13
|
import {type SidebarsUtils, toNavigationLink} from './sidebars/utils';
|
|
11
14
|
import {createDocsByIdIndex} from './docs';
|
|
@@ -17,14 +20,10 @@ function getCategoryGeneratedIndexMetadata({
|
|
|
17
20
|
}: {
|
|
18
21
|
category: SidebarItemCategoryWithGeneratedIndex;
|
|
19
22
|
sidebarsUtils: SidebarsUtils;
|
|
20
|
-
docsById:
|
|
23
|
+
docsById: {[docId: string]: DocMetadataBase};
|
|
21
24
|
}): CategoryGeneratedIndexMetadata {
|
|
22
25
|
const {sidebarName, previous, next} =
|
|
23
26
|
sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
|
24
|
-
if (!sidebarName) {
|
|
25
|
-
throw new Error('unexpected');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
27
|
return {
|
|
29
28
|
title: category.link.title ?? category.label,
|
|
30
29
|
description: category.link.description,
|
|
@@ -32,9 +31,11 @@ function getCategoryGeneratedIndexMetadata({
|
|
|
32
31
|
keywords: category.link.keywords,
|
|
33
32
|
slug: category.link.slug,
|
|
34
33
|
permalink: category.link.permalink,
|
|
35
|
-
sidebar: sidebarName
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
sidebar: sidebarName!,
|
|
35
|
+
navigation: {
|
|
36
|
+
previous: toNavigationLink(previous, docsById),
|
|
37
|
+
next: toNavigationLink(next, docsById),
|
|
38
|
+
},
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
|
package/src/cli.ts
CHANGED
|
@@ -7,18 +7,19 @@
|
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
getVersionsFilePath,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
getVersionDocsDirPath,
|
|
11
|
+
getVersionSidebarsPath,
|
|
12
|
+
getDocsDirPathLocalized,
|
|
13
|
+
} from './versions/files';
|
|
14
|
+
import {validateVersionName} from './versions/validation';
|
|
13
15
|
import fs from 'fs-extra';
|
|
14
16
|
import path from 'path';
|
|
15
|
-
import type {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from '@docusaurus/plugin-content-docs';
|
|
19
|
-
import {loadSidebarsFileUnsafe, resolveSidebarPathOption} from './sidebars';
|
|
17
|
+
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
18
|
+
import {loadSidebarsFileUnsafe} from './sidebars';
|
|
19
|
+
import {CURRENT_VERSION_NAME} from './constants';
|
|
20
20
|
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
|
21
21
|
import logger from '@docusaurus/logger';
|
|
22
|
+
import type {LoadContext} from '@docusaurus/types';
|
|
22
23
|
|
|
23
24
|
async function createVersionedSidebarFile({
|
|
24
25
|
siteDir,
|
|
@@ -42,14 +43,8 @@ async function createVersionedSidebarFile({
|
|
|
42
43
|
const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
|
|
43
44
|
|
|
44
45
|
if (shouldCreateVersionedSidebarFile) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
versionedSidebarsDir,
|
|
48
|
-
`version-${version}-sidebars.json`,
|
|
49
|
-
);
|
|
50
|
-
await fs.ensureDir(path.dirname(newSidebarFile));
|
|
51
|
-
await fs.writeFile(
|
|
52
|
-
newSidebarFile,
|
|
46
|
+
await fs.outputFile(
|
|
47
|
+
getVersionSidebarsPath(siteDir, pluginId, version),
|
|
53
48
|
`${JSON.stringify(sidebars, null, 2)}\n`,
|
|
54
49
|
'utf8',
|
|
55
50
|
);
|
|
@@ -58,54 +53,27 @@ async function createVersionedSidebarFile({
|
|
|
58
53
|
|
|
59
54
|
// Tests depend on non-default export for mocking.
|
|
60
55
|
export async function cliDocsVersionCommand(
|
|
61
|
-
version: string
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
options: PathOptions & SidebarOptions,
|
|
56
|
+
version: string,
|
|
57
|
+
{id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
|
|
58
|
+
{siteDir, i18n}: LoadContext,
|
|
65
59
|
): Promise<void> {
|
|
66
60
|
// It wouldn't be very user-friendly to show a [default] log prefix,
|
|
67
61
|
// so we use [docs] instead of [default]
|
|
68
62
|
const pluginIdLogPrefix =
|
|
69
63
|
pluginId === DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
|
|
70
64
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (version.includes('/') || version.includes('\\')) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (version.length > 32) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Since we are going to create `version-${version}` folder, we need to make
|
|
90
|
-
// sure it's a valid pathname.
|
|
91
|
-
// eslint-disable-next-line no-control-regex
|
|
92
|
-
if (/[<>:"|?*\x00-\x1F]/g.test(version)) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (/^\.\.?$/.test(version)) {
|
|
99
|
-
throw new Error(
|
|
100
|
-
`${pluginIdLogPrefix}: invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0.`,
|
|
101
|
-
);
|
|
65
|
+
try {
|
|
66
|
+
validateVersionName(version);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
logger.info`${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
|
|
69
|
+
throw e;
|
|
102
70
|
}
|
|
103
71
|
|
|
104
72
|
// Load existing versions.
|
|
105
73
|
let versions = [];
|
|
106
74
|
const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
|
|
107
75
|
if (await fs.pathExists(versionsJSONFile)) {
|
|
108
|
-
versions =
|
|
76
|
+
versions = await fs.readJSON(versionsJSONFile);
|
|
109
77
|
}
|
|
110
78
|
|
|
111
79
|
// Check if version already exists.
|
|
@@ -115,33 +83,60 @@ export async function cliDocsVersionCommand(
|
|
|
115
83
|
);
|
|
116
84
|
}
|
|
117
85
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// Copy docs files.
|
|
121
|
-
const docsDir = path.join(siteDir, docsPath);
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
(await fs.pathExists(docsDir)) &&
|
|
125
|
-
(await fs.readdir(docsDir)).length > 0
|
|
126
|
-
) {
|
|
127
|
-
const versionedDir = getVersionedDocsDirPath(siteDir, pluginId);
|
|
128
|
-
const newVersionDir = path.join(versionedDir, `version-${version}`);
|
|
129
|
-
await fs.copy(docsDir, newVersionDir);
|
|
130
|
-
} else {
|
|
131
|
-
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
|
|
86
|
+
if (i18n.locales.length > 1) {
|
|
87
|
+
logger.info`Versioned docs will be created for the following locales: name=${i18n.locales}`;
|
|
132
88
|
}
|
|
133
89
|
|
|
90
|
+
await Promise.all(
|
|
91
|
+
i18n.locales.map(async (locale) => {
|
|
92
|
+
// Copy docs files.
|
|
93
|
+
const docsDir =
|
|
94
|
+
locale === i18n.defaultLocale
|
|
95
|
+
? path.resolve(siteDir, docsPath)
|
|
96
|
+
: getDocsDirPathLocalized({
|
|
97
|
+
siteDir,
|
|
98
|
+
locale,
|
|
99
|
+
pluginId,
|
|
100
|
+
versionName: CURRENT_VERSION_NAME,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (
|
|
104
|
+
!(await fs.pathExists(docsDir)) ||
|
|
105
|
+
(await fs.readdir(docsDir)).length === 0
|
|
106
|
+
) {
|
|
107
|
+
if (locale === i18n.defaultLocale) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
logger.interpolate`${pluginIdLogPrefix}: no docs found in path=${docsDir}.`,
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
logger.warn`${pluginIdLogPrefix}: no docs found in path=${docsDir}. Skipping.`;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const newVersionDir =
|
|
118
|
+
locale === i18n.defaultLocale
|
|
119
|
+
? getVersionDocsDirPath(siteDir, pluginId, version)
|
|
120
|
+
: getDocsDirPathLocalized({
|
|
121
|
+
siteDir,
|
|
122
|
+
locale,
|
|
123
|
+
pluginId,
|
|
124
|
+
versionName: version,
|
|
125
|
+
});
|
|
126
|
+
await fs.copy(docsDir, newVersionDir);
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
|
|
134
130
|
await createVersionedSidebarFile({
|
|
135
131
|
siteDir,
|
|
136
132
|
pluginId,
|
|
137
133
|
version,
|
|
138
|
-
sidebarPath
|
|
134
|
+
sidebarPath,
|
|
139
135
|
});
|
|
140
136
|
|
|
141
137
|
// Update versions.json file.
|
|
142
138
|
versions.unshift(version);
|
|
143
|
-
await fs.
|
|
144
|
-
await fs.writeFile(
|
|
139
|
+
await fs.outputFile(
|
|
145
140
|
versionsJSONFile,
|
|
146
141
|
`${JSON.stringify(versions, null, 2)}\n`,
|
|
147
142
|
);
|
|
@@ -11,11 +11,11 @@ import type {
|
|
|
11
11
|
GlobalPluginData,
|
|
12
12
|
GlobalVersion,
|
|
13
13
|
GlobalDoc,
|
|
14
|
-
GetActivePluginOptions,
|
|
15
14
|
ActivePlugin,
|
|
16
15
|
ActiveDocContext,
|
|
17
16
|
DocVersionSuggestions,
|
|
18
17
|
} from '@docusaurus/plugin-content-docs/client';
|
|
18
|
+
import type {UseDataOptions} from '@docusaurus/types';
|
|
19
19
|
|
|
20
20
|
// This code is not part of the api surface, not in ./theme on purpose
|
|
21
21
|
|
|
@@ -23,11 +23,11 @@ import type {
|
|
|
23
23
|
// ie the docs of that plugin are currently browsed
|
|
24
24
|
// it is useful to support multiple docs plugin instances
|
|
25
25
|
export function getActivePlugin(
|
|
26
|
-
|
|
26
|
+
allPluginData: {[pluginId: string]: GlobalPluginData},
|
|
27
27
|
pathname: string,
|
|
28
|
-
options:
|
|
28
|
+
options: UseDataOptions = {},
|
|
29
29
|
): ActivePlugin | undefined {
|
|
30
|
-
const activeEntry = Object.entries(
|
|
30
|
+
const activeEntry = Object.entries(allPluginData)
|
|
31
31
|
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
|
32
32
|
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
33
33
|
.find(
|
|
@@ -46,7 +46,7 @@ export function getActivePlugin(
|
|
|
46
46
|
if (!activePlugin && options.failfast) {
|
|
47
47
|
throw new Error(
|
|
48
48
|
`Can't find active docs plugin for "${pathname}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(
|
|
49
|
-
|
|
49
|
+
allPluginData,
|
|
50
50
|
)
|
|
51
51
|
.map((plugin) => plugin.path)
|
|
52
52
|
.join(', ')}`,
|
|
@@ -59,12 +59,10 @@ export function getActivePlugin(
|
|
|
59
59
|
export const getLatestVersion = (data: GlobalPluginData): GlobalVersion =>
|
|
60
60
|
data.versions.find((version) => version.isLast)!;
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
// because there's no version currently considered as active
|
|
64
|
-
export const getActiveVersion = (
|
|
62
|
+
export function getActiveVersion(
|
|
65
63
|
data: GlobalPluginData,
|
|
66
64
|
pathname: string,
|
|
67
|
-
): GlobalVersion | undefined
|
|
65
|
+
): GlobalVersion | undefined {
|
|
68
66
|
const lastVersion = getLatestVersion(data);
|
|
69
67
|
// Last version is a route like /docs/*,
|
|
70
68
|
// we need to match it last or it would match /docs/version-1.0/* as well
|
|
@@ -80,12 +78,12 @@ export const getActiveVersion = (
|
|
|
80
78
|
strict: false,
|
|
81
79
|
}),
|
|
82
80
|
);
|
|
83
|
-
}
|
|
81
|
+
}
|
|
84
82
|
|
|
85
|
-
export
|
|
83
|
+
export function getActiveDocContext(
|
|
86
84
|
data: GlobalPluginData,
|
|
87
85
|
pathname: string,
|
|
88
|
-
): ActiveDocContext
|
|
86
|
+
): ActiveDocContext {
|
|
89
87
|
const activeVersion = getActiveVersion(data, pathname);
|
|
90
88
|
const activeDoc = activeVersion?.docs.find(
|
|
91
89
|
(doc) =>
|
|
@@ -119,15 +117,15 @@ export const getActiveDocContext = (
|
|
|
119
117
|
activeDoc,
|
|
120
118
|
alternateDocVersions: alternateVersionDocs,
|
|
121
119
|
};
|
|
122
|
-
}
|
|
120
|
+
}
|
|
123
121
|
|
|
124
|
-
export
|
|
122
|
+
export function getDocVersionSuggestions(
|
|
125
123
|
data: GlobalPluginData,
|
|
126
124
|
pathname: string,
|
|
127
|
-
): DocVersionSuggestions
|
|
125
|
+
): DocVersionSuggestions {
|
|
128
126
|
const latestVersion = getLatestVersion(data);
|
|
129
127
|
const activeDocContext = getActiveDocContext(data, pathname);
|
|
130
128
|
const latestDocSuggestion: GlobalDoc | undefined =
|
|
131
129
|
activeDocContext?.alternateDocVersions[latestVersion.name];
|
|
132
130
|
return {latestDocSuggestion, latestVersionSuggestion: latestVersion};
|
|
133
|
-
}
|
|
131
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {useLocation} from '@docusaurus/router';
|
|
9
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
useAllPluginInstancesData,
|
|
11
|
+
usePluginData,
|
|
12
|
+
} from '@docusaurus/useGlobalData';
|
|
10
13
|
|
|
11
14
|
import {
|
|
12
15
|
getActivePlugin,
|
|
@@ -21,84 +24,80 @@ import type {
|
|
|
21
24
|
ActivePlugin,
|
|
22
25
|
ActiveDocContext,
|
|
23
26
|
DocVersionSuggestions,
|
|
24
|
-
GetActivePluginOptions,
|
|
25
27
|
} from '@docusaurus/plugin-content-docs/client';
|
|
28
|
+
import type {UseDataOptions} from '@docusaurus/types';
|
|
26
29
|
|
|
27
30
|
// Important to use a constant object to avoid React useEffect executions etc.
|
|
28
31
|
// see https://github.com/facebook/docusaurus/issues/5089
|
|
29
32
|
const StableEmptyObject = {};
|
|
30
33
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// In blog-only mode, docs hooks are still used by the theme. We need a fail-
|
|
35
|
+
// safe fallback when the docs plugin is not in use
|
|
36
|
+
export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} =>
|
|
37
|
+
useAllPluginInstancesData('docusaurus-plugin-content-docs') ??
|
|
38
|
+
StableEmptyObject;
|
|
36
39
|
|
|
37
40
|
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
|
38
|
-
usePluginData('docusaurus-plugin-content-docs', pluginId
|
|
41
|
+
usePluginData('docusaurus-plugin-content-docs', pluginId, {
|
|
42
|
+
failfast: true,
|
|
43
|
+
}) as GlobalPluginData;
|
|
39
44
|
|
|
40
45
|
// TODO this feature should be provided by docusaurus core
|
|
41
|
-
export
|
|
42
|
-
options:
|
|
43
|
-
): ActivePlugin | undefined
|
|
46
|
+
export function useActivePlugin(
|
|
47
|
+
options: UseDataOptions = {},
|
|
48
|
+
): ActivePlugin | undefined {
|
|
44
49
|
const data = useAllDocsData();
|
|
45
50
|
const {pathname} = useLocation();
|
|
46
51
|
return getActivePlugin(data, pathname, options);
|
|
47
|
-
}
|
|
52
|
+
}
|
|
48
53
|
|
|
49
|
-
export
|
|
50
|
-
options:
|
|
54
|
+
export function useActivePluginAndVersion(
|
|
55
|
+
options: UseDataOptions = {},
|
|
51
56
|
):
|
|
52
|
-
| undefined
|
|
53
|
-
|
|
|
57
|
+
| {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined}
|
|
58
|
+
| undefined {
|
|
54
59
|
const activePlugin = useActivePlugin(options);
|
|
55
60
|
const {pathname} = useLocation();
|
|
56
|
-
if (activePlugin) {
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
activePlugin,
|
|
60
|
-
activeVersion,
|
|
61
|
-
};
|
|
61
|
+
if (!activePlugin) {
|
|
62
|
+
return undefined;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
|
|
65
|
+
return {
|
|
66
|
+
activePlugin,
|
|
67
|
+
activeVersion,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
export const useVersions = (pluginId: string | undefined): GlobalVersion[] => {
|
|
71
|
+
export function useVersions(pluginId: string | undefined): GlobalVersion[] {
|
|
68
72
|
const data = useDocsData(pluginId);
|
|
69
73
|
return data.versions;
|
|
70
|
-
}
|
|
74
|
+
}
|
|
71
75
|
|
|
72
|
-
export
|
|
73
|
-
pluginId: string | undefined,
|
|
74
|
-
): GlobalVersion => {
|
|
76
|
+
export function useLatestVersion(pluginId: string | undefined): GlobalVersion {
|
|
75
77
|
const data = useDocsData(pluginId);
|
|
76
78
|
return getLatestVersion(data);
|
|
77
|
-
}
|
|
79
|
+
}
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
// because there's no version currently considered as active
|
|
81
|
-
export const useActiveVersion = (
|
|
81
|
+
export function useActiveVersion(
|
|
82
82
|
pluginId: string | undefined,
|
|
83
|
-
): GlobalVersion | undefined
|
|
83
|
+
): GlobalVersion | undefined {
|
|
84
84
|
const data = useDocsData(pluginId);
|
|
85
85
|
const {pathname} = useLocation();
|
|
86
86
|
return getActiveVersion(data, pathname);
|
|
87
|
-
}
|
|
87
|
+
}
|
|
88
88
|
|
|
89
|
-
export
|
|
89
|
+
export function useActiveDocContext(
|
|
90
90
|
pluginId: string | undefined,
|
|
91
|
-
): ActiveDocContext
|
|
91
|
+
): ActiveDocContext {
|
|
92
92
|
const data = useDocsData(pluginId);
|
|
93
93
|
const {pathname} = useLocation();
|
|
94
94
|
return getActiveDocContext(data, pathname);
|
|
95
|
-
}
|
|
95
|
+
}
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
export const useDocVersionSuggestions = (
|
|
97
|
+
export function useDocVersionSuggestions(
|
|
99
98
|
pluginId: string | undefined,
|
|
100
|
-
): DocVersionSuggestions
|
|
99
|
+
): DocVersionSuggestions {
|
|
101
100
|
const data = useDocsData(pluginId);
|
|
102
101
|
const {pathname} = useLocation();
|
|
103
102
|
return getDocVersionSuggestions(data, pathname);
|
|
104
|
-
}
|
|
103
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/** The name of the version that's actively worked on (e.g. `website/docs`) */
|
|
9
9
|
export const CURRENT_VERSION_NAME = 'current';
|
|
10
|
-
|
|
10
|
+
/** All doc versions are stored here by version names */
|
|
11
11
|
export const VERSIONED_DOCS_DIR = 'versioned_docs';
|
|
12
|
+
/** All doc versioned sidebars are stored here by version names */
|
|
12
13
|
export const VERSIONED_SIDEBARS_DIR = 'versioned_sidebars';
|
|
14
|
+
/** The version names. Should 1-1 map to the content of versioned docs dir. */
|
|
13
15
|
export const VERSIONS_JSON_FILE = 'versions.json';
|