@docusaurus/plugin-content-docs 3.10.2 → 4.0.0-canary-6809

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/client/doc.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { useMemo, useContext } from 'react';
8
- import { ReactContextError } from '@docusaurus/theme-common/internal';
8
+ import { ReactContextError } from '@docusaurus/theme-common';
9
9
  const Context = React.createContext(null);
10
10
  /**
11
11
  * Note: we don't use `PropDoc` as context value on purpose. Metadata is
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { useMemo, useState, useContext } from 'react';
8
- import { ReactContextError } from '@docusaurus/theme-common/internal';
8
+ import { ReactContextError } from '@docusaurus/theme-common';
9
9
  const EmptyContext = Symbol('EmptyContext');
10
10
  const Context = React.createContext(EmptyContext);
11
11
  /**
@@ -8,7 +8,7 @@ import React, { useContext, useEffect, useMemo, useState, useCallback, } from 'r
8
8
  import { useAllDocsData, useDocsData, } from '@docusaurus/plugin-content-docs/client';
9
9
  import { DEFAULT_PLUGIN_ID } from '@docusaurus/constants';
10
10
  import { useThemeConfig } from '@docusaurus/theme-common';
11
- import { ReactContextError, createStorageSlot, } from '@docusaurus/theme-common/internal';
11
+ import { ReactContextError, createStorageSlot } from '@docusaurus/theme-common';
12
12
  const storageKey = (pluginId) => `docs-preferred-version-${pluginId}`;
13
13
  const DocsPreferredVersionStorage = {
14
14
  save: (pluginId, persistence, versionName) => {
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { useMemo, useContext } from 'react';
8
- import { ReactContextError } from '@docusaurus/theme-common/internal';
8
+ import { ReactContextError } from '@docusaurus/theme-common';
9
9
  // Using a Symbol because null is a valid context value (a doc with no sidebar)
10
10
  // Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx
11
11
  const EmptyContext = Symbol('EmptyContext');
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { useContext } from 'react';
8
- import { ReactContextError } from '@docusaurus/theme-common/internal';
8
+ import { ReactContextError } from '@docusaurus/theme-common';
9
9
  const Context = React.createContext(null);
10
10
  /**
11
11
  * Provide the current version's metadata to your children.
@@ -5,8 +5,15 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
8
- export function useBreadcrumbsStructuredData({ breadcrumbs, }) {
9
- const { siteConfig } = useDocusaurusContext();
8
+ import { applyTrailingSlash } from '@docusaurus/utils-common';
9
+ function getAbsoluteUrl(permalink, params) {
10
+ const absoluteUrl = `${params.url}${permalink}`;
11
+ return applyTrailingSlash(absoluteUrl, {
12
+ trailingSlash: params.trailingSlash,
13
+ baseUrl: params.baseUrl,
14
+ });
15
+ }
16
+ function getBreadcrumbsStructuredData({ breadcrumbs, params, }) {
10
17
  return {
11
18
  '@context': 'https://schema.org',
12
19
  '@type': 'BreadcrumbList',
@@ -18,7 +25,11 @@ export function useBreadcrumbsStructuredData({ breadcrumbs, }) {
18
25
  '@type': 'ListItem',
19
26
  position: index + 1,
20
27
  name: breadcrumb.label,
21
- item: `${siteConfig.url}${breadcrumb.href}`,
28
+ item: getAbsoluteUrl(breadcrumb.href, params),
22
29
  })),
23
30
  };
24
31
  }
32
+ export function useBreadcrumbsStructuredData({ breadcrumbs, }) {
33
+ const { siteConfig } = useDocusaurusContext();
34
+ return getBreadcrumbsStructuredData({ breadcrumbs, params: siteConfig });
35
+ }
@@ -1,3 +1,9 @@
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
+ */
1
7
  import type { DocFrontMatter } from '@docusaurus/plugin-content-docs';
2
8
  export declare const DocFrontMatterSchema: import("joi").ObjectSchema<DocFrontMatter>;
