@docusaurus/plugin-content-docs 0.0.0-4547 → 0.0.0-4551
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/cli.js +2 -1
- package/lib/client/index.d.ts +13 -1
- package/lib/client/index.js +66 -1
- package/lib/{server/index.d.ts → server-export.d.ts} +2 -2
- package/lib/{server/index.js → server-export.js} +7 -4
- package/lib/sidebars/generator.js +6 -7
- package/lib/sidebars/index.d.ts +3 -6
- package/lib/sidebars/index.js +8 -18
- package/lib/sidebars/normalization.d.ts +2 -3
- package/lib/sidebars/normalization.js +14 -32
- package/lib/sidebars/postProcessor.d.ts +8 -0
- package/lib/sidebars/postProcessor.js +71 -0
- package/lib/sidebars/processor.d.ts +2 -14
- package/lib/sidebars/processor.js +17 -55
- package/lib/sidebars/types.d.ts +24 -6
- package/lib/sidebars/utils.js +0 -1
- package/lib/sidebars/validation.d.ts +2 -2
- package/lib/sidebars/validation.js +12 -27
- package/lib/types.d.ts +2 -6
- package/package.json +10 -10
- package/src/cli.ts +3 -2
- package/src/client/index.ts +97 -1
- package/src/{server/index.ts → server-export.ts} +7 -2
- package/src/sidebars/README.md +9 -0
- package/src/sidebars/generator.ts +25 -22
- package/src/sidebars/index.ts +15 -31
- package/src/sidebars/normalization.ts +18 -46
- package/src/sidebars/postProcessor.ts +94 -0
- package/src/sidebars/processor.ts +26 -90
- package/src/sidebars/types.ts +32 -8
- package/src/sidebars/utils.ts +0 -1
- package/src/sidebars/validation.ts +38 -50
- package/src/types.ts +2 -10
- package/lib/client/globalDataHooks.d.ts +0 -19
- package/lib/client/globalDataHooks.js +0 -77
- package/src/client/globalDataHooks.ts +0 -108
|
@@ -1,108 +0,0 @@
|
|
|
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 {useLocation} from '@docusaurus/router';
|
|
9
|
-
import useGlobalData, {
|
|
10
|
-
// useAllPluginInstancesData,
|
|
11
|
-
usePluginData,
|
|
12
|
-
} from '@docusaurus/useGlobalData';
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
getActivePlugin,
|
|
16
|
-
getLatestVersion,
|
|
17
|
-
getActiveVersion,
|
|
18
|
-
getActiveDocContext,
|
|
19
|
-
getDocVersionSuggestions,
|
|
20
|
-
} from './docsClientUtils';
|
|
21
|
-
import type {
|
|
22
|
-
GlobalPluginData,
|
|
23
|
-
GlobalVersion,
|
|
24
|
-
ActivePlugin,
|
|
25
|
-
ActiveDocContext,
|
|
26
|
-
DocVersionSuggestions,
|
|
27
|
-
GetActivePluginOptions,
|
|
28
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
29
|
-
|
|
30
|
-
// Important to use a constant object to avoid React useEffect executions etc.
|
|
31
|
-
// see https://github.com/facebook/docusaurus/issues/5089
|
|
32
|
-
const StableEmptyObject = {};
|
|
33
|
-
|
|
34
|
-
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
|
|
35
|
-
// are still used by the theme. We need a fail-safe fallback when the docs
|
|
36
|
-
// plugin is not in use
|
|
37
|
-
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
|
38
|
-
// useAllPluginInstancesData('docusaurus-plugin-content-docs');
|
|
39
|
-
useGlobalData()['docusaurus-plugin-content-docs'] ?? StableEmptyObject;
|
|
40
|
-
|
|
41
|
-
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
|
42
|
-
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
|
|
43
|
-
|
|
44
|
-
// TODO this feature should be provided by docusaurus core
|
|
45
|
-
export const useActivePlugin = (
|
|
46
|
-
options: GetActivePluginOptions = {},
|
|
47
|
-
): ActivePlugin | undefined => {
|
|
48
|
-
const data = useAllDocsData();
|
|
49
|
-
const {pathname} = useLocation();
|
|
50
|
-
return getActivePlugin(data, pathname, options);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const useActivePluginAndVersion = (
|
|
54
|
-
options: GetActivePluginOptions = {},
|
|
55
|
-
):
|
|
56
|
-
| undefined
|
|
57
|
-
| {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined} => {
|
|
58
|
-
const activePlugin = useActivePlugin(options);
|
|
59
|
-
const {pathname} = useLocation();
|
|
60
|
-
if (activePlugin) {
|
|
61
|
-
const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
|
|
62
|
-
return {
|
|
63
|
-
activePlugin,
|
|
64
|
-
activeVersion,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return undefined;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// versions are returned ordered (most recent first)
|
|
71
|
-
export const useVersions = (pluginId: string | undefined): GlobalVersion[] => {
|
|
72
|
-
const data = useDocsData(pluginId);
|
|
73
|
-
return data.versions;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const useLatestVersion = (
|
|
77
|
-
pluginId: string | undefined,
|
|
78
|
-
): GlobalVersion => {
|
|
79
|
-
const data = useDocsData(pluginId);
|
|
80
|
-
return getLatestVersion(data);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// Note: return undefined on doc-unrelated pages,
|
|
84
|
-
// because there's no version currently considered as active
|
|
85
|
-
export const useActiveVersion = (
|
|
86
|
-
pluginId: string | undefined,
|
|
87
|
-
): GlobalVersion | undefined => {
|
|
88
|
-
const data = useDocsData(pluginId);
|
|
89
|
-
const {pathname} = useLocation();
|
|
90
|
-
return getActiveVersion(data, pathname);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const useActiveDocContext = (
|
|
94
|
-
pluginId: string | undefined,
|
|
95
|
-
): ActiveDocContext => {
|
|
96
|
-
const data = useDocsData(pluginId);
|
|
97
|
-
const {pathname} = useLocation();
|
|
98
|
-
return getActiveDocContext(data, pathname);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// Useful to say "hey, you are not on the latest docs version, please switch"
|
|
102
|
-
export const useDocVersionSuggestions = (
|
|
103
|
-
pluginId: string | undefined,
|
|
104
|
-
): DocVersionSuggestions => {
|
|
105
|
-
const data = useDocsData(pluginId);
|
|
106
|
-
const {pathname} = useLocation();
|
|
107
|
-
return getDocVersionSuggestions(data, pathname);
|
|
108
|
-
};
|