@docusaurus/plugin-content-docs 0.0.0-4710 → 0.0.0-4713

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/docs.d.ts CHANGED
@@ -30,22 +30,11 @@ export declare function getMainDocId({ docs, sidebarsUtils, }: {
30
30
  sidebarsUtils: SidebarsUtils;
31
31
  }): string;
32
32
  export declare const isCategoryIndex: CategoryIndexMatcher;
33
- export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): CategoryIndexMatcherParam;
34
33
  /**
35
34
  * `guides/sidebar/autogenerated.md` ->
36
35
  * `'autogenerated', '.md', ['sidebar', 'guides']`
37
36
  */
38
- export declare function splitPath(str: string): {
39
- /**
40
- * The list of directories, from lowest level to highest.
41
- * If there's no dir name, directories is ['.']
42
- */
43
- directories: string[];
44
- /** The file name, without extension */
45
- fileName: string;
46
- /** The extension, with a leading dot */
47
- extension: string;
48
- };
37
+ export declare function toCategoryIndexMatcherParam({ source, sourceDirName, }: Pick<DocMetadataBase, 'source' | 'sourceDirName'>): CategoryIndexMatcherParam;
49
38
  export declare function getDocIds(doc: DocMetadataBase): [string, string];
50
39
  export declare function createDocsByIdIndex<Doc extends {
51
40
  id: string;
package/lib/docs.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.createDocsByIdIndex = exports.getDocIds = exports.splitPath = exports.toCategoryIndexMatcherParam = exports.isCategoryIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
9
+ exports.createDocsByIdIndex = exports.getDocIds = exports.toCategoryIndexMatcherParam = exports.isCategoryIndex = exports.getMainDocId = exports.addDocNavigation = exports.processDocMetadata = exports.readVersionDocs = exports.readDocFile = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
@@ -248,6 +248,10 @@ const isCategoryIndex = ({ fileName, directories, }) => {
248
248
  return eligibleDocIndexNames.includes(fileName.toLowerCase());
249
249
  };
250
250
  exports.isCategoryIndex = isCategoryIndex;
251
+ /**
252
+ * `guides/sidebar/autogenerated.md` ->
253
+ * `'autogenerated', '.md', ['sidebar', 'guides']`
254
+ */
251
255
  function toCategoryIndexMatcherParam({ source, sourceDirName, }) {
252
256
  // source + sourceDirName are always posix-style
253
257
  return {
@@ -257,18 +261,6 @@ function toCategoryIndexMatcherParam({ source, sourceDirName, }) {
257
261
  };
258
262
  }
259
263
  exports.toCategoryIndexMatcherParam = toCategoryIndexMatcherParam;
260
- /**
261
- * `guides/sidebar/autogenerated.md` ->
262
- * `'autogenerated', '.md', ['sidebar', 'guides']`
263
- */
264
- function splitPath(str) {
265
- return {
266
- fileName: path_1.default.parse(str).name,
267
- extension: path_1.default.parse(str).ext,
268
- directories: path_1.default.dirname(str).split(path_1.default.sep).reverse(),
269
- };
270
- }
271
- exports.splitPath = splitPath;
272
264
  // Return both doc ids
273
265
  // TODO legacy retro-compatibility due to old versioned sidebars using
274
266
  // versioned doc ids ("id" should be removed & "versionedId" should be renamed
@@ -4,10 +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
- import type { Sidebars } from './sidebars/types';
8
- import type { CategoryGeneratedIndexMetadata, DocMetadata, LoadedVersion } from './types';
9
- import type { GlobalVersion, GlobalSidebar, GlobalDoc } from '@docusaurus/plugin-content-docs/client';
10
- export declare function toGlobalDataDoc(doc: DocMetadata): GlobalDoc;
11
- export declare function toGlobalDataGeneratedIndex(doc: CategoryGeneratedIndexMetadata): GlobalDoc;
12
- export declare function toGlobalSidebars(sidebars: Sidebars, version: LoadedVersion): Record<string, GlobalSidebar>;
7
+ import type { LoadedVersion } from './types';
8
+ import type { GlobalVersion } from '@docusaurus/plugin-content-docs/client';
13
9
  export declare function toGlobalDataVersion(version: LoadedVersion): GlobalVersion;
package/lib/globalData.js CHANGED
@@ -6,11 +6,10 @@
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 = exports.toGlobalSidebars = exports.toGlobalDataGeneratedIndex = exports.toGlobalDataDoc = void 0;
9
+ exports.toGlobalDataVersion = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
- const utils_1 = require("@docusaurus/utils");
13
- const utils_2 = require("./sidebars/utils");
12
+ const utils_1 = require("./sidebars/utils");
14
13
  function toGlobalDataDoc(doc) {
15
14
  return {
16
15
  id: doc.unversionedId,
@@ -18,7 +17,6 @@ function toGlobalDataDoc(doc) {
18
17
  sidebar: doc.sidebar,
19
18
  };
20
19
  }
21
- exports.toGlobalDataDoc = toGlobalDataDoc;
22
20
  function toGlobalDataGeneratedIndex(doc) {
23
21
  return {
24
22
  id: doc.slug,
@@ -26,9 +24,8 @@ function toGlobalDataGeneratedIndex(doc) {
26
24
  sidebar: doc.sidebar,
27
25
  };
28
26
  }
29
- exports.toGlobalDataGeneratedIndex = toGlobalDataGeneratedIndex;
30
27
  function toGlobalSidebars(sidebars, version) {
31
- const { getFirstLink } = (0, utils_2.createSidebarsUtils)(sidebars);
28
+ const { getFirstLink } = (0, utils_1.createSidebarsUtils)(sidebars);
32
29
  return lodash_1.default.mapValues(sidebars, (sidebar, sidebarId) => {
33
30
  const firstLink = getFirstLink(sidebarId);
34
31
  if (!firstLink) {
@@ -37,14 +34,13 @@ function toGlobalSidebars(sidebars, version) {
37
34
  return {
38
35
  link: {
39
36
  path: firstLink.type === 'generated-index'
40
- ? (0, utils_1.normalizeUrl)([version.versionPath, firstLink.slug])
37
+ ? firstLink.permalink
41
38
  : version.docs.find((doc) => doc.id === firstLink.id || doc.unversionedId === firstLink.id).permalink,
42
39
  label: firstLink.label,
43
40
  },
44
41
  };
45
42
  });
46
43
  }
47
- exports.toGlobalSidebars = toGlobalSidebars;
48
44
  function toGlobalDataVersion(version) {
49
45
  return {
50
46
  name: version.versionName,
@@ -27,13 +27,18 @@ export declare type SidebarsUtils = {
27
27
  getDocNavigation: (unversionedId: string, versionedId: string, displayedSidebar: string | null | undefined) => SidebarNavigation;
28
28
  getCategoryGeneratedIndexList: () => SidebarItemCategoryWithGeneratedIndex[];
29
29
  getCategoryGeneratedIndexNavigation: (categoryGeneratedIndexPermalink: string) => SidebarNavigation;
30
+ /**
31
+ * This function may return undefined. This is usually a user mistake, because
32
+ * it means this sidebar will never be displayed; however, we can still use
33
+ * `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
34
+ */
30
35
  getFirstLink: (sidebarId: string) => {
31
36
  type: 'doc';
32
37
  id: string;
33
38
  label: string;
34
39
  } | {
35
40
  type: 'generated-index';
36
- slug: string;
41
+ permalink: string;
37
42
  label: string;
38
43
  } | undefined;
39
44
  checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
@@ -196,7 +196,7 @@ Available document ids are:
196
196
  else if (item.link?.type === 'generated-index') {
197
197
  return {
198
198
  type: 'generated-index',
199
- slug: item.link.slug,
199
+ permalink: item.link.permalink,
200
200
  label: item.label,
201
201
  };
202
202
  }
package/lib/slug.js CHANGED
@@ -33,12 +33,11 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
33
33
  }
34
34
  function ensureValidSlug(slug) {
35
35
  if (!(0, utils_1.isValidPathname)(slug)) {
36
- throw new Error(`We couldn't compute a valid slug for document with id "${baseID}" in "${sourceDirName}" directory.
36
+ throw new Error(`We couldn't compute a valid slug for document with ID "${baseID}" in "${sourceDirName}" directory.
37
37
  The slug we computed looks invalid: ${slug}.
38
- Maybe your slug front matter is incorrect or you use weird chars in the file path?
39
- By using the slug front matter, you should be able to fix this error, by using the slug of your choice:
38
+ Maybe your slug front matter is incorrect or there are special characters in the file path?
39
+ By using front matter to set a custom slug, you should be able to fix this error:
40
40
 
41
- Example =>
42
41
  ---
43
42
  slug: /my/customDocPath
44
43
  ---
@@ -195,10 +195,7 @@ function getVersionTranslationFiles(version) {
195
195
  ];
196
196
  }
197
197
  function translateVersion(version, translationFiles) {
198
- const versionTranslations = translationFiles[getVersionFileName(version.versionName)]?.content;
199
- if (!versionTranslations) {
200
- return version;
201
- }
198
+ const versionTranslations = translationFiles[getVersionFileName(version.versionName)].content;
202
199
  return {
203
200
  ...version,
204
201
  versionLabel: versionTranslations['version.label']?.message ?? version.versionLabel,
package/lib/versions.js CHANGED
@@ -42,8 +42,8 @@ function ensureValidVersionString(version) {
42
42
  }
43
43
  }
44
44
  function ensureValidVersionArray(versionArray) {
45
- if (!(versionArray instanceof Array)) {
46
- throw new Error(`The versions file should contain an array of versions! Found content: ${JSON.stringify(versionArray)}`);
45
+ if (!Array.isArray(versionArray)) {
46
+ throw new Error(`The versions file should contain an array of version names! Found content: ${JSON.stringify(versionArray)}`);
47
47
  }
48
48
  versionArray.forEach(ensureValidVersionString);
49
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4710",
3
+ "version": "0.0.0-4713",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -23,11 +23,11 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4710",
27
- "@docusaurus/logger": "0.0.0-4710",
28
- "@docusaurus/mdx-loader": "0.0.0-4710",
29
- "@docusaurus/utils": "0.0.0-4710",
30
- "@docusaurus/utils-validation": "0.0.0-4710",
26
+ "@docusaurus/core": "0.0.0-4713",
27
+ "@docusaurus/logger": "0.0.0-4713",
28
+ "@docusaurus/mdx-loader": "0.0.0-4713",
29
+ "@docusaurus/utils": "0.0.0-4713",
30
+ "@docusaurus/utils-validation": "0.0.0-4713",
31
31
  "combine-promises": "^1.1.0",
32
32
  "fs-extra": "^10.0.1",
33
33
  "import-fresh": "^3.3.0",
@@ -39,8 +39,8 @@
39
39
  "webpack": "^5.70.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@docusaurus/module-type-aliases": "0.0.0-4710",
43
- "@docusaurus/types": "0.0.0-4710",
42
+ "@docusaurus/module-type-aliases": "0.0.0-4713",
43
+ "@docusaurus/types": "0.0.0-4713",
44
44
  "@types/js-yaml": "^4.0.5",
45
45
  "@types/picomatch": "^2.3.0",
46
46
  "commander": "^5.1.0",
@@ -56,5 +56,5 @@
56
56
  "engines": {
57
57
  "node": ">=14"
58
58
  },
59
- "gitHead": "b87b7d90b4b0f155d034b52406c2056ea1dced54"
59
+ "gitHead": "43c65e82adb2329758821232b7157fceb9830980"
60
60
  }
@@ -25,7 +25,7 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
25
25
  hide_table_of_contents: Joi.boolean(),
26
26
  keywords: Joi.array().items(Joi.string().required()),
27
27
  image: URISchema,
28
- description: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
28
+ description: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
29
29
  slug: Joi.string(),
30
30
  sidebar_label: Joi.string(),
31
31
  sidebar_position: Joi.number(),
package/src/docs.ts CHANGED
@@ -391,6 +391,10 @@ export const isCategoryIndex: CategoryIndexMatcher = ({
391
391
  return eligibleDocIndexNames.includes(fileName.toLowerCase());
392
392
  };
393
393
 
394
+ /**
395
+ * `guides/sidebar/autogenerated.md` ->
396
+ * `'autogenerated', '.md', ['sidebar', 'guides']`
397
+ */
394
398
  export function toCategoryIndexMatcherParam({
395
399
  source,
396
400
  sourceDirName,
@@ -406,28 +410,6 @@ export function toCategoryIndexMatcherParam({
406
410
  };
407
411
  }
408
412
 
409
- /**
410
- * `guides/sidebar/autogenerated.md` ->
411
- * `'autogenerated', '.md', ['sidebar', 'guides']`
412
- */
413
- export function splitPath(str: string): {
414
- /**
415
- * The list of directories, from lowest level to highest.
416
- * If there's no dir name, directories is ['.']
417
- */
418
- directories: string[];
419
- /** The file name, without extension */
420
- fileName: string;
421
- /** The extension, with a leading dot */
422
- extension: string;
423
- } {
424
- return {
425
- fileName: path.parse(str).name,
426
- extension: path.parse(str).ext,
427
- directories: path.dirname(str).split(path.sep).reverse(),
428
- };
429
- }
430
-
431
413
  // Return both doc ids
432
414
  // TODO legacy retro-compatibility due to old versioned sidebars using
433
415
  // versioned doc ids ("id" should be removed & "versionedId" should be renamed
package/src/globalData.ts CHANGED
@@ -6,7 +6,6 @@
6
6
  */
7
7
 
8
8
  import _ from 'lodash';
9
- import {normalizeUrl} from '@docusaurus/utils';
10
9
  import type {Sidebars} from './sidebars/types';
11
10
  import {createSidebarsUtils} from './sidebars/utils';
12
11
  import type {
@@ -20,7 +19,7 @@ import type {
20
19
  GlobalDoc,
21
20
  } from '@docusaurus/plugin-content-docs/client';
22
21
 
23
- export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
22
+ function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
24
23
  return {
25
24
  id: doc.unversionedId,
26
25
  path: doc.permalink,
@@ -28,7 +27,7 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
28
27
  };
29
28
  }
30
29
 
31
- export function toGlobalDataGeneratedIndex(
30
+ function toGlobalDataGeneratedIndex(
32
31
  doc: CategoryGeneratedIndexMetadata,
33
32
  ): GlobalDoc {
34
33
  return {
@@ -38,7 +37,7 @@ export function toGlobalDataGeneratedIndex(
38
37
  };
39
38
  }
40
39
 
41
- export function toGlobalSidebars(
40
+ function toGlobalSidebars(
42
41
  sidebars: Sidebars,
43
42
  version: LoadedVersion,
44
43
  ): Record<string, GlobalSidebar> {
@@ -52,7 +51,7 @@ export function toGlobalSidebars(
52
51
  link: {
53
52
  path:
54
53
  firstLink.type === 'generated-index'
55
- ? normalizeUrl([version.versionPath, firstLink.slug])
54
+ ? firstLink.permalink
56
55
  : version.docs.find(
57
56
  (doc) =>
58
57
  doc.id === firstLink.id || doc.unversionedId === firstLink.id,
@@ -18,8 +18,14 @@ declare module '@docusaurus/plugin-content-docs' {
18
18
  };
19
19
 
20
20
  export type CategoryIndexMatcherParam = {
21
+ /** The file name, without extension */
21
22
  fileName: string;
23
+ /**
24
+ * The list of directories, from lowest level to highest.
25
+ * If there's no dir name, directories is ['.']
26
+ */
22
27
  directories: string[];
28
+ /** The extension, with a leading dot */
23
29
  extension: string;
24
30
  };
25
31
  export type CategoryIndexMatcher = (
@@ -139,6 +139,11 @@ export type SidebarsUtils = {
139
139
  getCategoryGeneratedIndexNavigation: (
140
140
  categoryGeneratedIndexPermalink: string,
141
141
  ) => SidebarNavigation;
142
+ /**
143
+ * This function may return undefined. This is usually a user mistake, because
144
+ * it means this sidebar will never be displayed; however, we can still use
145
+ * `displayed_sidebar` to make it displayed. Pretty weird but valid use-case
146
+ */
142
147
  getFirstLink: (sidebarId: string) =>
143
148
  | {
144
149
  type: 'doc';
@@ -147,7 +152,7 @@ export type SidebarsUtils = {
147
152
  }
148
153
  | {
149
154
  type: 'generated-index';
150
- slug: string;
155
+ permalink: string;
151
156
  label: string;
152
157
  }
153
158
  | undefined;
@@ -295,7 +300,7 @@ Available document ids are:
295
300
  }
296
301
  | {
297
302
  type: 'generated-index';
298
- slug: string;
303
+ permalink: string;
299
304
  label: string;
300
305
  }
301
306
  | undefined {
@@ -316,7 +321,7 @@ Available document ids are:
316
321
  } else if (item.link?.type === 'generated-index') {
317
322
  return {
318
323
  type: 'generated-index',
319
- slug: item.link.slug,
324
+ permalink: item.link.permalink,
320
325
  label: item.label,
321
326
  };
322
327
  }
package/src/slug.ts CHANGED
@@ -63,12 +63,11 @@ export default function getSlug({
63
63
  function ensureValidSlug(slug: string): string {
64
64
  if (!isValidPathname(slug)) {
65
65
  throw new Error(
66
- `We couldn't compute a valid slug for document with id "${baseID}" in "${sourceDirName}" directory.
66
+ `We couldn't compute a valid slug for document with ID "${baseID}" in "${sourceDirName}" directory.
67
67
  The slug we computed looks invalid: ${slug}.
68
- Maybe your slug front matter is incorrect or you use weird chars in the file path?
69
- By using the slug front matter, you should be able to fix this error, by using the slug of your choice:
68
+ Maybe your slug front matter is incorrect or there are special characters in the file path?
69
+ By using front matter to set a custom slug, you should be able to fix this error:
70
70
 
71
- Example =>
72
71
  ---
73
72
  slug: /my/customDocPath
74
73
  ---
@@ -274,10 +274,7 @@ function translateVersion(
274
274
  translationFiles: Record<string, TranslationFile>,
275
275
  ): LoadedVersion {
276
276
  const versionTranslations =
277
- translationFiles[getVersionFileName(version.versionName)]?.content;
278
- if (!versionTranslations) {
279
- return version;
280
- }
277
+ translationFiles[getVersionFileName(version.versionName)]!.content;
281
278
  return {
282
279
  ...version,
283
280
  versionLabel:
package/src/versions.ts CHANGED
@@ -74,9 +74,9 @@ function ensureValidVersionString(version: unknown): asserts version is string {
74
74
  function ensureValidVersionArray(
75
75
  versionArray: unknown,
76
76
  ): asserts versionArray is string[] {
77
- if (!(versionArray instanceof Array)) {
77
+ if (!Array.isArray(versionArray)) {
78
78
  throw new Error(
79
- `The versions file should contain an array of versions! Found content: ${JSON.stringify(
79
+ `The versions file should contain an array of version names! Found content: ${JSON.stringify(
80
80
  versionArray,
81
81
  )}`,
82
82
  );