@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.
Files changed (90) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +0 -1
  2. package/lib/categoryGeneratedIndex.js +1 -2
  3. package/lib/cli.d.ts +0 -1
  4. package/lib/cli.js +1 -2
  5. package/lib/client/doc.d.ts +29 -0
  6. package/lib/client/doc.js +47 -0
  7. package/lib/client/docSidebarItemsExpandedState.d.ts +30 -0
  8. package/lib/client/docSidebarItemsExpandedState.js +27 -0
  9. package/lib/client/docsClientUtils.js +16 -8
  10. package/lib/client/docsPreferredVersion.d.ts +29 -0
  11. package/lib/client/docsPreferredVersion.js +124 -0
  12. package/lib/client/docsSearch.d.ts +19 -0
  13. package/lib/client/docsSearch.js +39 -0
  14. package/lib/{markdown/linkify.d.ts → client/docsSearch.test.d.ts} +1 -2
  15. package/lib/client/docsSearch.test.js +12 -0
  16. package/lib/client/docsSidebar.d.ts +25 -0
  17. package/lib/client/docsSidebar.js +29 -0
  18. package/lib/client/docsUtils.d.ts +106 -0
  19. package/lib/client/docsUtils.js +273 -0
  20. package/lib/client/docsVersion.d.ts +19 -0
  21. package/lib/client/docsVersion.js +25 -0
  22. package/lib/client/index.d.ts +8 -0
  23. package/lib/client/index.js +8 -0
  24. package/lib/docs.d.ts +2 -1
  25. package/lib/docs.js +17 -10
  26. package/lib/frontMatter.d.ts +0 -1
  27. package/lib/frontMatter.js +2 -2
  28. package/lib/globalData.js +1 -2
  29. package/lib/index.d.ts +0 -1
  30. package/lib/index.js +85 -55
  31. package/lib/numberPrefix.d.ts +0 -1
  32. package/lib/numberPrefix.js +3 -3
  33. package/lib/options.d.ts +0 -1
  34. package/lib/options.js +13 -2
  35. package/lib/props.d.ts +0 -1
  36. package/lib/props.js +7 -6
  37. package/lib/routes.d.ts +0 -1
  38. package/lib/routes.js +23 -7
  39. package/lib/sidebars/generator.js +3 -0
  40. package/lib/sidebars/index.d.ts +0 -1
  41. package/lib/sidebars/index.js +4 -4
  42. package/lib/sidebars/normalization.js +2 -3
  43. package/lib/sidebars/postProcessor.js +1 -2
  44. package/lib/sidebars/processor.js +1 -2
  45. package/lib/sidebars/types.d.ts +1 -1
  46. package/lib/sidebars/utils.d.ts +0 -1
  47. package/lib/sidebars/utils.js +13 -14
  48. package/lib/sidebars/validation.js +3 -3
  49. package/lib/slug.d.ts +0 -1
  50. package/lib/slug.js +1 -1
  51. package/lib/translations.d.ts +0 -1
  52. package/lib/translations.js +2 -3
  53. package/lib/types.d.ts +3 -14
  54. package/lib/versions/files.d.ts +0 -1
  55. package/lib/versions/files.js +7 -8
  56. package/lib/versions/index.d.ts +1 -1
  57. package/lib/versions/index.js +15 -8
  58. package/lib/versions/validation.d.ts +0 -1
  59. package/lib/versions/validation.js +3 -4
  60. package/package.json +11 -10
  61. package/src/client/doc.tsx +71 -0
  62. package/src/client/docSidebarItemsExpandedState.tsx +55 -0
  63. package/src/client/docsClientUtils.ts +17 -8
  64. package/src/client/docsPreferredVersion.tsx +248 -0
  65. package/src/client/docsSearch.test.ts +14 -0
  66. package/src/client/docsSearch.ts +57 -0
  67. package/src/client/docsSidebar.tsx +50 -0
  68. package/src/client/docsUtils.tsx +415 -0
  69. package/src/client/docsVersion.tsx +36 -0
  70. package/src/client/index.ts +39 -0
  71. package/src/docs.ts +14 -2
  72. package/src/index.ts +116 -73
  73. package/src/options.ts +12 -0
  74. package/src/plugin-content-docs.d.ts +4 -3
  75. package/src/props.ts +2 -0
  76. package/src/routes.ts +23 -4
  77. package/src/sidebars/generator.ts +3 -0
  78. package/src/sidebars/postProcessor.ts +1 -0
  79. package/src/sidebars/types.ts +1 -0
  80. package/src/sidebars/validation.ts +1 -0
  81. package/src/types.ts +2 -16
  82. package/src/versions/index.ts +18 -1
  83. package/lib/markdown/index.d.ts +0 -9
  84. package/lib/markdown/index.js +0 -16
  85. package/lib/markdown/linkify.js +0 -34
  86. package/lib/tags.d.ts +0 -10
  87. package/lib/tags.js +0 -28
  88. package/src/markdown/index.ts +0 -20
  89. package/src/markdown/linkify.ts +0 -47
  90. package/src/tags.ts +0 -27