3
9
  export declare function validateDocFrontMatter(frontMatter: {
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocFrontMatterSchema = void 0;
4
- exports.validateDocFrontMatter = validateDocFrontMatter;
5
2
  /**
6
3
  * Copyright (c) Facebook, Inc. and its affiliates.
7
4
  *
8
5
  * This source code is licensed under the MIT license found in the
9
6
  * LICENSE file in the root directory of this source tree.
10
7
  */
8
+ /* eslint-disable camelcase */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DocFrontMatterSchema = void 0;
11
+ exports.validateDocFrontMatter = validateDocFrontMatter;
11
12
  const utils_validation_1 = require("@docusaurus/utils-validation");
12
13
  // NOTE: we don't add any default value on purpose here
13
14
  // We don't want default values to magically appear in doc metadata and props
@@ -131,7 +131,7 @@ Available doc IDs:
131
131
  return undefined;
132
132
  }
133
133
  const id = link
134
- ? findDocByLocalId(link.id)?.id ?? getDoc(link.id).id
134
+ ? (findDocByLocalId(link.id)?.id ?? getDoc(link.id).id)
135
135
  : findConventionalCategoryDocLink()?.id;
136
136
  if (!id) {
137
137
  return undefined;
@@ -73,7 +73,7 @@ async function loadSidebarsFileUnsafe(sidebarFilePath) {
73
73
  return exports.DisabledSidebars;
74
74
  }
75
75
  // We don't want sidebars to be cached because of hot reloading.
76
- const module = await (0, utils_1.loadFreshModule)(sidebarFilePath);
76
+ const module = await (0, utils_1.loadFreshModule)(sidebarFilePath, { default: true });
77
77
  // TODO unsafe, need to refactor and improve validation
78
78
  return module;
79
79
  }
@@ -93,7 +93,7 @@ async function readVersionNames(siteDir, options) {
93
93
  if (!versionFileContent && options.disableVersioning) {
94
94
  throw new Error(`Docs: using "disableVersioning: true" option on a non-versioned site does not make sense.`);
95
95
  }
96
- const versions = options.disableVersioning ? [] : versionFileContent ?? [];
96
+ const versions = options.disableVersioning ? [] : (versionFileContent ?? []);
97
97
  // We add the current version at the beginning, unless:
98
98
  // - user don't want to; or
99
99
  // - it's already been explicitly added to versions.json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "3.10.2",
3
+ "version": "4.0.0-canary-6809",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -35,37 +35,37 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@docusaurus/core": "3.10.2",
39
- "@docusaurus/logger": "3.10.2",
40
- "@docusaurus/mdx-loader": "3.10.2",
41
- "@docusaurus/module-type-aliases": "3.10.2",
42
- "@docusaurus/theme-common": "3.10.2",
43
- "@docusaurus/types": "3.10.2",
44
- "@docusaurus/utils": "3.10.2",
45
- "@docusaurus/utils-common": "3.10.2",
46
- "@docusaurus/utils-validation": "3.10.2",
47
- "@types/react-router-config": "^5.0.7",
48
- "combine-promises": "^1.1.0",
49
- "fs-extra": "^11.1.1",
50
- "js-yaml": "^4.1.0",
51
- "lodash": "^4.17.21",
52
- "schema-dts": "^1.1.2",
53
- "tslib": "^2.6.0",
54
- "utility-types": "^3.10.0",
55
- "webpack": "^5.88.1"
38
+ "@docusaurus/core": "4.0.0-canary-6809",
39
+ "@docusaurus/logger": "4.0.0-canary-6809",
40
+ "@docusaurus/mdx-loader": "4.0.0-canary-6809",
41
+ "@docusaurus/module-type-aliases": "4.0.0-canary-6809",
42
+ "@docusaurus/theme-common": "4.0.0-canary-6809",
43
+ "@docusaurus/types": "4.0.0-canary-6809",
44
+ "@docusaurus/utils": "4.0.0-canary-6809",
45
+ "@docusaurus/utils-common": "4.0.0-canary-6809",
46
+ "@docusaurus/utils-validation": "4.0.0-canary-6809",
47
+ "@types/react-router-config": "^5.0.11",
48
+ "combine-promises": "^1.2.0",
49
+ "fs-extra": "^11.4.0",
50
+ "js-yaml": "^4.3.2",
51
+ "lodash": "^4.18.1",
52
+ "schema-dts": "^1.1.5",
53
+ "tslib": "^2.8.1",
54
+ "utility-types": "^3.11.0",
55
+ "webpack": "^5.110.3"
56
56
  },
57
57
  "devDependencies": {
58
- "@types/js-yaml": "^4.0.5",
59
- "@types/picomatch": "^2.3.0",
58
+ "@types/js-yaml": "^4.0.9",
59
+ "@types/picomatch": "^2.3.4",
60
60
  "commander": "^5.1.0",
61
- "picomatch": "^2.3.1"
61
+ "picomatch": "^2.3.2"
62
62
  },
63
63
  "peerDependencies": {
64
- "react": "^18.0.0 || ^19.0.0",
65
- "react-dom": "^18.0.0 || ^19.0.0"
64
+ "react": "^19.3.0",
65
+ "react-dom": "^19.3.0"
66
66
  },
67
67
  "engines": {
68
- "node": ">=20.0"
68
+ "node": ">=24.14"
69
69
  },
70
- "gitHead": "f37f9035584917a97a260b91fc2842cba4f8b94f"
70
+ "gitHead": "db942b07f3529b5359bcae27ab3796cb07dec10e"
71
71
  }
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import React, {useMemo, type ReactNode, useContext} from 'react';
9
- import {ReactContextError} from '@docusaurus/theme-common/internal';
9
+ import {ReactContextError} from '@docusaurus/theme-common';
10
10
  import type {PropDocContent} from '@docusaurus/plugin-content-docs';
