@docusaurus/plugin-content-docs 0.0.0-4533 → 0.0.0-4539

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.
@@ -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
+ export * from '../constants';
8
+ export { filterVersions, getDefaultVersionBanner, getVersionBadge, getVersionBanner, getVersionsFilePath, readVersionsFile, readVersionNames, } from '../versions';
@@ -0,0 +1,20 @@
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.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getVersionBanner = exports.getVersionBadge = exports.getDefaultVersionBanner = exports.filterVersions = void 0;
10
+ const tslib_1 = require("tslib");
11
+ // APIs available to Node.js
12
+ (0, tslib_1.__exportStar)(require("../constants"), exports);
13
+ var versions_1 = require("../versions");
14
+ Object.defineProperty(exports, "filterVersions", { enumerable: true, get: function () { return versions_1.filterVersions; } });
15
+ Object.defineProperty(exports, "getDefaultVersionBanner", { enumerable: true, get: function () { return versions_1.getDefaultVersionBanner; } });
16
+ Object.defineProperty(exports, "getVersionBadge", { enumerable: true, get: function () { return versions_1.getVersionBadge; } });
17
+ Object.defineProperty(exports, "getVersionBanner", { enumerable: true, get: function () { return versions_1.getVersionBanner; } });
18
+ Object.defineProperty(exports, "getVersionsFilePath", { enumerable: true, get: function () { return versions_1.getVersionsFilePath; } });
19
+ Object.defineProperty(exports, "readVersionsFile", { enumerable: true, get: function () { return versions_1.readVersionsFile; } });
20
+ Object.defineProperty(exports, "readVersionNames", { enumerable: true, get: function () { return versions_1.readVersionNames; } });
@@ -61,6 +61,32 @@ async function processSidebar(unprocessedSidebar, params) {
61
61
  }
