@docusaurus/plugin-content-docs 0.0.0-5042 → 0.0.0-5047

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.
@@ -73,6 +73,6 @@ export function getActiveDocContext(data, pathname) {
73
73
  export function getDocVersionSuggestions(data, pathname) {
74
74
  const latestVersion = getLatestVersion(data);
75
75
  const activeDocContext = getActiveDocContext(data, pathname);
76
- const latestDocSuggestion = activeDocContext?.alternateDocVersions[latestVersion.name];
76
+ const latestDocSuggestion = activeDocContext.alternateDocVersions[latestVersion.name];
77
77
  return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
78
78
  }
package/lib/index.js CHANGED
@@ -76,7 +76,7 @@ async function pluginContentDocs(context, options) {
76
76
  if (docFiles.length === 0) {
77
77
  throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(siteDir, versionMetadata.contentPath)}".`);
78
78
  }
79
- async function processVersionDoc(docFile) {
79
+ function processVersionDoc(docFile) {
80
80
  return (0, docs_1.processDocMetadata)({
81
81
  docFile,
82
82
  versionMetadata,
@@ -11,6 +11,6 @@ function markdownLoader(source) {
11
11
  const fileString = source;
12
12
  const callback = this.async();
13
13
  const options = this.getOptions();
14
- return callback?.(null, (0, linkify_1.linkify)(fileString, this.resourcePath, options));
14
+ return callback(null, (0, linkify_1.linkify)(fileString, this.resourcePath, options));
15
15
  }
16
16
  exports.default = markdownLoader;
package/lib/props.js CHANGED
@@ -26,7 +26,7 @@ Available document ids are:
26
26
  const { title, permalink, frontMatter: { sidebar_label: sidebarLabel }, } = docMetadata;
27
27
  return {
28
28
  type: 'link',
29
- label: sidebarLabel || item.label || title,
29
+ label: sidebarLabel ?? item.label ?? title,
30
30
  href: permalink,
31
31
  className: item.className,
32
32
  customProps: item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
@@ -21,7 +21,7 @@ function getLocalDocId(docId) {
21
21
  exports.CategoryMetadataFilenameBase = '_category_';
22
22
  exports.CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';
23
23
  // Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
24
- const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryIndex, docs: allDocs, item: { dirName: autogenDir }, categoriesMetadata, }) => {
24
+ const DefaultSidebarItemsGenerator = ({ numberPrefixParser, isCategoryIndex, docs: allDocs, item: { dirName: autogenDir }, categoriesMetadata, }) => {
25
25
  const docsById = (0, docs_1.createDocsByIdIndex)(allDocs);
26
26
  const findDoc = (docId) => docsById[docId];
27
27
  const getDoc = (docId) => {
@@ -61,7 +61,7 @@ function postProcessSidebarItem(item, params) {
61
61
  };
62
62
  }
63
63
  // A non-collapsible category can't be collapsed!
64
- if (category.collapsible === false) {
64
+ if (!category.collapsible) {
65
65
  category.collapsed = false;
66
66
  }
67
67
  return category;
@@ -157,7 +157,7 @@ export declare type SidebarItemsGeneratorArgs = {
157
157
  [filePath: string]: CategoryMetadataFile;
158
158
  };
159
159
  };
160
- export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
160
+ export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
161
161
  export declare type SidebarItemsGeneratorOption = (generatorArgs: {
162
162
  /**
163
163
  * Useful to re-use/enhance the default sidebar generation logic from
@@ -165,7 +165,7 @@ export declare type SidebarItemsGeneratorOption = (generatorArgs: {
165
165
  * @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
166
166
  */
167
167
  defaultSidebarItemsGenerator: SidebarItemsGenerator;
168
- } & SidebarItemsGeneratorArgs) => Promise<NormalizedSidebarItem[]>;
168
+ } & SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
169
169
  export declare type SidebarProcessorParams = {
170
170
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
171
171
  numberPrefixParser: NumberPrefixParser;
@@ -158,7 +158,7 @@ function createSidebarsUtils(sidebars) {
158
158
  function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
159
159
  function isCurrentCategoryGeneratedIndexItem(item) {
160
160
  return (item.type === 'category' &&
161
- item.link?.type === 'generated-index' &&
161
+ item.link.type === 'generated-index' &&
162
162
  item.link.permalink === categoryGeneratedIndexPermalink);
163
163
  }
164
164
  const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
@@ -133,6 +133,10 @@ const categoryMetadataFileSchema = utils_validation_1.Joi.object({
133
133
  customProps: utils_validation_1.Joi.object().unknown(),
134
134
  });
135
135
  function validateCategoryMetadataFile(unsafeContent) {
136
- return utils_validation_1.Joi.attempt(unsafeContent, categoryMetadataFileSchema);
136
+ const { error, value } = categoryMetadataFileSchema.validate(unsafeContent);
137
+ if (error) {
138
+ throw error;
139
+ }
140
+ return value;
137
141
  }
138
142
  exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
package/lib/slug.js CHANGED
@@ -28,7 +28,7 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
28
28
  (0, docs_1.isCategoryIndex)((0, docs_1.toCategoryIndexMatcherParam)({ source, sourceDirName }))) {
29
29
  return dirNameSlug;
30
30
  }
31
- const baseSlug = frontMatterSlug || baseID;
31
+ const baseSlug = frontMatterSlug ?? baseID;
32
32
  return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
33
33
  }
34
34
  function ensureValidSlug(slug) {
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  function validateVersionName(name) {
13
13
  if (typeof name !== 'string') {
14
- throw new Error(`Versions should be strings. Found type "${typeof name}" for version "${name}".`);
14
+ throw new Error(`Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(name)}.`);
15
15
  }
16
16
  if (!name.trim()) {
17
17
  throw new Error(`Invalid version name "${name}": version name must contain at least one non-whitespace character.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-5042",
3
+ "version": "0.0.0-5047",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -25,11 +25,11 @@
25
25
  },
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "@docusaurus/core": "0.0.0-5042",
29
- "@docusaurus/logger": "0.0.0-5042",
30
- "@docusaurus/mdx-loader": "0.0.0-5042",
31
- "@docusaurus/utils": "0.0.0-5042",
32
- "@docusaurus/utils-validation": "0.0.0-5042",
28
+ "@docusaurus/core": "0.0.0-5047",
29
+ "@docusaurus/logger": "0.0.0-5047",
30
+ "@docusaurus/mdx-loader": "0.0.0-5047",
31
+ "@docusaurus/utils": "0.0.0-5047",
32
+ "@docusaurus/utils-validation": "0.0.0-5047",
33
33
  "combine-promises": "^1.1.0",
34
34
  "fs-extra": "^10.1.0",
35
35
  "import-fresh": "^3.3.0",
@@ -41,8 +41,8 @@
41
41
  "webpack": "^5.72.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@docusaurus/module-type-aliases": "0.0.0-5042",
45
- "@docusaurus/types": "0.0.0-5042",
44
+ "@docusaurus/module-type-aliases": "0.0.0-5047",
45
+ "@docusaurus/types": "0.0.0-5047",
46
46
  "@types/js-yaml": "^4.0.5",
47
47
  "@types/picomatch": "^2.3.0",
48
48
  "commander": "^5.1.0",
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=14"
60
60
  },
61
- "gitHead": "af5fa0b311db8cf3934d437d74435966eb456c38"
61
+ "gitHead": "67ac297469d98ac3eb8482d8636aee4648586f33"
62
62
  }
@@ -126,6 +126,6 @@ export function getDocVersionSuggestions(
126
126
  const latestVersion = getLatestVersion(data);
127
127
  const activeDocContext = getActiveDocContext(data, pathname);
128
128
  const latestDocSuggestion: GlobalDoc | undefined =
129
- activeDocContext?.alternateDocVersions[latestVersion.name];
129
+ activeDocContext.alternateDocVersions[latestVersion.name];
130
130
  return {latestDocSuggestion, latestVersionSuggestion: latestVersion};
131
131
  }
@@ -34,9 +34,11 @@ const StableEmptyObject = {};
34
34
  // In blog-only mode, docs hooks are still used by the theme. We need a fail-
35
35
  // safe fallback when the docs plugin is not in use
36
36
  export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} =>
37
- (useAllPluginInstancesData('docusaurus-plugin-content-docs') as {
38
- [pluginId: string]: GlobalPluginData;
39
- }) ?? StableEmptyObject;
37
+ (useAllPluginInstancesData('docusaurus-plugin-content-docs') as
38
+ | {
39
+ [pluginId: string]: GlobalPluginData;
40
+ }
41
+ | undefined) ?? StableEmptyObject;
40
42
 
41
43
  export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
42
44
  usePluginData('docusaurus-plugin-content-docs', pluginId, {
package/src/index.ts CHANGED
@@ -143,7 +143,7 @@ export default async function pluginContentDocs(
143
143
  )}".`,
144
144
  );
145
145
  }
146
- async function processVersionDoc(docFile: DocFile) {
146
+ function processVersionDoc(docFile: DocFile) {
147
147
  return processDocMetadata({
148
148
  docFile,
149
149
  versionMetadata,
@@ -16,5 +16,5 @@ export default function markdownLoader(
16
16
  const fileString = source;
17
17
  const callback = this.async();
18
18
  const options = this.getOptions();
19
- return callback?.(null, linkify(fileString, this.resourcePath, options));
19
+ return callback(null, linkify(fileString, this.resourcePath, options));
20
20
  }
package/src/options.ts CHANGED
@@ -165,7 +165,7 @@ export function validateOptions({
165
165
  }
166
166
  }
167
167
 
168
- const normalizedOptions = validate(OptionsSchema, options) as PluginOptions;
168
+ const normalizedOptions = validate(OptionsSchema, options);
169
169
 
170
170
  if (normalizedOptions.admonitions) {
171
171
  normalizedOptions.remarkPlugins = normalizedOptions.remarkPlugins.concat([
package/src/props.ts CHANGED
@@ -51,7 +51,7 @@ Available document ids are:
51
51
  } = docMetadata;
52
52
  return {
53
53
  type: 'link',
54
- label: sidebarLabel || item.label || title,
54
+ label: sidebarLabel ?? item.label ?? title,
55
55
  href: permalink,
56
56
  className: item.className,
57
57
  customProps:
@@ -46,7 +46,7 @@ type Dir = {
46
46
  };
47
47
 
48
48
  // Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
49
- export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
49
+ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = ({
50
50
  numberPrefixParser,
51
51
  isCategoryIndex,
52
52
  docs: allDocs,
@@ -84,7 +84,7 @@ function postProcessSidebarItem(
84
84
  };
85
85
  }
86
86
  // A non-collapsible category can't be collapsed!
87
- if (category.collapsible === false) {
87
+ if (!category.collapsible) {
88
88
  category.collapsed = false;
89
89
  }
90
90
  return category;
@@ -251,7 +251,7 @@ export type SidebarItemsGeneratorArgs = {
251
251
  };
252
252
  export type SidebarItemsGenerator = (
253
253
  generatorArgs: SidebarItemsGeneratorArgs,
254
- ) => Promise<NormalizedSidebar>;
254
+ ) => NormalizedSidebar | Promise<NormalizedSidebar>;
255
255
 
256
256
  export type SidebarItemsGeneratorOption = (
257
257
  generatorArgs: {
@@ -262,7 +262,7 @@ export type SidebarItemsGeneratorOption = (
262
262
  */
263
263
  defaultSidebarItemsGenerator: SidebarItemsGenerator;
264
264
  } & SidebarItemsGeneratorArgs,
265
- ) => Promise<NormalizedSidebarItem[]>;
265
+ ) => NormalizedSidebar | Promise<NormalizedSidebar>;
266
266
 
267
267
  export type SidebarProcessorParams = {
268
268
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
@@ -257,7 +257,7 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
257
257
  ): boolean {
258
258
  return (
259
259
  item.type === 'category' &&
260
- item.link?.type === 'generated-index' &&
260
+ item.link.type === 'generated-index' &&
261
261
  item.link.permalink === categoryGeneratedIndexPermalink
262
262
  );
263
263
  }
@@ -144,7 +144,7 @@ function validateSidebarItem(
144
144
  // manually
145
145
  Joi.assert(item, sidebarItemSchema);
146
146
 
147
- if ((item as NormalizedSidebarItemCategory).type === 'category') {
147
+ if ((item as NormalizedSidebarItem).type === 'category') {
148
148
  (item as NormalizedSidebarItemCategory).items.forEach(validateSidebarItem);
149
149
  }
150
150
  }
@@ -170,5 +170,9 @@ const categoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
170
170
  export function validateCategoryMetadataFile(
171
171
  unsafeContent: unknown,
172
172
  ): CategoryMetadataFile {
173
- return Joi.attempt(unsafeContent, categoryMetadataFileSchema);
173
+ const {error, value} = categoryMetadataFileSchema.validate(unsafeContent);
174
+ if (error) {
175
+ throw error;
176
+ }
177
+ return value;
174
178
  }
package/src/slug.ts CHANGED
@@ -58,7 +58,7 @@ export default function getSlug({
58
58
  ) {
59
59
  return dirNameSlug;
60
60
  }
61
- const baseSlug = frontMatterSlug || baseID;
61
+ const baseSlug = frontMatterSlug ?? baseID;
62
62
  return resolvePathname(baseSlug, getDirNameSlug());
63
63
  }
64
64
 
@@ -11,7 +11,9 @@ import type {VersionsOptions} from '@docusaurus/plugin-content-docs';
11
11
  export function validateVersionName(name: unknown): asserts name is string {
12
12
  if (typeof name !== 'string') {
13
13
  throw new Error(
14
- `Versions should be strings. Found type "${typeof name}" for version "${name}".`,
14
+ `Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(
15
+ name,
16
+ )}.`,
15
17
  );
16
18
  }
17
19
  if (!name.trim()) {