@docusaurus/plugin-content-docs 2.0.0-beta.8e9b829d9 → 2.0.0-beta.9

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 (103) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/cli.d.ts +1 -1
  3. package/lib/cli.js +18 -23
  4. package/lib/client/docsClientUtils.d.ts +0 -3
  5. package/lib/client/docsClientUtils.js +10 -7
  6. package/lib/docFrontMatter.js +6 -2
  7. package/lib/docs.d.ts +3 -1
  8. package/lib/docs.js +76 -25
  9. package/lib/index.js +70 -77
  10. package/lib/lastUpdate.js +4 -4
  11. package/lib/markdown/index.d.ts +3 -6
  12. package/lib/markdown/index.js +3 -3
  13. package/lib/markdown/linkify.js +2 -2
  14. package/lib/options.js +12 -4
  15. package/lib/props.d.ts +7 -2
  16. package/lib/props.js +26 -3
  17. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +2 -1
  18. package/lib/sidebars/generator.js +174 -0
  19. package/lib/sidebars/index.d.ts +14 -0
  20. package/lib/sidebars/index.js +64 -0
  21. package/lib/sidebars/normalization.d.ts +9 -0
  22. package/lib/sidebars/normalization.js +58 -0
  23. package/lib/sidebars/processor.d.ts +16 -0
  24. package/lib/sidebars/processor.js +70 -0
  25. package/lib/sidebars/types.d.ts +87 -0
  26. package/lib/sidebars/types.js +13 -0
  27. package/lib/sidebars/utils.d.ts +22 -0
  28. package/lib/sidebars/utils.js +101 -0
  29. package/lib/sidebars/validation.d.ts +8 -0
  30. package/lib/sidebars/validation.js +102 -0
  31. package/lib/slug.js +4 -4
  32. package/lib/tags.d.ts +8 -0
  33. package/lib/tags.js +22 -0
  34. package/lib/theme/hooks/useDocs.js +21 -21
  35. package/lib/translations.d.ts +1 -1
  36. package/lib/translations.js +13 -13
  37. package/lib/types.d.ts +29 -61
  38. package/lib/versions.d.ts +1 -1
  39. package/lib/versions.js +40 -20
  40. package/package.json +15 -14
  41. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
  42. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +1 -0
  43. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
  44. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
  45. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
  46. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
  47. package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
  48. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
  49. package/src/__tests__/__snapshots__/cli.test.ts.snap +28 -0
  50. package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
  51. package/src/__tests__/__snapshots__/index.test.ts.snap +426 -25
  52. package/src/__tests__/docFrontMatter.test.ts +160 -45
  53. package/src/__tests__/docs.test.ts +167 -21
  54. package/src/__tests__/index.test.ts +53 -27
  55. package/src/__tests__/options.test.ts +4 -1
  56. package/src/__tests__/props.test.ts +62 -0
  57. package/src/__tests__/versions.test.ts +68 -63
  58. package/src/cli.ts +23 -30
  59. package/src/client/docsClientUtils.ts +1 -12
  60. package/src/docFrontMatter.ts +7 -2
  61. package/src/docs.ts +88 -9
  62. package/src/index.ts +77 -91
  63. package/src/markdown/index.ts +8 -12
  64. package/src/numberPrefix.ts +4 -2
  65. package/src/options.ts +13 -1
  66. package/src/plugin-content-docs.d.ts +107 -32
  67. package/src/props.ts +41 -5
  68. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
  69. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
  70. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
  71. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
  72. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
  73. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
  74. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
  75. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
  76. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
  77. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
  78. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
  79. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
  80. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
  81. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
  82. package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +6 -6
  83. package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +2 -2
  84. package/src/sidebars/__tests__/index.test.ts +202 -0
  85. package/src/sidebars/__tests__/processor.test.ts +148 -0
  86. package/src/sidebars/__tests__/utils.test.ts +395 -0
  87. package/src/sidebars/generator.ts +253 -0
  88. package/src/sidebars/index.ts +84 -0
  89. package/src/sidebars/normalization.ts +88 -0
  90. package/src/sidebars/processor.ts +124 -0
  91. package/src/sidebars/types.ts +156 -0
  92. package/src/sidebars/utils.ts +146 -0
  93. package/src/sidebars/validation.ts +124 -0
  94. package/src/tags.ts +21 -0
  95. package/src/translations.ts +26 -36
  96. package/src/types.ts +35 -101
  97. package/src/versions.ts +51 -21
  98. package/lib/sidebarItemsGenerator.js +0 -215
  99. package/lib/sidebars.d.ts +0 -45
  100. package/lib/sidebars.js +0 -354
  101. package/src/__tests__/sidebars.test.ts +0 -746
  102. package/src/sidebarItemsGenerator.ts +0 -315
  103. package/src/sidebars.ts +0 -589
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createSidebarsUtils = exports.collectSidebarsDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = void 0;
10
+ const lodash_1 = require("lodash");
11
+ const utils_1 = require("@docusaurus/utils");
12
+ function transformSidebarItems(sidebar, updateFn) {
13
+ function transformRecursive(item) {
14
+ if (item.type === 'category') {
15
+ return updateFn({
16
+ ...item,
17
+ items: item.items.map(transformRecursive),
18
+ });
19
+ }
20
+ return updateFn(item);
21
+ }
22
+ return sidebar.map(transformRecursive);
23
+ }
24
+ exports.transformSidebarItems = transformSidebarItems;
25
+ function collectSidebarItemsOfType(type, sidebar) {
26
+ function collectRecursive(item) {
27
+ const currentItemsCollected = item.type === type ? [item] : [];
28
+ const childItemsCollected = item.type === 'category' ? item.items.flatMap(collectRecursive) : [];
29
+ return [...currentItemsCollected, ...childItemsCollected];
30
+ }
31
+ return sidebar.flatMap(collectRecursive);
32
+ }
33
+ function collectSidebarDocItems(sidebar) {
34
+ return collectSidebarItemsOfType('doc', sidebar);
35
+ }
36
+ exports.collectSidebarDocItems = collectSidebarDocItems;
37
+ function collectSidebarCategories(sidebar) {
38
+ return collectSidebarItemsOfType('category', sidebar);
39
+ }
40
+ exports.collectSidebarCategories = collectSidebarCategories;
41
+ function collectSidebarLinks(sidebar) {
42
+ return collectSidebarItemsOfType('link', sidebar);
43
+ }
44
+ exports.collectSidebarLinks = collectSidebarLinks;
45
+ function collectSidebarsDocIds(sidebars) {
46
+ return (0, lodash_1.mapValues)(sidebars, (sidebar) => {
47
+ return collectSidebarDocItems(sidebar).map((docItem) => docItem.id);
48
+ });
49
+ }
50
+ exports.collectSidebarsDocIds = collectSidebarsDocIds;
51
+ function createSidebarsUtils(sidebars) {
52
+ const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
53
+ // Reverse mapping
54
+ const docIdToSidebarName = Object.fromEntries(Object.entries(sidebarNameToDocIds).flatMap(([sidebarName, docIds]) => docIds.map((docId) => [docId, sidebarName])));
55
+ function getFirstDocIdOfFirstSidebar() {
56
+ var _a;
57
+ return (_a = Object.values(sidebarNameToDocIds)[0]) === null || _a === void 0 ? void 0 : _a[0];
58
+ }
59
+ function getSidebarNameByDocId(docId) {
60
+ return docIdToSidebarName[docId];
61
+ }
62
+ function getDocNavigation(docId) {
63
+ const sidebarName = getSidebarNameByDocId(docId);
64
+ if (sidebarName) {
65
+ const docIds = sidebarNameToDocIds[sidebarName];
66
+ const currentIndex = docIds.indexOf(docId);
67
+ const { previous, next } = (0, utils_1.getElementsAround)(docIds, currentIndex);
68
+ return {
69
+ sidebarName,
70
+ previousId: previous,
71
+ nextId: next,
72
+ };
73
+ }
74
+ else {
75
+ return {
76
+ sidebarName: undefined,
77
+ previousId: undefined,
78
+ nextId: undefined,
79
+ };
80
+ }
81
+ }
82
+ function checkSidebarsDocIds(validDocIds, sidebarFilePath) {
83
+ const allSidebarDocIds = Object.values(sidebarNameToDocIds).flat();
84
+ const invalidSidebarDocIds = (0, lodash_1.difference)(allSidebarDocIds, validDocIds);
85
+ if (invalidSidebarDocIds.length > 0) {
86
+ throw new Error(`Invalid sidebar file at "${(0, utils_1.toMessageRelativeFilePath)(sidebarFilePath)}".
87
+ These sidebar document ids do not exist:
88
+ - ${invalidSidebarDocIds.sort().join('\n- ')}
89
+
90
+ Available document ids are:
91
+ - ${validDocIds.sort().join('\n- ')}`);
92
+ }
93
+ }
94
+ return {
95
+ getFirstDocIdOfFirstSidebar,
96
+ getSidebarNameByDocId,
97
+ getDocNavigation,
98
+ checkSidebarsDocIds,
99
+ };
100
+ }
101
+ exports.createSidebarsUtils = createSidebarsUtils;
@@ -0,0 +1,8 @@
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 { SidebarsConfig } from './types';
8
+ export declare function validateSidebars(sidebars: unknown): asserts sidebars is SidebarsConfig;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateSidebars = void 0;
10
+ const utils_validation_1 = require("@docusaurus/utils-validation");
11
+ const types_1 = require("./types");
12
+ const sidebarItemBaseSchema = utils_validation_1.Joi.object({
13
+ className: utils_validation_1.Joi.string(),
14
+ customProps: utils_validation_1.Joi.object().unknown(),
15
+ });
16
+ const sidebarItemAutogeneratedSchema = sidebarItemBaseSchema.append({
17
+ type: 'autogenerated',
18
+ dirName: utils_validation_1.Joi.string()
19
+ .required()
20
+ .pattern(/^[^/](.*[^/])?$/)
21
+ .message('"dirName" must be a dir path relative to the docs folder root, and should not start or end with slash'),
22
+ });
23
+ const sidebarItemDocSchema = sidebarItemBaseSchema.append({
24
+ type: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
25
+ id: utils_validation_1.Joi.string().required(),
26
+ label: utils_validation_1.Joi.string(),
27
+ });
28
+ const sidebarItemLinkSchema = sidebarItemBaseSchema.append({
29
+ type: 'link',
30
+ href: utils_validation_1.URISchema.required(),
31
+ label: utils_validation_1.Joi.string()
32
+ .required()
33
+ .messages({ 'any.unknown': '"label" must be a string' }),
34
+ });
35
+ const sidebarItemCategorySchema = sidebarItemBaseSchema.append({
36
+ type: 'category',
37
+ label: utils_validation_1.Joi.string()
38
+ .required()
39
+ .messages({ 'any.unknown': '"label" must be a string' }),
40
+ // TODO: Joi doesn't allow mutual recursion. See https://github.com/sideway/joi/issues/2611
41
+ items: utils_validation_1.Joi.array()
42
+ .required()
43
+ .messages({ 'any.unknown': '"items" must be an array' }),
44
+ collapsed: utils_validation_1.Joi.boolean().messages({
45
+ 'any.unknown': '"collapsed" must be a boolean',
46
+ }),
47
+ collapsible: utils_validation_1.Joi.boolean().messages({
48
+ 'any.unknown': '"collapsible" must be a boolean',
49
+ }),
50
+ });
51
+ const sidebarItemSchema = utils_validation_1.Joi.object()
52
+ .when('.type', {
53
+ switch: [
54
+ { is: 'link', then: sidebarItemLinkSchema },
55
+ {
56
+ is: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
57
+ then: sidebarItemDocSchema,
58
+ },
59
+ { is: 'autogenerated', then: sidebarItemAutogeneratedSchema },
60
+ { is: 'category', then: sidebarItemCategorySchema },
61
+ {
62
+ is: 'subcategory',
63
+ then: utils_validation_1.Joi.forbidden().messages({
64
+ 'any.unknown': 'Docusaurus v2: "subcategory" has been renamed as "category".',
65
+ }),
66
+ },
67
+ {
68
+ is: utils_validation_1.Joi.string().required(),
69
+ then: utils_validation_1.Joi.forbidden().messages({
70
+ 'any.unknown': 'Unknown sidebar item type "{.type}".',
71
+ }),
72
+ },
73
+ ],
74
+ })
75
+ .id('sidebarItemSchema');
76
+ function validateSidebarItem(item) {
77
+ if (typeof item === 'string') {
78
+ return;
79
+ }
80
+ // TODO: remove once with proper Joi support
81
+ // Because we can't use Joi to validate nested items (see above), we do it manually
82
+ if ((0, types_1.isCategoriesShorthand)(item)) {
83
+ Object.values(item).forEach((category) => category.forEach(validateSidebarItem));
84
+ }
85
+ else {
86
+ utils_validation_1.Joi.assert(item, sidebarItemSchema);
87
+ if (item.type === 'category') {
88
+ item.items.forEach(validateSidebarItem);
89
+ }
90
+ }
91
+ }
92
+ function validateSidebars(sidebars) {
93
+ Object.values(sidebars).forEach((sidebar) => {
94
+ if (Array.isArray(sidebar)) {
95
+ sidebar.forEach(validateSidebarItem);
96
+ }
97
+ else {
98
+ validateSidebarItem(sidebar);
99
+ }
100
+ });
101
+ }
102
+ exports.validateSidebars = validateSidebars;
package/lib/slug.js CHANGED
@@ -16,14 +16,14 @@ function getSlug({ baseID, frontmatterSlug, dirName, stripDirNumberPrefixes = tr
16
16
  }
17
17
  else {
18
18
  const dirNameStripped = stripDirNumberPrefixes
19
- ? numberPrefix_1.stripPathNumberPrefixes(dirName, numberPrefixParser)
19
+ ? (0, numberPrefix_1.stripPathNumberPrefixes)(dirName, numberPrefixParser)
20
20
  : dirName;
21
21
  const resolveDirname = dirName === '.'
22
22
  ? '/'
23
- : utils_1.addLeadingSlash(utils_1.addTrailingSlash(dirNameStripped));
24
- slug = utils_1.resolvePathname(baseSlug, resolveDirname);
23
+ : (0, utils_1.addLeadingSlash)((0, utils_1.addTrailingSlash)(dirNameStripped));
24
+ slug = (0, utils_1.resolvePathname)(baseSlug, resolveDirname);
25
25
  }
26
- if (!utils_1.isValidPathname(slug)) {
26
+ if (!(0, utils_1.isValidPathname)(slug)) {
27
27
  throw new Error(`We couldn't compute a valid slug for document with id "${baseID}" in "${dirName}" directory.
28
28
  The slug we computed looks invalid: ${slug}.
29
29
  Maybe your slug frontmatter is incorrect or you use weird chars in the file path?
package/lib/tags.d.ts ADDED
@@ -0,0 +1,8 @@
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 { VersionTags, DocMetadata } from './types';
8
+ export declare function getVersionTags(docs: DocMetadata[]): VersionTags;
package/lib/tags.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getVersionTags = void 0;
10
+ const utils_1 = require("@docusaurus/utils");
11
+ const lodash_1 = require("lodash");
12
+ function getVersionTags(docs) {
13
+ const groups = (0, utils_1.groupTaggedItems)(docs, (doc) => doc.tags);
14
+ return (0, lodash_1.mapValues)(groups, (group) => {
15
+ return {
16
+ name: group.tag.label,
17
+ docIds: group.items.map((item) => item.id),
18
+ permalink: group.tag.permalink,
19
+ };
20
+ });
21
+ }
22
+ exports.getVersionTags = getVersionTags;
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.useDocVersionSuggestions = exports.useActiveDocContext = exports.useActiveVersion = exports.useLatestVersion = exports.useVersions = exports.useActivePluginAndVersion = exports.useActivePlugin = exports.useDocsData = exports.useAllDocsData = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const router_1 = require("@docusaurus/router");
12
- const useGlobalData_1 = tslib_1.__importStar(require("@docusaurus/useGlobalData"));
12
+ const useGlobalData_1 = (0, tslib_1.__importStar)(require("@docusaurus/useGlobalData"));
13
13
  const docsClientUtils_1 = require("../../client/docsClientUtils");
14
14
  // Important to use a constant object to avoid React useEffect executions etc...,
15
15
  // see https://github.com/facebook/docusaurus/issues/5089
@@ -18,21 +18,21 @@ const StableEmptyObject = {};
18
18
  // We need a fail-safe fallback when the docs plugin is not in use
19
19
  const useAllDocsData = () => { var _a;
20
20
  // useAllPluginInstancesData('docusaurus-plugin-content-docs');
21
- return (_a = useGlobalData_1.default()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : StableEmptyObject; };
21
+ return (_a = (0, useGlobalData_1.default)()['docusaurus-plugin-content-docs']) !== null && _a !== void 0 ? _a : StableEmptyObject; };
22
22
  exports.useAllDocsData = useAllDocsData;
23
- const useDocsData = (pluginId) => useGlobalData_1.usePluginData('docusaurus-plugin-content-docs', pluginId);
23
+ const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus-plugin-content-docs', pluginId);
24
24
  exports.useDocsData = useDocsData;
25
25
  const useActivePlugin = (options = {}) => {
26
- const data = exports.useAllDocsData();
27
- const { pathname } = router_1.useLocation();
28
- return docsClientUtils_1.getActivePlugin(data, pathname, options);
26
+ const data = (0, exports.useAllDocsData)();
27
+ const { pathname } = (0, router_1.useLocation)();
28
+ return (0, docsClientUtils_1.getActivePlugin)(data, pathname, options);
29
29
  };
30
30
  exports.useActivePlugin = useActivePlugin;
31
31
  const useActivePluginAndVersion = (options = {}) => {
32
- const activePlugin = exports.useActivePlugin(options);
33
- const { pathname } = router_1.useLocation();
32
+ const activePlugin = (0, exports.useActivePlugin)(options);
33
+ const { pathname } = (0, router_1.useLocation)();
34
34
  if (activePlugin) {
35
- const activeVersion = docsClientUtils_1.getActiveVersion(activePlugin.pluginData, pathname);
35
+ const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
36
36
  return {
37
37
  activePlugin,
38
38
  activeVersion,
@@ -43,33 +43,33 @@ const useActivePluginAndVersion = (options = {}) => {
43
43
  exports.useActivePluginAndVersion = useActivePluginAndVersion;
44
44
  // versions are returned ordered (most recent first)
45
45
  const useVersions = (pluginId) => {
46
- const data = exports.useDocsData(pluginId);
46
+ const data = (0, exports.useDocsData)(pluginId);
47
47
  return data.versions;
48
48
  };
49
49
  exports.useVersions = useVersions;
50
50
  const useLatestVersion = (pluginId) => {
51
- const data = exports.useDocsData(pluginId);
52
- return docsClientUtils_1.getLatestVersion(data);
51
+ const data = (0, exports.useDocsData)(pluginId);
52
+ return (0, docsClientUtils_1.getLatestVersion)(data);
53
53
  };
54
54
  exports.useLatestVersion = useLatestVersion;
55
55
  // Note: return undefined on doc-unrelated pages,
56
56
  // because there's no version currently considered as active
57
57
  const useActiveVersion = (pluginId) => {
58
- const data = exports.useDocsData(pluginId);
59
- const { pathname } = router_1.useLocation();
60
- return docsClientUtils_1.getActiveVersion(data, pathname);
58
+ const data = (0, exports.useDocsData)(pluginId);
59
+ const { pathname } = (0, router_1.useLocation)();
60
+ return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
61
61
  };
62
62
  exports.useActiveVersion = useActiveVersion;
63
63
  const useActiveDocContext = (pluginId) => {
64
- const data = exports.useDocsData(pluginId);
65
- const { pathname } = router_1.useLocation();
66
- return docsClientUtils_1.getActiveDocContext(data, pathname);
64
+ const data = (0, exports.useDocsData)(pluginId);
65
+ const { pathname } = (0, router_1.useLocation)();
66
+ return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
67
67
  };
68
68
  exports.useActiveDocContext = useActiveDocContext;
69
69
  // Useful to say "hey, you are not on the latest docs version, please switch"
70
70
  const useDocVersionSuggestions = (pluginId) => {
71
- const data = exports.useDocsData(pluginId);
72
- const { pathname } = router_1.useLocation();
73
- return docsClientUtils_1.getDocVersionSuggestions(data, pathname);
71
+ const data = (0, exports.useDocsData)(pluginId);
72
+ const { pathname } = (0, router_1.useLocation)();
73
+ return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
74
74
  };
75
75
  exports.useDocVersionSuggestions = useDocVersionSuggestions;
@@ -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
- import { LoadedContent } from './types';
7
+ import type { LoadedContent } from './types';
8
8
  import { TranslationFile, TranslationFiles } from '@docusaurus/types';
9
9
  export declare function getLoadedContentTranslationFiles(loadedContent: LoadedContent): TranslationFiles;
10
10
  export declare function translateLoadedContent(loadedContent: LoadedContent, translationFiles: TranslationFile[]): LoadedContent;
@@ -8,8 +8,8 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.translateLoadedContent = exports.getLoadedContentTranslationFiles = void 0;
10
10
  const lodash_1 = require("lodash");
11
- const sidebars_1 = require("./sidebars");
12
- const utils_1 = require("@docusaurus/utils");
11
+ const utils_1 = require("./sidebars/utils");
12
+ const utils_2 = require("@docusaurus/utils");
13
13
  const constants_1 = require("./constants");
14
14
  function getVersionFileName(versionName) {
15
15
  if (versionName === constants_1.CURRENT_VERSION_NAME) {
@@ -74,26 +74,26 @@ function translateDocs(
74
74
  }
75
75
  */
76
76
  function getSidebarTranslationFileContent(sidebar, sidebarName) {
77
- const categories = sidebars_1.collectSidebarCategories(sidebar);
78
- const categoryContent = lodash_1.chain(categories)
77
+ const categories = (0, utils_1.collectSidebarCategories)(sidebar);
78
+ const categoryContent = (0, lodash_1.chain)(categories)
79
79
  .keyBy((category) => `sidebar.${sidebarName}.category.${category.label}`)
80
80
  .mapValues((category) => ({
81
81
  message: category.label,
82
82
  description: `The label for category ${category.label} in sidebar ${sidebarName}`,
83
83
  }))
84
84
  .value();
85
- const links = sidebars_1.collectSidebarLinks(sidebar);
86
- const linksContent = lodash_1.chain(links)
85
+ const links = (0, utils_1.collectSidebarLinks)(sidebar);
86
+ const linksContent = (0, lodash_1.chain)(links)
87
87
  .keyBy((link) => `sidebar.${sidebarName}.link.${link.label}`)
88
88
  .mapValues((link) => ({
89
89
  message: link.label,
90
90
  description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
91
91
  }))
92
92
  .value();
93
- return utils_1.mergeTranslations([categoryContent, linksContent]);
93
+ return (0, utils_2.mergeTranslations)([categoryContent, linksContent]);
94
94
  }
95
95
  function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
96
- return sidebars_1.transformSidebarItems(sidebar, (item) => {
96
+ return (0, utils_1.transformSidebarItems)(sidebar, (item) => {
97
97
  var _a, _b, _c, _d;
98
98
  if (item.type === 'category') {
99
99
  return {
@@ -111,7 +111,7 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
111
111
  });
112
112
  }
113
113
  function getSidebarsTranslations(version) {
114
- return utils_1.mergeTranslations(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
114
+ return (0, utils_2.mergeTranslations)(Object.entries(version.sidebars).map(([sidebarName, sidebar]) => {
115
115
  const normalizedSidebarName = getNormalizedSidebarName({
116
116
  sidebarName,
117
117
  versionName: version.versionName,
@@ -120,7 +120,7 @@ function getSidebarsTranslations(version) {
120
120
  }));
121
121
  }
122
122
  function translateSidebars(version, sidebarsTranslations) {
123
- return lodash_1.mapValues(version.sidebars, (sidebar, sidebarName) => {
123
+ return (0, lodash_1.mapValues)(version.sidebars, (sidebar, sidebarName) => {
124
124
  return translateSidebar({
125
125
  sidebar,
126
126
  sidebarName: getNormalizedSidebarName({
@@ -143,7 +143,7 @@ function getVersionTranslationFiles(version) {
143
143
  return [
144
144
  {
145
145
  path: getVersionFileName(version.versionName),
146
- content: utils_1.mergeTranslations([
146
+ content: (0, utils_2.mergeTranslations)([
147
147
  versionTranslations,
148
148
  sidebarsTranslations,
149
149
  // docsTranslations,
@@ -162,7 +162,7 @@ function translateVersion(version, translationFiles) {
162
162
  };
163
163
  }
164
164
  function getVersionsTranslationFiles(versions) {
165
- return lodash_1.flatten(versions.map(getVersionTranslationFiles));
165
+ return versions.flatMap(getVersionTranslationFiles);
166
166
  }
167
167
  function translateVersions(versions, translationFiles) {
168
168
  return versions.map((version) => translateVersion(version, translationFiles));
@@ -172,7 +172,7 @@ function getLoadedContentTranslationFiles(loadedContent) {
172
172
  }
173
173
  exports.getLoadedContentTranslationFiles = getLoadedContentTranslationFiles;
174
174
  function translateLoadedContent(loadedContent, translationFiles) {
175
- const translationFilesMap = lodash_1.keyBy(translationFiles, (f) => f.path);
175
+ const translationFilesMap = (0, lodash_1.keyBy)(translationFiles, (f) => f.path);
176
176
  return {
177
177
  loadedVersions: translateVersions(loadedContent.loadedVersions, translationFilesMap),
178
178
  };
package/lib/types.d.ts CHANGED
@@ -5,7 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { RemarkAndRehypePluginOptions } from '@docusaurus/mdx-loader';
8
- import { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
8
+ import type { Tag, FrontMatterTag } from '@docusaurus/utils';
9
+ import type { BrokenMarkdownLink as IBrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
10
+ import type { SidebarItemsGeneratorOption, Sidebars } from './sidebars/types';
9
11
  export declare type DocFile = {
10
12
  contentPath: string;
11
13
  filePath: string;
@@ -18,9 +20,12 @@ export declare type VersionMetadata = ContentPaths & {
18
20
  versionName: VersionName;
19
21
  versionLabel: string;
20
22
  versionPath: string;
23
+ tagsPath: string;
21
24
  versionEditUrl?: string | undefined;
22
25
  versionEditUrlLocalized?: string | undefined;
23
- versionBanner: VersionBanner;
26
+ versionBanner: VersionBanner | null;
27
+ versionBadge: boolean;
28
+ versionClassName: string;
24
29
  isLast: boolean;
25
30
  sidebarFilePath: string | false | undefined;
26
31
  routePriority: number | undefined;
@@ -46,11 +51,13 @@ export declare type PathOptions = {
46
51
  path: string;
47
52
  sidebarPath?: string | false | undefined;
48
53
  };
49
- export declare type VersionBanner = 'none' | 'unreleased' | 'unmaintained';
54
+ export declare type VersionBanner = 'unreleased' | 'unmaintained';
50
55
  export declare type VersionOptions = {
51
56
  path?: string;
52
57
  label?: string;
53
- banner?: VersionBanner;
58
+ banner?: 'none' | VersionBanner;
59
+ badge?: boolean;
60
+ className?: string;
54
61
  };
55
62
  export declare type VersionsOptions = {
56
63
  lastVersion?: string;
@@ -67,67 +74,13 @@ export declare type PluginOptions = MetadataOptions & PathOptions & VersionsOpti
67
74
  exclude: string[];
68
75
  docLayoutComponent: string;
69
76
  docItemComponent: string;
77
+ docTagDocListComponent: string;
78
+ docTagsListComponent: string;
70
79
  admonitions: Record<string, unknown>;
71
80
  disableVersioning: boolean;
72
81
  includeCurrentVersion: boolean;
73
82
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
74
- };
75
- export declare type SidebarItemBase = {
76
- customProps?: Record<string, unknown>;
77
- };
78
- export declare type SidebarItemDoc = SidebarItemBase & {
79
- type: 'doc' | 'ref';
80
- label?: string;
81
- id: string;
82
- };
83
- export declare type SidebarItemLink = SidebarItemBase & {
84
- type: 'link';
85
- href: string;
86
- label: string;
87
- };
88
- export declare type SidebarItemCategory = SidebarItemBase & {
89
- type: 'category';
90
- label: string;
91
- items: SidebarItem[];
92
- collapsed: boolean;
93
- collapsible: boolean;
94
- };
95
- export declare type UnprocessedSidebarItemAutogenerated = {
96
- type: 'autogenerated';
97
- dirName: string;
98
- };
99
- export declare type UnprocessedSidebarItemCategory = SidebarItemBase & {
100
- type: 'category';
101
- label: string;
102
- items: UnprocessedSidebarItem[];
103
- collapsed: boolean;
104
- collapsible: boolean;
105
- };
106
- export declare type UnprocessedSidebarItem = SidebarItemDoc | SidebarItemLink | UnprocessedSidebarItemCategory | UnprocessedSidebarItemAutogenerated;
107
- export declare type UnprocessedSidebar = UnprocessedSidebarItem[];
108
- export declare type UnprocessedSidebars = Record<string, UnprocessedSidebar>;
109
- export declare type SidebarItem = SidebarItemDoc | SidebarItemLink | SidebarItemCategory;
110
- export declare type Sidebar = SidebarItem[];
111
- export declare type SidebarItemType = SidebarItem['type'];
112
- export declare type Sidebars = Record<string, Sidebar>;
113
- export declare type SidebarItemsGeneratorDoc = Pick<DocMetadataBase, 'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'>;
114
- export declare type SidebarItemsGeneratorVersion = Pick<VersionMetadata, 'versionName' | 'contentPath'>;
115
- export declare type SidebarItemsGeneratorArgs = {
116
- item: UnprocessedSidebarItemAutogenerated;
117
- version: SidebarItemsGeneratorVersion;
118
- docs: SidebarItemsGeneratorDoc[];
119
- numberPrefixParser: NumberPrefixParser;
120
- options: SidebarOptions;
121
- };
122
- export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<SidebarItem[]>;
123
- export declare type SidebarItemsGeneratorOptionArgs = {
124
- defaultSidebarItemsGenerator: SidebarItemsGenerator;
125
- } & SidebarItemsGeneratorArgs;
126
- export declare type SidebarItemsGeneratorOption = (generatorArgs: SidebarItemsGeneratorOptionArgs) => Promise<SidebarItem[]>;
127
- export declare type OrderMetadata = {
128
- previous?: string;
129
- next?: string;
130
- sidebar?: string;
83
+ tagsBasePath: string;
131
84
  };
132
85
  export declare type LastUpdateData = {
133
86
  lastUpdatedAt?: number;
@@ -137,6 +90,7 @@ export declare type LastUpdateData = {
137
90
  export declare type DocFrontMatter = {
138
91
  id?: string;
139
92
  title?: string;
93
+ tags?: FrontMatterTag[];
140
94
  hide_title?: boolean;
141
95
  hide_table_of_contents?: boolean;
142
96
  keywords?: string[];
@@ -145,9 +99,14 @@ export declare type DocFrontMatter = {
145
99
  slug?: string;
146
100
  sidebar_label?: string;
147
101
  sidebar_position?: number;
102
+ sidebar_class_name?: string;
148
103
  pagination_label?: string;
149
104
  custom_edit_url?: string | null;
150
105
  parse_number_prefixes?: boolean;
106
+ toc_min_heading_level?: number;
107
+ toc_max_heading_level?: number;
108
+ pagination_next?: string | null;
109
+ pagination_prev?: string | null;
151
110
  };
152
111
  export declare type DocMetadataBase = LastUpdateData & {
153
112
  version: VersionName;
@@ -162,6 +121,7 @@ export declare type DocMetadataBase = LastUpdateData & {
162
121
  permalink: string;
163
122
  sidebarPosition?: number;
164
123
  editUrl?: string | null;
124
+ tags: Tag[];
165
125
  frontMatter: DocFrontMatter & Record<string, unknown>;
166
126
  };
167
127
  export declare type DocNavLink = {
@@ -176,6 +136,14 @@ export declare type DocMetadata = DocMetadataBase & {
176
136
  export declare type SourceToPermalink = {
177
137
  [source: string]: string;
178
138
  };
139
+ export declare type VersionTag = {
140
+ name: string;
141
+ docIds: string[];
142
+ permalink: string;
143
+ };
144
+ export declare type VersionTags = {
145
+ [key: string]: VersionTag;
146
+ };
179
147
  export declare type LoadedVersion = VersionMetadata & {
180
148
  versionPath: string;
181
149
  mainDocId: string;
package/lib/versions.d.ts CHANGED
@@ -11,6 +11,6 @@ export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: s
11
11
  export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
12
12
  export declare function readVersionsMetadata({ context, options, }: {
13
13
  context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
14
- options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
14
+ options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
15
15
  }): VersionMetadata[];
16
16
  export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];