@@ -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
+ }
@@ -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;
@@ -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,7 @@
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" />
7
+ import type { TagsFile } from '@docusaurus/utils';
8
8
  import type { MetadataOptions, PluginOptions, CategoryIndexMatcher, DocMetadataBase, VersionMetadata, LoadedVersion } from '@docusaurus/plugin-content-docs';
9
9
  import type { LoadContext } from '@docusaurus/types';
10
10
  import type { SidebarsUtils } from './sidebars/utils';
@@ -18,6 +18,7 @@ export declare function processDocMetadata(args: {
18
18
  context: LoadContext;
19
19
  options: MetadataOptions;
20
20
  env: DocEnv;
21
+ tagsFile: TagsFile | null;
21
22
  }): Promise<DocMetadataBase>;
22
23
  export declare function addDocNavigation({ docs, sidebarsUtils, }: {
23
24
  docs: DocMetadataBase[];
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.createDocsByIdIndex = exports.toCategoryIndexMatcherParam = exports.isCategoryIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
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,8 +36,7 @@ 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
- async function doProcessDocMetadata({ docFile, versionMetadata, context, options, env, }) {
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;
37
42
  const { frontMatter: unsafeFrontMatter, contentTitle, excerpt, } = await (0, utils_1.parseMarkdownFile)({
@@ -108,6 +113,13 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
108
113
  }
109
114
  const draft = (0, utils_1.isDraft)({ env, frontMatter });
110
115
  const unlisted = (0, utils_1.isUnlisted)({ env, frontMatter });
116
+ const tags = (0, utils_1.normalizeTags)({
117
+ options,
118
+ source,
119
+ frontMatterTags: frontMatter.tags,
120
+ tagsBaseRoutePath: versionMetadata.tagsPath,
121
+ tagsFile,
122
+ });
111
123
  // Assign all of object properties during instantiation (if possible) for
112
124
  // NodeJS optimization.
113
125
  // Adding properties to object after instantiation will cause hidden
@@ -123,7 +135,7 @@ async function doProcessDocMetadata({ docFile, versionMetadata, context, options
123
135
  draft,
124
136
  unlisted,
125
137
  editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
126
- tags: (0, utils_1.normalizeFrontMatterTags)(versionMetadata.tagsPath, frontMatter.tags),
138
+ tags,
127
139
  version: versionMetadata.versionName,
128
140
  lastUpdatedBy: lastUpdate.lastUpdatedBy,
129
141
  lastUpdatedAt: lastUpdate.lastUpdatedAt,
@@ -139,7 +151,6 @@ async function processDocMetadata(args) {
139
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 });
140
152
  }
141
153
  }
142
- exports.processDocMetadata = processDocMetadata;
143
154
  function getUnlistedIds(docs) {
144
155
  return new Set(docs.filter((doc) => doc.unlisted).map((doc) => doc.id));
145
156
  }
@@ -181,7 +192,6 @@ function addDocNavigation({ docs, sidebarsUtils, }) {
181
192
  docsWithNavigation.sort((a, b) => a.id.localeCompare(b.id));
182
193
  return docsWithNavigation;
183
194
  }
184
- exports.addDocNavigation = addDocNavigation;
185
195
  /**
186
196
  * The "main doc" is the "version entry point"
187
197
  * We browse this doc by clicking on a version:
@@ -203,7 +213,6 @@ function getMainDocId({ docs, sidebarsUtils, }) {
203
213
  }
204
214
  return getMainDoc().id;
205
215
  }
206
- exports.getMainDocId = getMainDocId;
207
216
  // By convention, Docusaurus considers some docs are "indexes":
208
217
  // - index.md
209
218
  // - readme.md
@@ -235,9 +244,7 @@ function toCategoryIndexMatcherParam({ source, sourceDirName, }) {
235
244
  directories: sourceDirName.split(path_1.default.posix.sep).reverse(),
236
245
  };
237
246
  }
238
- exports.toCategoryIndexMatcherParam = toCategoryIndexMatcherParam;
239
247
  // Docs are indexed by their id
240
248
  function createDocsByIdIndex(docs) {
241
249
  return lodash_1.default.keyBy(docs, (d) => d.id);
242
250
  }
243
- exports.createDocsByIdIndex = createDocsByIdIndex;
@@ -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: {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateDocFrontMatter = exports.DocFrontMatterSchema = void 0;
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 = void 0;
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>>;