11
11
 
12
12
  /**
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import React, {type ReactNode, useMemo, useState, useContext} from 'react';
9
- import {ReactContextError} from '@docusaurus/theme-common/internal';
9
+ import {ReactContextError} from '@docusaurus/theme-common';
10
10
 
11
11
  type ContextValue = {
12
12
  /**
@@ -21,10 +21,7 @@ import {
21
21
  } from '@docusaurus/plugin-content-docs/client';
22
22
  import {DEFAULT_PLUGIN_ID} from '@docusaurus/constants';
23
23
  import {useThemeConfig, type ThemeConfig} from '@docusaurus/theme-common';
24
- import {
25
- ReactContextError,
26
- createStorageSlot,
27
- } from '@docusaurus/theme-common/internal';
24
+ import {ReactContextError, createStorageSlot} from '@docusaurus/theme-common';
28
25
 
29
26
  type DocsVersionPersistence = ThemeConfig['docs']['versionPersistence'];
30
27
 
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ import {describe, expect, it} from 'vitest';
8
9
  import {getDocsVersionSearchTag} from './docsSearch';
9
10
 
10
11
  describe('getDocsVersionSearchTag', () => {
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import React, {useMemo, useContext, type ReactNode} from 'react';
9
- import {ReactContextError} from '@docusaurus/theme-common/internal';
9
+ import {ReactContextError} from '@docusaurus/theme-common';
10
10
  import type {PropSidebar} from '@docusaurus/plugin-content-docs';
11
11
 
12
12
  // Using a Symbol because null is a valid context value (a doc with no sidebar)
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import React, {type ReactNode, useContext} from 'react';
9
- import {ReactContextError} from '@docusaurus/theme-common/internal';
9
+ import {ReactContextError} from '@docusaurus/theme-common';
10
10
  import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';
11
11
 
12
12
  const Context = React.createContext<PropVersionMetadata | null>(null);
@@ -138,7 +138,7 @@ export const useDocsData = (pluginId: string | undefined): GlobalPluginData => {
138
138
  `You are using a feature of the Docusaurus docs plugin, but this plugin does not seem to be enabled${
139
139
  pluginId === 'Default' ? '' : ` (pluginId=${pluginId}`
140
140
  }`,
141
- {cause: error as Error},
141
+ {cause: error},
142
142
  );
143
143
  }
144
144
  };
@@ -6,15 +6,28 @@
6
6
  */
7
7
 
