@docusaurus/plugin-content-docs 3.4.0 → 3.5.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 +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/client/docsSearch.test.d.ts +7 -0
- 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 +0 -1
- package/lib/docs.js +8 -8
- 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 +3 -2
- package/lib/numberPrefix.d.ts +0 -1
- package/lib/numberPrefix.js +3 -3
- package/lib/options.d.ts +0 -1
- package/lib/options.js +4 -2
- package/lib/props.d.ts +0 -1
- package/lib/props.js +5 -6
- package/lib/routes.d.ts +0 -1
- package/lib/routes.js +2 -3
- 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 +0 -1
- package/lib/versions/files.d.ts +0 -1
- package/lib/versions/files.js +7 -8
- package/lib/versions/index.d.ts +0 -1
- package/lib/versions/index.js +8 -9
- 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/index.ts +2 -0
- package/src/options.ts +3 -0
- 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
|
@@ -0,0 +1,273 @@
|
|
|
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 { useMemo } from 'react';
|
|
8
|
+
import { matchPath, useLocation } from '@docusaurus/router';
|
|
9
|
+
import renderRoutes from '@docusaurus/renderRoutes';
|
|
10
|
+
import { useActivePlugin, useActiveDocContext, useLatestVersion, } from '@docusaurus/plugin-content-docs/client';
|
|
11
|
+
import { isSamePath } from '@docusaurus/theme-common/internal';
|
|
12
|
+
import { uniq } from '@docusaurus/theme-common';
|
|
13
|
+
import { useDocsPreferredVersion } from './docsPreferredVersion';
|
|
14
|
+
import { useDocsVersion } from './docsVersion';
|
|
15
|
+
import { useDocsSidebar } from './docsSidebar';
|
|
16
|
+
export function useDocById(id) {
|
|
17
|
+
const version = useDocsVersion();
|
|
18
|
+
if (!id) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const doc = version.docs[id];
|
|
22
|
+
if (!doc) {
|
|
23
|
+
throw new Error(`no version doc found by id=${id}`);
|
|
24
|
+
}
|
|
25
|
+
return doc;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Pure function, similar to `Array#find`, but works on the sidebar tree.
|
|
29
|
+
*/
|
|
30
|
+
export function findSidebarCategory(sidebar, predicate) {
|
|
31
|
+
for (const item of sidebar) {
|
|
32
|
+
if (item.type === 'category') {
|
|
33
|
+
if (predicate(item)) {
|
|
34
|
+
return item;
|
|
35
|
+
}
|
|
36
|
+
const subItem = findSidebarCategory(item.items, predicate);
|
|
37
|
+
if (subItem) {
|
|
38
|
+
return subItem;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Best effort to assign a link to a sidebar category. If the category doesn't
|
|
46
|
+
* have a link itself, we link to the first sub item with a link.
|
|
47
|
+
*/
|
|
48
|
+
export function findFirstSidebarItemCategoryLink(item) {
|
|
49
|
+
if (item.href && !item.linkUnlisted) {
|
|
50
|
+
return item.href;
|
|
51
|
+
}
|
|
52
|
+
for (const subItem of item.items) {
|
|
53
|
+
const link = findFirstSidebarItemLink(subItem);
|
|
54
|
+
if (link) {
|
|
55
|
+
return link;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Best effort to assign a link to a sidebar item.
|
|
62
|
+
*/
|
|
63
|
+
export function findFirstSidebarItemLink(item) {
|
|
64
|
+
if (item.type === 'link' && !item.unlisted) {
|
|
65
|
+
return item.href;
|
|
66
|
+
}
|
|
67
|
+
if (item.type === 'category') {
|
|
68
|
+
return findFirstSidebarItemCategoryLink(item);
|
|
69
|
+
}
|
|
70
|
+
// Other items types, like "html"
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets the category associated with the current location. Should only be used
|
|
75
|
+
* on category index pages.
|
|
76
|
+
*/
|
|
77
|
+
export function useCurrentSidebarCategory() {
|
|
78
|
+
const { pathname } = useLocation();
|
|
79
|
+
const sidebar = useDocsSidebar();
|
|
80
|
+
if (!sidebar) {
|
|
81
|
+
throw new Error('Unexpected: cant find current sidebar in context');
|
|
82
|
+
}
|
|
83
|
+
const categoryBreadcrumbs = getSidebarBreadcrumbs({
|
|
84
|
+
sidebarItems: sidebar.items,
|
|
85
|
+
pathname,
|
|
86
|
+
onlyCategories: true,
|
|
87
|
+
});
|
|
88
|
+
const deepestCategory = categoryBreadcrumbs.slice(-1)[0];
|
|
89
|
+
if (!deepestCategory) {
|
|
90
|
+
throw new Error(`${pathname} is not associated with a category. useCurrentSidebarCategory() should only be used on category index pages.`);
|
|
91
|
+
}
|
|
92
|
+
return deepestCategory;
|
|
93
|
+
}
|
|
94
|
+
const isActive = (testedPath, activePath) => typeof testedPath !== 'undefined' && isSamePath(testedPath, activePath);
|
|
95
|
+
const containsActiveSidebarItem = (items, activePath) => items.some((subItem) => isActiveSidebarItem(subItem, activePath));
|
|
96
|
+
/**
|
|
97
|
+
* Checks if a sidebar item should be active, based on the active path.
|
|
98
|
+
*/
|
|
99
|
+
export function isActiveSidebarItem(item, activePath) {
|
|
100
|
+
if (item.type === 'link') {
|
|
101
|
+
return isActive(item.href, activePath);
|
|
102
|
+
}
|
|
103
|
+
if (item.type === 'category') {
|
|
104
|
+
return (isActive(item.href, activePath) ||
|
|
105
|
+
containsActiveSidebarItem(item.items, activePath));
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
export function isVisibleSidebarItem(item, activePath) {
|
|
110
|
+
switch (item.type) {
|
|
111
|
+
case 'category':
|
|
112
|
+
return (isActiveSidebarItem(item, activePath) ||
|
|
113
|
+
item.items.some((subItem) => isVisibleSidebarItem(subItem, activePath)));
|
|
114
|
+
case 'link':
|
|
115
|
+
// An unlisted item remains visible if it is active
|
|
116
|
+
return !item.unlisted || isActiveSidebarItem(item, activePath);
|
|
117
|
+
default:
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function useVisibleSidebarItems(items, activePath) {
|
|
122
|
+
return useMemo(() => items.filter((item) => isVisibleSidebarItem(item, activePath)), [items, activePath]);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the sidebar the breadcrumbs for a given pathname
|
|
126
|
+
* Ordered from top to bottom
|
|
127
|
+
*/
|
|
128
|
+
function getSidebarBreadcrumbs({ sidebarItems, pathname, onlyCategories = false, }) {
|
|
129
|
+
const breadcrumbs = [];
|
|
130
|
+
function extract(items) {
|
|
131
|
+
for (const item of items) {
|
|
132
|
+
if ((item.type === 'category' &&
|
|
133
|
+
(isSamePath(item.href, pathname) || extract(item.items))) ||
|
|
134
|
+
(item.type === 'link' && isSamePath(item.href, pathname))) {
|
|
135
|
+
const filtered = onlyCategories && item.type !== 'category';
|
|
136
|
+
if (!filtered) {
|
|
137
|
+
breadcrumbs.unshift(item);
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
extract(sidebarItems);
|
|
145
|
+
return breadcrumbs;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Gets the breadcrumbs of the current doc page, based on its sidebar location.
|
|
149
|
+
* Returns `null` if there's no sidebar or breadcrumbs are disabled.
|
|
150
|
+
*/
|
|
151
|
+
export function useSidebarBreadcrumbs() {
|
|
152
|
+
const sidebar = useDocsSidebar();
|
|
153
|
+
const { pathname } = useLocation();
|
|
154
|
+
const breadcrumbsOption = useActivePlugin()?.pluginData.breadcrumbs;
|
|
155
|
+
if (breadcrumbsOption === false || !sidebar) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return getSidebarBreadcrumbs({ sidebarItems: sidebar.items, pathname });
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* "Version candidates" are mostly useful for the layout components, which must
|
|
162
|
+
* be able to work on all pages. For example, if a user has `{ type: "doc",
|
|
163
|
+
* docId: "intro" }` as a navbar item, which version does that refer to? We
|
|
164
|
+
* believe that it could refer to at most three version candidates:
|
|
165
|
+
*
|
|
166
|
+
* 1. The **active version**, the one that the user is currently browsing. See
|
|
167
|
+
* {@link useActiveDocContext}.
|
|
168
|
+
* 2. The **preferred version**, the one that the user last visited. See
|
|
169
|
+
* {@link useDocsPreferredVersion}.
|
|
170
|
+
* 3. The **latest version**, the "default". See {@link useLatestVersion}.
|
|
171
|
+
*
|
|
172
|
+
* @param docsPluginId The plugin ID to get versions from.
|
|
173
|
+
* @returns An array of 1~3 versions with priorities defined above, guaranteed
|
|
174
|
+
* to be unique and non-sparse. Will be memoized, hence stable for deps array.
|
|
175
|
+
*/
|
|
176
|
+
export function useDocsVersionCandidates(docsPluginId) {
|
|
177
|
+
const { activeVersion } = useActiveDocContext(docsPluginId);
|
|
178
|
+
const { preferredVersion } = useDocsPreferredVersion(docsPluginId);
|
|
179
|
+
const latestVersion = useLatestVersion(docsPluginId);
|
|
180
|
+
return useMemo(() => uniq([activeVersion, preferredVersion, latestVersion].filter(Boolean)), [activeVersion, preferredVersion, latestVersion]);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The layout components, like navbar items, must be able to work on all pages,
|
|
184
|
+
* even on non-doc ones where there's no version context, so a sidebar ID could
|
|
185
|
+
* be ambiguous. This hook would always return a sidebar to be linked to. See
|
|
186
|
+
* also {@link useDocsVersionCandidates} for how this selection is done.
|
|
187
|
+
*
|
|
188
|
+
* @throws This hook throws if a sidebar with said ID is not found.
|
|
189
|
+
*/
|
|
190
|
+
export function useLayoutDocsSidebar(sidebarId, docsPluginId) {
|
|
191
|
+
const versions = useDocsVersionCandidates(docsPluginId);
|
|
192
|
+
return useMemo(() => {
|
|
193
|
+
const allSidebars = versions.flatMap((version) => version.sidebars ? Object.entries(version.sidebars) : []);
|
|
194
|
+
const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
|
|
195
|
+
if (!sidebarEntry) {
|
|
196
|
+
throw new Error(`Can't find any sidebar with id "${sidebarId}" in version${versions.length > 1 ? 's' : ''} ${versions.map((version) => version.name).join(', ')}".
|
|
197
|
+
Available sidebar ids are:
|
|
198
|
+
- ${allSidebars.map((entry) => entry[0]).join('\n- ')}`);
|
|
199
|
+
}
|
|
200
|
+
return sidebarEntry[1];
|
|
201
|
+
}, [sidebarId, versions]);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The layout components, like navbar items, must be able to work on all pages,
|
|
205
|
+
* even on non-doc ones where there's no version context, so a doc ID could be
|
|
206
|
+
* ambiguous. This hook would always return a doc to be linked to. See also
|
|
207
|
+
* {@link useDocsVersionCandidates} for how this selection is done.
|
|
208
|
+
*
|
|
209
|
+
* @throws This hook throws if a doc with said ID is not found.
|
|
210
|
+
*/
|
|
211
|
+
export function useLayoutDoc(docId, docsPluginId) {
|
|
212
|
+
const versions = useDocsVersionCandidates(docsPluginId);
|
|
213
|
+
return useMemo(() => {
|
|
214
|
+
const allDocs = versions.flatMap((version) => version.docs);
|
|
215
|
+
const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
|
|
216
|
+
if (!doc) {
|
|
217
|
+
const isDraft = versions
|
|
218
|
+
.flatMap((version) => version.draftIds)
|
|
219
|
+
.includes(docId);
|
|
220
|
+
// Drafts should be silently filtered instead of throwing
|
|
221
|
+
if (isDraft) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
throw new Error(`Couldn't find any doc with id "${docId}" in version${versions.length > 1 ? 's' : ''} "${versions.map((version) => version.name).join(', ')}".
|
|
225
|
+
Available doc ids are:
|
|
226
|
+
- ${uniq(allDocs.map((versionDoc) => versionDoc.id)).join('\n- ')}`);
|
|
227
|
+
}
|
|
228
|
+
return doc;
|
|
229
|
+
}, [docId, versions]);
|
|
230
|
+
}
|
|
231
|
+
// TODO later read version/route directly from context
|
|
232
|
+
/**
|
|
233
|
+
* The docs plugin creates nested routes, with the top-level route providing the
|
|
234
|
+
* version metadata, and the subroutes creating individual doc pages. This hook
|
|
235
|
+
* will match the current location against all known sub-routes.
|
|
236
|
+
*
|
|
237
|
+
* @param props The props received by `@theme/DocRoot`
|
|
238
|
+
* @returns The data of the relevant document at the current location, or `null`
|
|
239
|
+
* if no document associated with the current location can be found.
|
|
240
|
+
*/
|
|
241
|
+
export function useDocRootMetadata({ route }) {
|
|
242
|
+
const location = useLocation();
|
|
243
|
+
const versionMetadata = useDocsVersion();
|
|
244
|
+
const docRoutes = route.routes;
|
|
245
|
+
const currentDocRoute = docRoutes.find((docRoute) => matchPath(location.pathname, docRoute));
|
|
246
|
+
if (!currentDocRoute) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
// For now, the sidebarName is added as route config: not ideal!
|
|
250
|
+
const sidebarName = currentDocRoute.sidebar;
|
|
251
|
+
const sidebarItems = sidebarName
|
|
252
|
+
? versionMetadata.docsSidebars[sidebarName]
|
|
253
|
+
: undefined;
|
|
254
|
+
const docElement = renderRoutes(docRoutes);
|
|
255
|
+
return {
|
|
256
|
+
docElement,
|
|
257
|
+
sidebarName,
|
|
258
|
+
sidebarItems,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Filter items we don't want to display on the doc card list view
|
|
263
|
+
* @param items
|
|
264
|
+
*/
|
|
265
|
+
export function filterDocCardListItems(items) {
|
|
266
|
+
return items.filter((item) => {
|
|
267
|
+
const canHaveLink = item.type === 'category' || item.type === 'link';
|
|
268
|
+
if (canHaveLink) {
|
|
269
|
+
return !!findFirstSidebarItemLink(item);
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 ReactNode } from 'react';
|
|
8
|
+
import type { PropVersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
/**
|
|
10
|
+
* Provide the current version's metadata to your children.
|
|
11
|
+
*/
|
|
12
|
+
export declare function DocsVersionProvider({ children, version, }: {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
version: PropVersionMetadata | null;
|
|
15
|
+
}): JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the version metadata of the current doc page.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useDocsVersion(): PropVersionMetadata;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 React, { useContext } from 'react';
|
|
8
|
+
import { ReactContextError } from '@docusaurus/theme-common/internal';
|
|
9
|
+
const Context = React.createContext(null);
|
|
10
|
+
/**
|
|
11
|
+
* Provide the current version's metadata to your children.
|
|
12
|
+
*/
|
|
13
|
+
export function DocsVersionProvider({ children, version, }) {
|
|
14
|
+
return <Context.Provider value={version}>{children}</Context.Provider>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets the version metadata of the current doc page.
|
|
18
|
+
*/
|
|
19
|
+
export function useDocsVersion() {
|
|
20
|
+
const version = useContext(Context);
|
|
21
|
+
if (version === null) {
|
|
22
|
+
throw new ReactContextError('DocsVersionProvider');
|
|
23
|
+
}
|
|
24
|
+
return version;
|
|
25
|
+
}
|
package/lib/client/index.d.ts
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { UseDataOptions } from '@docusaurus/types';
|
|
8
|
+
export { useDocById, findSidebarCategory, findFirstSidebarItemLink, isActiveSidebarItem, isVisibleSidebarItem, useVisibleSidebarItems, useSidebarBreadcrumbs, useDocsVersionCandidates, useLayoutDoc, useLayoutDocsSidebar, useDocRootMetadata, useCurrentSidebarCategory, filterDocCardListItems, } from './docsUtils';
|
|
9
|
+
export { useDocsPreferredVersion } from './docsPreferredVersion';
|
|
10
|
+
export { DocSidebarItemsExpandedStateProvider, useDocSidebarItemsExpandedState, } from './docSidebarItemsExpandedState';
|
|
11
|
+
export { DocsVersionProvider, useDocsVersion } from './docsVersion';
|
|
12
|
+
export { DocsSidebarProvider, useDocsSidebar } from './docsSidebar';
|
|
13
|
+
export { DocProvider, useDoc, type DocContextValue } from './doc';
|
|
14
|
+
export { useDocsPreferredVersionByPluginId, DocsPreferredVersionContextProvider, } from './docsPreferredVersion';
|
|
15
|
+
export { useDocsContextualSearchTags, getDocsVersionSearchTag, } from './docsSearch';
|
|
8
16
|
export type ActivePlugin = {
|
|
9
17
|
pluginId: string;
|
|
10
18
|
pluginData: GlobalPluginData;
|
package/lib/client/index.js
CHANGED
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
import { useLocation } from '@docusaurus/router';
|
|
8
8
|
import { useAllPluginInstancesData, usePluginData, } from '@docusaurus/useGlobalData';
|
|
9
9
|
import { getActivePlugin, getLatestVersion, getActiveVersion, getActiveDocContext, getDocVersionSuggestions, } from './docsClientUtils';
|
|
10
|
+
export { useDocById, findSidebarCategory, findFirstSidebarItemLink, isActiveSidebarItem, isVisibleSidebarItem, useVisibleSidebarItems, useSidebarBreadcrumbs, useDocsVersionCandidates, useLayoutDoc, useLayoutDocsSidebar, useDocRootMetadata, useCurrentSidebarCategory, filterDocCardListItems, } from './docsUtils';
|
|
11
|
+
export { useDocsPreferredVersion } from './docsPreferredVersion';
|
|
12
|
+
export { DocSidebarItemsExpandedStateProvider, useDocSidebarItemsExpandedState, } from './docSidebarItemsExpandedState';
|
|
13
|
+
export { DocsVersionProvider, useDocsVersion } from './docsVersion';
|
|
14
|
+
export { DocsSidebarProvider, useDocsSidebar } from './docsSidebar';
|
|
15
|
+
export { DocProvider, useDoc } from './doc';
|
|
16
|
+
export { useDocsPreferredVersionByPluginId, DocsPreferredVersionContextProvider, } from './docsPreferredVersion';
|
|
17
|
+
export { useDocsContextualSearchTags, getDocsVersionSearchTag, } from './docsSearch';
|
|
10
18
|
// Important to use a constant object to avoid React useEffect executions etc.
|
|
11
19
|
// see https://github.com/facebook/docusaurus/issues/5089
|
|
12
20
|
const StableEmptyObject = {};
|
package/lib/docs.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 { TagsFile } from '@docusaurus/utils';
|
|
9
8
|
import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
|
|
10
9
|
import type { LoadContext } from '@docusaurus/types';
|
package/lib/docs.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.isCategoryIndex = void 0;
|
|
10
|
+
exports.readDocFile = readDocFile;
|
|
11
|
+
exports.readVersionDocs = readVersionDocs;
|
|
12
|
+
exports.processDocMetadata = processDocMetadata;
|
|
13
|
+
exports.addDocNavigation = addDocNavigation;
|
|
14
|
+
exports.getMainDocId = getMainDocId;
|
|
15
|
+
exports.toCategoryIndexMatcherParam = toCategoryIndexMatcherParam;
|
|
16
|
+
exports.createDocsByIdIndex = createDocsByIdIndex;
|
|
10
17
|
const tslib_1 = require("tslib");
|
|
11
18
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
19
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
@@ -22,7 +29,6 @@ async function readDocFile(versionMetadata, source) {
|
|
|
22
29
|
const content = await fs_extra_1.default.readFile(filePath, 'utf-8');
|
|
23
30
|
return { source, content, contentPath, filePath };
|
|
24
31
|
}
|
|
25
|
-
exports.readDocFile = readDocFile;
|
|
26
32
|
async function readVersionDocs(versionMetadata, options) {
|
|
27
33
|
const sources = await (0, utils_1.Globby)(options.include, {
|
|
28
34
|
cwd: versionMetadata.contentPath,
|
|
@@ -30,7 +36,6 @@ async function readVersionDocs(versionMetadata, options) {
|
|
|
30
36
|
});
|
|
31
37
|
return Promise.all(sources.map((source) => readDocFile(versionMetadata, source)));
|
|
32
38
|
}
|
|
33
|
-
exports.readVersionDocs = readVersionDocs;
|
|
34
39
|
async function doProcessDocMetadata({ docFile, versionMetadata, context, options, env, tagsFile, }) {
|
|
35
40
|
const { source, content, contentPath, filePath } = docFile;
|
|
36
41
|
const { siteDir, siteConfig: { markdown: { parseFrontMatter }, }, } = context;
|
|
@@ -146,7 +151,6 @@ async function processDocMetadata(args) {
|
|
|
146
151
|
throw new Error(`Can't process doc metadata for doc at path path=${args.docFile.filePath} in version name=${args.versionMetadata.versionName}`, { cause: err });
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
|
-
exports.processDocMetadata = processDocMetadata;
|
|
150
154
|
function getUnlistedIds(docs) {
|
|
151
155
|
return new Set(docs.filter((doc) => doc.unlisted).map((doc) => doc.id));
|
|
152
156
|
}
|
|
@@ -188,7 +192,6 @@ function addDocNavigation({ docs, sidebarsUtils, }) {
|
|
|
188
192
|
docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
|
|
189
193
|
return docsWithNavigation;
|
|
190
194
|
}
|
|
191
|
-
exports.addDocNavigation = addDocNavigation;
|
|
192
195
|
/**
|
|
193
196
|
* The "main doc" is the "version entry point"
|
|
194
197
|
* We browse this doc by clicking on a version:
|
|
@@ -210,7 +213,6 @@ function getMainDocId({ docs, sidebarsUtils, }) {
|
|
|
210
213
|
}
|
|
211
214
|
return getMainDoc().id;
|
|
212
215
|
}
|
|
213
|
-
exports.getMainDocId = getMainDocId;
|
|
214
216
|
// By convention, Docusaurus considers some docs are "indexes":
|
|
215
217
|
// - index.md
|
|
216
218
|
// - readme.md
|
|
@@ -242,9 +244,7 @@ function toCategoryIndexMatcherParam({ source, sourceDirName, }) {
|
|
|
242
244
|
directories: sourceDirName.split(path_1.default.posix.sep).reverse(),
|
|
243
245
|
};
|
|
244
246
|
}
|
|
245
|
-
exports.toCategoryIndexMatcherParam = toCategoryIndexMatcherParam;
|
|
246
247
|
// Docs are indexed by their id
|
|
247
248
|
function createDocsByIdIndex(docs) {
|
|
248
249
|
return lodash_1.default.keyBy(docs, (d) => d.id);
|
|
249
250
|
}
|
|
250
|
-
exports.createDocsByIdIndex = createDocsByIdIndex;
|
package/lib/frontMatter.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference path="../src/plugin-content-docs.d.ts" />
|
|
2
1
|
import type { DocFrontMatter } from '@docusaurus/plugin-content-docs';
|
|
3
2
|
export declare const DocFrontMatterSchema: import("joi").ObjectSchema<DocFrontMatter>;
|
|
4
3
|
export declare function validateDocFrontMatter(frontMatter: {
|
package/lib/frontMatter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DocFrontMatterSchema = void 0;
|
|
4
|
+
exports.validateDocFrontMatter = validateDocFrontMatter;
|
|
4
5
|
/**
|
|
5
6
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
7
|
*
|
|
@@ -42,4 +43,3 @@ exports.DocFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
42
43
|
function validateDocFrontMatter(frontMatter) {
|
|
43
44
|
return (0, utils_validation_1.validateFrontMatter)(frontMatter, exports.DocFrontMatterSchema);
|
|
44
45
|
}
|
|
45
|
-
exports.validateDocFrontMatter = validateDocFrontMatter;
|
package/lib/globalData.js
CHANGED
|
@@ -6,7 +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.toGlobalDataVersion =
|
|
9
|
+
exports.toGlobalDataVersion = toGlobalDataVersion;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const docs_1 = require("./docs");
|
|
@@ -57,4 +57,3 @@ function toGlobalDataVersion(version) {
|
|
|
57
57
|
sidebars: toGlobalSidebars(version.sidebars, version),
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
exports.toGlobalDataVersion = toGlobalDataVersion;
|
package/lib/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 { PluginOptions, LoadedContent } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
10
9
|
export default function pluginContentDocs(context: LoadContext, options: PluginOptions): Promise<Plugin<LoadedContent>>;
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateOptions = void 0;
|
|
10
|
+
exports.default = pluginContentDocs;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
13
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
@@ -190,7 +191,7 @@ async function pluginContentDocs(context, options) {
|
|
|
190
191
|
});
|
|
191
192
|
},
|
|
192
193
|
configureWebpack(_config, isServer, utils, content) {
|
|
193
|
-
const { rehypePlugins, remarkPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
|
|
194
|
+
const { rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
|
|
194
195
|
const contentDirs = versionsMetadata
|
|
195
196
|
.flatMap(utils_1.getContentPathList)
|
|
196
197
|
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
@@ -200,6 +201,7 @@ async function pluginContentDocs(context, options) {
|
|
|
200
201
|
admonitions: options.admonitions,
|
|
201
202
|
remarkPlugins,
|
|
202
203
|
rehypePlugins,
|
|
204
|
+
recmaPlugins,
|
|
203
205
|
beforeDefaultRehypePlugins,
|
|
204
206
|
beforeDefaultRemarkPlugins,
|
|
205
207
|
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
@@ -260,6 +262,5 @@ async function pluginContentDocs(context, options) {
|
|
|
260
262
|
},
|
|
261
263
|
};
|
|
262
264
|
}
|
|
263
|
-
exports.default = pluginContentDocs;
|
|
264
265
|
var options_1 = require("./options");
|
|
265
266
|
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
|
package/lib/numberPrefix.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 } from '@docusaurus/plugin-content-docs';
|
|
9
8
|
export declare const DefaultNumberPrefixParser: NumberPrefixParser;
|
|
10
9
|
export declare const DisabledNumberPrefixParser: NumberPrefixParser;
|
package/lib/numberPrefix.js
CHANGED
|
@@ -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.DisabledNumberPrefixParser = exports.DefaultNumberPrefixParser = void 0;
|
|
10
|
+
exports.stripNumberPrefix = stripNumberPrefix;
|
|
11
|
+
exports.stripPathNumberPrefixes = stripPathNumberPrefixes;
|
|
10
12
|
// Best-effort to avoid parsing some patterns as number prefix
|
|
11
13
|
// ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
|
|
12
14
|
// ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
|
|
@@ -39,7 +41,6 @@ exports.DisabledNumberPrefixParser = DisabledNumberPrefixParser;
|
|
|
39
41
|
function stripNumberPrefix(str, parser) {
|
|
40
42
|
return parser(str).filename;
|
|
41
43
|
}
|
|
42
|
-
exports.stripNumberPrefix = stripNumberPrefix;
|
|
43
44
|
// 0-myFolder/0-mySubfolder/0-myDoc => myFolder/mySubfolder/myDoc
|
|
44
45
|
function stripPathNumberPrefixes(path, parser) {
|
|
45
46
|
return path
|
|
@@ -47,4 +48,3 @@ function stripPathNumberPrefixes(path, parser) {
|
|
|
47
48
|
.map((segment) => stripNumberPrefix(segment, parser))
|
|
48
49
|
.join('/');
|
|
49
50
|
}
|
|
50
|
-
exports.stripPathNumberPrefixes = stripPathNumberPrefixes;
|
package/lib/options.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 { OptionValidationContext } from '@docusaurus/types';
|
|
9
8
|
import type { PluginOptions, Options } from '@docusaurus/plugin-content-docs';
|
|
10
9
|
export declare const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'>;
|
package/lib/options.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.DEFAULT_OPTIONS = void 0;
|
|
10
|
+
exports.validateOptions = validateOptions;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
13
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
@@ -30,6 +31,7 @@ exports.DEFAULT_OPTIONS = {
|
|
|
30
31
|
docCategoryGeneratedIndexComponent: '@theme/DocCategoryGeneratedIndexPage',
|
|
31
32
|
remarkPlugins: [],
|
|
32
33
|
rehypePlugins: [],
|
|
34
|
+
recmaPlugins: [],
|
|
33
35
|
beforeDefaultRemarkPlugins: [],
|
|
34
36
|
beforeDefaultRehypePlugins: [],
|
|
35
37
|
showLastUpdateTime: false,
|
|
@@ -91,6 +93,7 @@ const OptionsSchema = utils_validation_1.Joi.object({
|
|
|
91
93
|
docCategoryGeneratedIndexComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docCategoryGeneratedIndexComponent),
|
|
92
94
|
remarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.remarkPlugins),
|
|
93
95
|
rehypePlugins: utils_validation_1.RehypePluginsSchema.default(exports.DEFAULT_OPTIONS.rehypePlugins),
|
|
96
|
+
recmaPlugins: utils_validation_1.RecmaPluginsSchema.default(exports.DEFAULT_OPTIONS.recmaPlugins),
|
|
94
97
|
beforeDefaultRemarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRemarkPlugins),
|
|
95
98
|
beforeDefaultRehypePlugins: utils_validation_1.RehypePluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRehypePlugins),
|
|
96
99
|
admonitions: utils_validation_1.AdmonitionsSchema.default(exports.DEFAULT_OPTIONS.admonitions),
|
|
@@ -133,4 +136,3 @@ function validateOptions({ validate, options: userOptions, }) {
|
|
|
133
136
|
const normalizedOptions = validate(OptionsSchema, options);
|
|
134
137
|
return normalizedOptions;
|
|
135
138
|
}
|
|
136
|
-
exports.validateOptions = validateOptions;
|
package/lib/props.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 { VersionTag, VersionTags } from './types';
|
|
9
8
|
import type { SidebarItemDoc } from './sidebars/types';
|
|
10
9
|
import type { PropSidebars, PropVersionMetadata, PropTagDocList, PropTagsListPage, PropSidebarItemLink, DocMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
|
package/lib/props.js
CHANGED
|
@@ -6,7 +6,11 @@
|
|
|
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.toSidebarDocItemLinkProp = toSidebarDocItemLinkProp;
|
|
10
|
+
exports.toSidebarsProp = toSidebarsProp;
|
|
11
|
+
exports.toVersionMetadataProp = toVersionMetadataProp;
|
|
12
|
+
exports.toTagDocListProp = toTagDocListProp;
|
|
13
|
+
exports.toTagsListTagsProp = toTagsListTagsProp;
|
|
10
14
|
const tslib_1 = require("tslib");
|
|
11
15
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
16
|
const docs_1 = require("./docs");
|
|
@@ -22,7 +26,6 @@ function toSidebarDocItemLinkProp({ item, doc, }) {
|
|
|
22
26
|
unlisted,
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
|
-
exports.toSidebarDocItemLinkProp = toSidebarDocItemLinkProp;
|
|
26
29
|
function toSidebarsProp(loadedVersion) {
|
|
27
30
|
const docsById = (0, docs_1.createDocsByIdIndex)(loadedVersion.docs);
|
|
28
31
|
function getDocById(docId) {
|
|
@@ -92,7 +95,6 @@ Available document ids are:
|
|
|
92
95
|
// This is what will be passed as props to the UI component.
|
|
93
96
|
return lodash_1.default.mapValues(loadedVersion.sidebars, (items) => items.map(normalizeItem));
|
|
94
97
|
}
|
|
95
|
-
exports.toSidebarsProp = toSidebarsProp;
|
|
96
98
|
function toVersionDocsProp(loadedVersion) {
|
|
97
99
|
return Object.fromEntries(loadedVersion.docs.map((doc) => [
|
|
98
100
|
doc.id,
|
|
@@ -118,7 +120,6 @@ function toVersionMetadataProp(pluginId, loadedVersion) {
|
|
|
118
120
|
docs: toVersionDocsProp(loadedVersion),
|
|
119
121
|
};
|
|
120
122
|
}
|
|
121
|
-
exports.toVersionMetadataProp = toVersionMetadataProp;
|
|
122
123
|
function toTagDocListProp({ allTagsPath, tag, docs, }) {
|
|
123
124
|
function toDocListProp() {
|
|
124
125
|
const list = lodash_1.default.compact(tag.docIds.map((id) => docs.find((doc) => doc.id === id)));
|
|
@@ -141,7 +142,6 @@ function toTagDocListProp({ allTagsPath, tag, docs, }) {
|
|
|
141
142
|
unlisted: tag.unlisted,
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
|
-
exports.toTagDocListProp = toTagDocListProp;
|
|
145
145
|
function toTagsListTagsProp(versionTags) {
|
|
146
146
|
return Object.values(versionTags)
|
|
147
147
|
.filter((tagValue) => !tagValue.unlisted)
|
|
@@ -152,4 +152,3 @@ function toTagsListTagsProp(versionTags) {
|
|
|
152
152
|
count: tagValue.docIds.length,
|
|
153
153
|
}));
|
|
154
154
|
}
|
|
155
|
-
exports.toTagsListTagsProp = toTagsListTagsProp;
|
package/lib/routes.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 { PluginContentLoadedActions, RouteConfig } from '@docusaurus/types';
|
|
9
8
|
import type { FullVersion } from './types';
|
|
10
9
|
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
package/lib/routes.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.buildAllRoutes = buildAllRoutes;
|
|
10
|
+
exports.createAllRoutes = createAllRoutes;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
11
12
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
@@ -177,9 +178,7 @@ async function buildAllRoutes(param) {
|
|
|
177
178
|
},
|
|
178
179
|
];
|
|
179
180
|
}
|
|
180
|
-
exports.buildAllRoutes = buildAllRoutes;
|
|
181
181
|
async function createAllRoutes(param) {
|
|
182
182
|
const routes = await buildAllRoutes(param);
|
|
183
183
|
routes.forEach(param.actions.addRoute);
|
|
184
184
|
}
|
|
185
|
-
exports.createAllRoutes = createAllRoutes;
|