@docusaurus/plugin-content-docs 0.0.0-5012 → 0.0.0-5024
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/client/docsClientUtils.js +11 -19
- package/lib/client/index.js +29 -41
- package/package.json +10 -10
- package/src/plugin-content-docs.d.ts +2 -0
- package/src/types.ts +0 -2
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
3
|
*
|
|
5
4
|
* This source code is licensed under the MIT license found in the
|
|
6
5
|
* LICENSE file in the root directory of this source tree.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
exports.getDocVersionSuggestions = exports.getActiveDocContext = exports.getActiveVersion = exports.getLatestVersion = exports.getActivePlugin = void 0;
|
|
10
|
-
const router_1 = require("@docusaurus/router");
|
|
7
|
+
import { matchPath } from '@docusaurus/router';
|
|
11
8
|
// This code is not part of the api surface, not in ./theme on purpose
|
|
12
9
|
// get the data of the plugin that is currently "active"
|
|
13
10
|
// ie the docs of that plugin are currently browsed
|
|
14
11
|
// it is useful to support multiple docs plugin instances
|
|
15
|
-
function getActivePlugin(allPluginData, pathname, options = {}) {
|
|
12
|
+
export function getActivePlugin(allPluginData, pathname, options = {}) {
|
|
16
13
|
const activeEntry = Object.entries(allPluginData)
|
|
17
14
|
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
|
18
15
|
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
|
19
|
-
.find(([, pluginData]) => !!
|
|
16
|
+
.find(([, pluginData]) => !!matchPath(pathname, {
|
|
20
17
|
path: pluginData.path,
|
|
21
18
|
exact: false,
|
|
22
19
|
strict: false,
|
|
@@ -31,27 +28,24 @@ function getActivePlugin(allPluginData, pathname, options = {}) {
|
|
|
31
28
|
}
|
|
32
29
|
return activePlugin;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
function getActiveVersion(data, pathname) {
|
|
38
|
-
const lastVersion = (0, exports.getLatestVersion)(data);
|
|
31
|
+
export const getLatestVersion = (data) => data.versions.find((version) => version.isLast);
|
|
32
|
+
export function getActiveVersion(data, pathname) {
|
|
33
|
+
const lastVersion = getLatestVersion(data);
|
|
39
34
|
// Last version is a route like /docs/*,
|
|
40
35
|
// we need to match it last or it would match /docs/version-1.0/* as well
|
|
41
36
|
const orderedVersionsMetadata = [
|
|
42
37
|
...data.versions.filter((version) => version !== lastVersion),
|
|
43
38
|
lastVersion,
|
|
44
39
|
];
|
|
45
|
-
return orderedVersionsMetadata.find((version) => !!
|
|
40
|
+
return orderedVersionsMetadata.find((version) => !!matchPath(pathname, {
|
|
46
41
|
path: version.path,
|
|
47
42
|
exact: false,
|
|
48
43
|
strict: false,
|
|
49
44
|
}));
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
function getActiveDocContext(data, pathname) {
|
|
46
|
+
export function getActiveDocContext(data, pathname) {
|
|
53
47
|
const activeVersion = getActiveVersion(data, pathname);
|
|
54
|
-
const activeDoc = activeVersion?.docs.find((doc) => !!
|
|
48
|
+
const activeDoc = activeVersion?.docs.find((doc) => !!matchPath(pathname, {
|
|
55
49
|
path: doc.path,
|
|
56
50
|
exact: true,
|
|
57
51
|
strict: false,
|
|
@@ -76,11 +70,9 @@ function getActiveDocContext(data, pathname) {
|
|
|
76
70
|
alternateDocVersions: alternateVersionDocs,
|
|
77
71
|
};
|
|
78
72
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const latestVersion = (0, exports.getLatestVersion)(data);
|
|
73
|
+
export function getDocVersionSuggestions(data, pathname) {
|
|
74
|
+
const latestVersion = getLatestVersion(data);
|
|
82
75
|
const activeDocContext = getActiveDocContext(data, pathname);
|
|
83
76
|
const latestDocSuggestion = activeDocContext?.alternateDocVersions[latestVersion.name];
|
|
84
77
|
return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
|
|
85
78
|
}
|
|
86
|
-
exports.getDocVersionSuggestions = getDocVersionSuggestions;
|
package/lib/client/index.js
CHANGED
|
@@ -1,72 +1,60 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
3
|
*
|
|
5
4
|
* This source code is licensed under the MIT license found in the
|
|
6
5
|
* LICENSE file in the root directory of this source tree.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const useGlobalData_1 = require("@docusaurus/useGlobalData");
|
|
12
|
-
const docsClientUtils_1 = require("./docsClientUtils");
|
|
7
|
+
import { useLocation } from '@docusaurus/router';
|
|
8
|
+
import { useAllPluginInstancesData, usePluginData, } from '@docusaurus/useGlobalData';
|
|
9
|
+
import { getActivePlugin, getLatestVersion, getActiveVersion, getActiveDocContext, getDocVersionSuggestions, } from './docsClientUtils';
|
|
13
10
|
// Important to use a constant object to avoid React useEffect executions etc.
|
|
14
11
|
// see https://github.com/facebook/docusaurus/issues/5089
|
|
15
12
|
const StableEmptyObject = {};
|
|
16
13
|
// In blog-only mode, docs hooks are still used by the theme. We need a fail-
|
|
17
14
|
// safe fallback when the docs plugin is not in use
|
|
18
|
-
const useAllDocsData = () =>
|
|
15
|
+
export const useAllDocsData = () => useAllPluginInstancesData('docusaurus-plugin-content-docs') ??
|
|
19
16
|
StableEmptyObject;
|
|
20
|
-
|
|
21
|
-
const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId, {
|
|
17
|
+
export const useDocsData = (pluginId) => usePluginData('docusaurus-plugin-content-docs', pluginId, {
|
|
22
18
|
failfast: true,
|
|
23
19
|
});
|
|
24
|
-
exports.useDocsData = useDocsData;
|
|
25
20
|
// TODO this feature should be provided by docusaurus core
|
|
26
|
-
function useActivePlugin(options = {}) {
|
|
27
|
-
const data =
|
|
28
|
-
const { pathname } =
|
|
29
|
-
return
|
|
21
|
+
export function useActivePlugin(options = {}) {
|
|
22
|
+
const data = useAllDocsData();
|
|
23
|
+
const { pathname } = useLocation();
|
|
24
|
+
return getActivePlugin(data, pathname, options);
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
function useActivePluginAndVersion(options = {}) {
|
|
26
|
+
export function useActivePluginAndVersion(options = {}) {
|
|
33
27
|
const activePlugin = useActivePlugin(options);
|
|
34
|
-
const { pathname } =
|
|
28
|
+
const { pathname } = useLocation();
|
|
35
29
|
if (!activePlugin) {
|
|
36
30
|
return undefined;
|
|
37
31
|
}
|
|
38
|
-
const activeVersion =
|
|
32
|
+
const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
|
|
39
33
|
return {
|
|
40
34
|
activePlugin,
|
|
41
35
|
activeVersion,
|
|
42
36
|
};
|
|
43
37
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const data = (0, exports.useDocsData)(pluginId);
|
|
38
|
+
export function useVersions(pluginId) {
|
|
39
|
+
const data = useDocsData(pluginId);
|
|
47
40
|
return data.versions;
|
|
48
41
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return (0, docsClientUtils_1.getLatestVersion)(data);
|
|
42
|
+
export function useLatestVersion(pluginId) {
|
|
43
|
+
const data = useDocsData(pluginId);
|
|
44
|
+
return getLatestVersion(data);
|
|
53
45
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
|
|
46
|
+
export function useActiveVersion(pluginId) {
|
|
47
|
+
const data = useDocsData(pluginId);
|
|
48
|
+
const { pathname } = useLocation();
|
|
49
|
+
return getActiveVersion(data, pathname);
|
|
59
50
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
|
|
51
|
+
export function useActiveDocContext(pluginId) {
|
|
52
|
+
const data = useDocsData(pluginId);
|
|
53
|
+
const { pathname } = useLocation();
|
|
54
|
+
return getActiveDocContext(data, pathname);
|
|
65
55
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
|
|
56
|
+
export function useDocVersionSuggestions(pluginId) {
|
|
57
|
+
const data = useDocsData(pluginId);
|
|
58
|
+
const { pathname } = useLocation();
|
|
59
|
+
return getDocVersionSuggestions(data, pathname);
|
|
71
60
|
}
|
|
72
|
-
exports.useDocVersionSuggestions = useDocVersionSuggestions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5024",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"types": "src/plugin-content-docs.d.ts",
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsc",
|
|
15
|
+
"build": "tsc --build",
|
|
16
16
|
"watch": "tsc --watch"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@docusaurus/core": "0.0.0-
|
|
29
|
-
"@docusaurus/logger": "0.0.0-
|
|
30
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
31
|
-
"@docusaurus/utils": "0.0.0-
|
|
32
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
28
|
+
"@docusaurus/core": "0.0.0-5024",
|
|
29
|
+
"@docusaurus/logger": "0.0.0-5024",
|
|
30
|
+
"@docusaurus/mdx-loader": "0.0.0-5024",
|
|
31
|
+
"@docusaurus/utils": "0.0.0-5024",
|
|
32
|
+
"@docusaurus/utils-validation": "0.0.0-5024",
|
|
33
33
|
"combine-promises": "^1.1.0",
|
|
34
34
|
"fs-extra": "^10.1.0",
|
|
35
35
|
"import-fresh": "^3.3.0",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"webpack": "^5.72.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
45
|
-
"@docusaurus/types": "0.0.0-
|
|
44
|
+
"@docusaurus/module-type-aliases": "0.0.0-5024",
|
|
45
|
+
"@docusaurus/types": "0.0.0-5024",
|
|
46
46
|
"@types/js-yaml": "^4.0.5",
|
|
47
47
|
"@types/picomatch": "^2.3.0",
|
|
48
48
|
"commander": "^5.1.0",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=14"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "9d61f0a1f0c1121d25211afbb0fc45a92ca3b2ec"
|
|
62
62
|
}
|