62
62
  async function processItem(item) {
63
63
  if (item.type === 'category') {
64
+ // If the current category doesn't have subitems, we render a normal doc link instead.
65
+ if (item.items.length === 0) {
66
+ if (!item.link) {
67
+ throw new Error(`Sidebar category ${item.label} has neither any subitem nor a link. This makes this item not able to link to anything.`);
68
+ }
69
+ switch (item.link.type) {
70
+ case 'doc':
71
+ return [
72
+ {
73
+ type: 'doc',
74
+ label: item.label,
75
+ id: item.link.id,
76
+ },
77
+ ];
78
+ case 'generated-index':
79
+ return [
80
+ {
81
+ type: 'link',
82
+ label: item.label,
83
+ href: item.link.permalink,
84
+ },
85
+ ];
86
+ default:
87
+ throw new Error('Unexpected sidebar category link type');
88
+ }
89
+ }
64
90
  return [await processCategoryItem(item)];
65
91
  }
66
92
  if (item.type === 'autogenerated') {
package/lib/versions.d.ts CHANGED
@@ -5,11 +5,35 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { VersionMetadata } from './types';
8
- import type { PluginOptions } from '@docusaurus/plugin-content-docs';
8
+ import type { PluginOptions, VersionBanner } from '@docusaurus/plugin-content-docs';
9
9
  import type { LoadContext } from '@docusaurus/types';
10
10
  export declare function getVersionedDocsDirPath(siteDir: string, pluginId: string): string;
11
11
  export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: string): string;
12
12
  export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
13
+ export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
14
+ export declare function readVersionNames(siteDir: string, options: Pick<PluginOptions, 'id' | 'disableVersioning' | 'includeCurrentVersion'>): Promise<string[]>;
15
+ export declare function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }: {
16
+ versionName: string;
17
+ versionNames: string[];
18
+ lastVersionName: string;
19
+ }): VersionBanner | null;
20
+ export declare function getVersionBanner({ versionName, versionNames, lastVersionName, options, }: {
21
+ versionName: string;
22
+ versionNames: string[];
23
+ lastVersionName: string;
24
+ options: Pick<PluginOptions, 'versions'>;
25
+ }): VersionBanner | null;
26
+ export declare function getVersionBadge({ versionName, versionNames, options, }: {
27
+ versionName: string;
28
+ versionNames: string[];
29
+ options: Pick<PluginOptions, 'versions'>;
30
+ }): boolean;
31
+ /**
32
+ * Filter versions according to provided options.
33
+ * Note: we preserve the order in which versions are provided;
34
+ * the order of the onlyIncludeVersions array does not matter
35
+ */
36
+ export declare function filterVersions(versionNamesUnfiltered: string[], options: Pick<PluginOptions, 'onlyIncludeVersions'>): string[];
13
37
  export declare function readVersionsMetadata({ context, options, }: {
14
38
  context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
15
39
  options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
package/lib/versions.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.getDocsDirPaths = exports.readVersionsMetadata = exports.getVersionsFilePath = exports.getVersionedSidebarsDirPath = exports.getVersionedDocsDirPath = void 0;
9
+ exports.getDocsDirPaths = exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getVersionedSidebarsDirPath = exports.getVersionedDocsDirPath = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
12
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
@@ -56,6 +56,7 @@ async function readVersionsFile(siteDir, pluginId) {
56
56
  }
57
57
  return null;
58
58
  }
59
+ exports.readVersionsFile = readVersionsFile;
59
60
  async function readVersionNames(siteDir, options) {
60
61
  const versionFileContent = await readVersionsFile(siteDir, options.id);
61
62
  if (!versionFileContent && options.disableVersioning) {
@@ -74,6 +75,7 @@ async function readVersionNames(siteDir, options) {
74
75
  }
75
76
  return versions;
76
77
  }
78
+ exports.readVersionNames = readVersionNames;
77
79
  function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }) {
78
80
  return (0, utils_1.getPluginI18nPath)({
79
81
  siteDir,
@@ -150,6 +152,7 @@ function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }
150
152
  // Older versions: display unmaintained banner
151
153
  return 'unmaintained';
152
154
  }
155
+ exports.getDefaultVersionBanner = getDefaultVersionBanner;
153
156
  function getVersionBanner({ versionName, versionNames, lastVersionName, options, }) {
154
157
  var _a;
155
158
  const versionBannerOption = (_a = options.versions[versionName]) === null || _a === void 0 ? void 0 : _a.banner;
@@ -162,6 +165,7 @@ function getVersionBanner({ versionName, versionNames, lastVersionName, options,
162
165
  lastVersionName,
163
166
  });
164
167
  }
168
+ exports.getVersionBanner = getVersionBanner;
165
169
  function getVersionBadge({ versionName, versionNames, options, }) {
166
170
  var _a;
167
171
  const versionBadgeOption = (_a = options.versions[versionName]) === null || _a === void 0 ? void 0 : _a.badge;
@@ -171,6 +175,7 @@ function getVersionBadge({ versionName, versionNames, options, }) {
171
175
  const versionBadgeDefault = versionNames.length !== 1;
172
176
  return versionBadgeOption !== null && versionBadgeOption !== void 0 ? versionBadgeOption : versionBadgeDefault;
173
177
  }
178
+ exports.getVersionBadge = getVersionBadge;
174
179
  function getVersionClassName({ versionName, options, }) {
175
180
  var _a;
176
181
  const versionClassNameOption = (_a = options.versions[versionName]) === null || _a === void 0 ? void 0 : _a.className;
@@ -297,6 +302,7 @@ function filterVersions(versionNamesUnfiltered, options) {
297
302
  }
298
303
  return versionNamesUnfiltered;
299
304
  }
305
+ exports.filterVersions = filterVersions;
300
306
  async function readVersionsMetadata({ context, options, }) {
301
307
  var _a;
302
308
  const versionNamesUnfiltered = await readVersionNames(context.siteDir, options);
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4533",
3
+ "version": "0.0.0-4539",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
7
7
  "./client": "./lib/client/index.js",
8
+ "./server": "./lib/server/index.js",
8
9
  ".": "./lib/index.js"
9
10
  },
10
11
  "types": "src/plugin-content-docs.d.ts",
@@ -22,11 +23,11 @@
22
23
  },
23
24
  "license": "MIT",
24
25
  "dependencies": {
25
- "@docusaurus/core": "0.0.0-4533",
26
- "@docusaurus/logger": "0.0.0-4533",
27
- "@docusaurus/mdx-loader": "0.0.0-4533",
28
- "@docusaurus/utils": "0.0.0-4533",
29
- "@docusaurus/utils-validation": "0.0.0-4533",
26
+ "@docusaurus/core": "0.0.0-4539",
27
+ "@docusaurus/logger": "0.0.0-4539",
28
+ "@docusaurus/mdx-loader": "0.0.0-4539",
29
+ "@docusaurus/utils": "0.0.0-4539",
30
+ "@docusaurus/utils-validation": "0.0.0-4539",
30
31
  "combine-promises": "^1.1.0",
31
32
  "fs-extra": "^10.0.0",
32
33
  "import-fresh": "^3.2.2",
@@ -39,8 +40,8 @@
39
40
  "webpack": "^5.68.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@docusaurus/module-type-aliases": "0.0.0-4533",
43
- "@docusaurus/types": "0.0.0-4533",
43
+ "@docusaurus/module-type-aliases": "0.0.0-4539",
44
+ "@docusaurus/types": "0.0.0-4539",
44
45
  "@types/js-yaml": "^4.0.0",
45
46
  "@types/picomatch": "^2.2.1",
46
47
  "commander": "^5.1.0",
@@ -56,5 +57,5 @@
56
57
  "engines": {
57
58
  "node": ">=14"
58
59
  },
59
- "gitHead": "5ab127cc566e3d1af8653a162eafbfbd64d0764e"
60
+ "gitHead": "7b82719906447f76637ad0452ad8df1d9698f805"
60
61
  }
@@ -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
+
8
+ // APIs available to Node.js
9
+ export * from '../constants';
10
+
11
+ export {
12
+ filterVersions,
13
+ getDefaultVersionBanner,
14
+ getVersionBadge,
15
+ getVersionBanner,
16
+ getVersionsFilePath,
17
+ readVersionsFile,
18
+ readVersionNames,
19
+ } from '../versions';
@@ -117,6 +117,34 @@ async function processSidebar(
117
117
  item: NormalizedSidebarItem,
118
118
  ): Promise<SidebarItem[]> {
119
119
  if (item.type === 'category') {
120
+ // If the current category doesn't have subitems, we render a normal doc link instead.
121
+ if (item.items.length === 0) {
122
+ if (!item.link) {
123
+ throw new Error(
124
+ `Sidebar category ${item.label} has neither any subitem nor a link. This makes this item not able to link to anything.`,
125
+ );
126
+ }
127
+ switch (item.link.type) {
128
+ case 'doc':
129
+ return [
130
+ {
131
+ type: 'doc',
132
+ label: item.label,
133
+ id: item.link.id,
134
+ },
135
+ ];
136
+ case 'generated-index':
137
+ return [
138
+ {
139
+ type: 'link',
140
+ label: item.label,
141
+ href: item.link.permalink,
142
+ },
143
+ ];
144
+ default:
145
+ throw new Error('Unexpected sidebar category link type');
146
+ }
147
+ }
120
148
  return [await processCategoryItem(item)];
121
149
  }
122
150
  if (item.type === 'autogenerated') {
package/src/versions.ts CHANGED
@@ -85,7 +85,7 @@ function ensureValidVersionArray(
85
85
  versionArray.forEach(ensureValidVersionString);
86
86
  }
87
87
 
88
- async function readVersionsFile(
88
+ export async function readVersionsFile(
89
89
  siteDir: string,
90
90
  pluginId: string,
91
91
  ): Promise<string[] | null> {
@@ -98,7 +98,7 @@ async function readVersionsFile(
98
98
  return null;
99
99
  }
100
100
 
101
- async function readVersionNames(
101
+ export async function readVersionNames(
102
102
  siteDir: string,
103
103
  options: Pick<
104
104
  PluginOptions,
@@ -257,7 +257,7 @@ function getVersionEditUrls({
257
257
  };
258
258
  }
259
259
 
260
- function getDefaultVersionBanner({
260
+ export function getDefaultVersionBanner({
261
261
  versionName,
262
262
  versionNames,
263
263
  lastVersionName,
@@ -280,7 +280,7 @@ function getDefaultVersionBanner({
280
280
  return 'unmaintained';
281
281
  }
282
282
 
283
- function getVersionBanner({
283
+ export function getVersionBanner({
284
284
  versionName,
285
285
  versionNames,
286
286
  lastVersionName,
@@ -302,7 +302,7 @@ function getVersionBanner({
302
302
  });
303
303
  }
304
304
 
305
- function getVersionBadge({
305
+ export function getVersionBadge({
306
306
  versionName,
307
307
  versionNames,
308
308
  options,
@@ -531,10 +531,10 @@ function checkVersionsOptions(
531
531
  * Note: we preserve the order in which versions are provided;
532
532
  * the order of the onlyIncludeVersions array does not matter
533
533
  */
534
- function filterVersions(
534
+ export function filterVersions(
535
535
  versionNamesUnfiltered: string[],
536
536
  options: Pick<PluginOptions, 'onlyIncludeVersions'>,
537
- ) {
537
+ ): string[] {
538
538
  if (options.onlyIncludeVersions) {
539
539
  return versionNamesUnfiltered.filter((name) =>
540
540
  (options.onlyIncludeVersions || []).includes(name),