8
8
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
+ import {applyTrailingSlash} from '@docusaurus/utils-common';
9
10
  import type {PropSidebarBreadcrumbsItem} from '@docusaurus/plugin-content-docs';
10
11
  import type {WithContext, BreadcrumbList} from 'schema-dts';
12
+ import type {DocusaurusConfig} from '@docusaurus/types';
11
13
 
12
- export function useBreadcrumbsStructuredData({
14
+ type Params = Pick<DocusaurusConfig, 'url' | 'baseUrl' | 'trailingSlash'>;
15
+
16
+ function getAbsoluteUrl(permalink: string, params: Params): string {
17
+ const absoluteUrl = `${params.url}${permalink}`;
18
+ return applyTrailingSlash(absoluteUrl, {
19
+ trailingSlash: params.trailingSlash,
20
+ baseUrl: params.baseUrl,
21
+ });
22
+ }
23
+
24
+ function getBreadcrumbsStructuredData({
13
25
  breadcrumbs,
26
+ params,
14
27
  }: {
15
28
  breadcrumbs: PropSidebarBreadcrumbsItem[];
29
+ params: Params;
16
30
  }): WithContext<BreadcrumbList> {
17
- const {siteConfig} = useDocusaurusContext();
18
31
  return {
19
32
  '@context': 'https://schema.org',
20
33
  '@type': 'BreadcrumbList',
@@ -26,7 +39,16 @@ export function useBreadcrumbsStructuredData({
26
39
  '@type': 'ListItem',
27
40
  position: index + 1,
28
41
  name: breadcrumb.label,
29
- item: `${siteConfig.url}${breadcrumb.href}`,
42
+ item: getAbsoluteUrl(breadcrumb.href!, params),
30
43
  })),
31
44
  };
32
45
  }
46
+
47
+ export function useBreadcrumbsStructuredData({
48
+ breadcrumbs,
49
+ }: {
50
+ breadcrumbs: PropSidebarBreadcrumbsItem[];
51
+ }): WithContext<BreadcrumbList> {
52
+ const {siteConfig} = useDocusaurusContext();
53
+ return getBreadcrumbsStructuredData({breadcrumbs, params: siteConfig});
54
+ }
package/src/docs.ts CHANGED
@@ -258,7 +258,7 @@ export async function processDocMetadata(args: {
258
258
  } catch (err) {
259
259
  throw new Error(
260
260
  `Can't process doc metadata for doc at path path=${args.docFile.filePath} in version name=${args.versionMetadata.versionName}`,
261
- {cause: err as Error},
261
+ {cause: err},
262
262
  );
263
263
  }
264
264
  }
@@ -4,6 +4,8 @@
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
+ /* eslint-disable camelcase */
8
+
7
9
  import {
8
10
  JoiFrontMatter as Joi, // Custom instance for front matter
9
11
  URISchema,
@@ -206,7 +206,7 @@ Available doc IDs:
206
206
  return undefined;
207
207
  }
208
208
  const id = link
209
- ? findDocByLocalId(link.id)?.id ?? getDoc(link.id).id
209
+ ? (findDocByLocalId(link.id)?.id ?? getDoc(link.id).id)
210
210
  : findConventionalCategoryDocLink()?.id;
211
211
  if (!id) {
212
212
  return undefined;
@@ -88,7 +88,7 @@ async function loadSidebarsFileUnsafe(
88
88
  }
89
89
 
90
90
  // We don't want sidebars to be cached because of hot reloading.
91
- const module = await loadFreshModule(sidebarFilePath);
91
+ const module = await loadFreshModule(sidebarFilePath, {default: true});
92
92
 
93
93
  // TODO unsafe, need to refactor and improve validation
94
94
  return module as SidebarsConfig;
@@ -145,7 +145,7 @@ export async function readVersionNames(
145
145
  );
146
146
  }
147
147
 
148
- const versions = options.disableVersioning ? [] : versionFileContent ?? [];
148
+ const versions = options.disableVersioning ? [] : (versionFileContent ?? []);
149
149
 
150
150
  // We add the current version at the beginning, unless:
151
151
  // - user don't want to; or