@docusaurus/core 2.0.0-beta.1decd6f80 → 2.0.0-beta.20
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/bin/beforeCli.mjs +138 -0
- package/bin/docusaurus.mjs +228 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/client/.eslintrc.js +2 -4
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +30 -27
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +24 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +39 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +11 -5
- package/lib/client/docusaurus.js +29 -42
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +67 -41
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +44 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +9 -13
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +11 -31
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +7 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +91 -132
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +49 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +77 -61
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +32 -20
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +91 -71
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +6 -11
- package/lib/commands/serve.d.ts +7 -2
- package/lib/commands/serve.js +31 -18
- package/lib/commands/start.d.ts +8 -2
- package/lib/commands/start.js +105 -91
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +83 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +116 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +21 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +41 -23
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +65 -54
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +14 -6
- package/lib/server/configValidation.d.ts +4 -2
- package/lib/server/configValidation.js +96 -39
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +19 -55
- package/lib/server/index.d.ts +28 -6
- package/lib/server/index.js +82 -171
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +10 -10
- package/lib/server/plugins/index.js +74 -125
- package/lib/server/plugins/init.d.ts +6 -9
- package/lib/server/plugins/init.js +43 -108
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +6 -2
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +112 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +185 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +13 -17
- package/lib/server/translations/translations.js +37 -61
- package/lib/server/translations/translationsExtractor.d.ts +10 -5
- package/lib/server/translations/translationsExtractor.js +159 -121
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +53 -55
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +8 -8
- package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +18 -8
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
- package/lib/webpack/utils.d.ts +16 -31
- package/lib/webpack/utils.js +59 -177
- package/package.json +77 -73
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5682
- package/lib/choosePort.js +0 -105
- package/lib/client/.tsbuildinfo +0 -4127
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -39
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -39
- package/lib/server/themes/index.d.ts +0 -8
- package/lib/server/themes/index.js +0 -35
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -7,17 +7,22 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ensureUniquePluginInstanceIds = void 0;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
/**
|
|
14
|
+
* It is forbidden to have 2 plugins of the same name sharing the same ID.
|
|
15
|
+
* This is required to support multi-instance plugins without conflict.
|
|
16
|
+
*/
|
|
14
17
|
function ensureUniquePluginInstanceIds(plugins) {
|
|
15
|
-
const pluginsByName = lodash_1.groupBy(plugins, (p) => p.name);
|
|
18
|
+
const pluginsByName = lodash_1.default.groupBy(plugins, (p) => p.name);
|
|
16
19
|
Object.entries(pluginsByName).forEach(([pluginName, pluginInstances]) => {
|
|
17
|
-
const pluginInstancesById = lodash_1.groupBy(pluginInstances, (p) =>
|
|
20
|
+
const pluginInstancesById = lodash_1.default.groupBy(pluginInstances, (p) => p.options.id ?? utils_1.DEFAULT_PLUGIN_ID);
|
|
18
21
|
Object.entries(pluginInstancesById).forEach(([pluginId, pluginInstancesWithId]) => {
|
|
19
22
|
if (pluginInstancesWithId.length !== 1) {
|
|
20
|
-
throw new Error(`Plugin ${pluginName} is used ${pluginInstancesWithId.length} times with
|
|
23
|
+
throw new Error(`Plugin "${pluginName}" is used ${pluginInstancesWithId.length} times with ID "${pluginId}".\nTo use the same plugin multiple times on a Docusaurus site, you need to assign a unique ID to each plugin instance.${pluginId === utils_1.DEFAULT_PLUGIN_ID
|
|
24
|
+
? `\n\nThe plugin ID is "${utils_1.DEFAULT_PLUGIN_ID}" by default. It's possible that the preset you are using already includes a plugin instance, in which case you either want to disable the plugin in the preset (to use a single instance), or assign another ID to your extra plugin instance (to use multiple instances).`
|
|
25
|
+
: ''}`);
|
|
21
26
|
}
|
|
22
27
|
});
|
|
23
28
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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 type { LoadContext, DocusaurusConfig } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Calls preset functions, aggregates each of their return values, and returns
|
|
10
|
+
* the plugin and theme configs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadPresets(context: LoadContext): Promise<Pick<DocusaurusConfig, 'plugins' | 'themes'>>;
|
|
@@ -0,0 +1,49 @@
|
|
|
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.loadPresets = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
13
|
+
const moduleShorthand_1 = require("./moduleShorthand");
|
|
14
|
+
/**
|
|
15
|
+
* Calls preset functions, aggregates each of their return values, and returns
|
|
16
|
+
* the plugin and theme configs.
|
|
17
|
+
*/
|
|
18
|
+
async function loadPresets(context) {
|
|
19
|
+
// We need to resolve plugins from the perspective of the site config, as if
|
|
20
|
+
// we are using `require.resolve` on those module names.
|
|
21
|
+
const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
|
|
22
|
+
const { presets } = context.siteConfig;
|
|
23
|
+
const plugins = [];
|
|
24
|
+
const themes = [];
|
|
25
|
+
presets.forEach((presetItem) => {
|
|
26
|
+
let presetModuleImport;
|
|
27
|
+
let presetOptions = {};
|
|
28
|
+
if (!presetItem) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (typeof presetItem === 'string') {
|
|
32
|
+
presetModuleImport = presetItem;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
[presetModuleImport, presetOptions] = presetItem;
|
|
36
|
+
}
|
|
37
|
+
const presetName = (0, moduleShorthand_1.resolveModuleName)(presetModuleImport, presetRequire, 'preset');
|
|
38
|
+
const presetModule = (0, import_fresh_1.default)(presetRequire.resolve(presetName));
|
|
39
|
+
const preset = (presetModule.default ?? presetModule)(context, presetOptions);
|
|
40
|
+
if (preset.plugins) {
|
|
41
|
+
plugins.push(...preset.plugins);
|
|
42
|
+
}
|
|
43
|
+
if (preset.themes) {
|
|
44
|
+
themes.push(...preset.themes);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return { plugins, themes };
|
|
48
|
+
}
|
|
49
|
+
exports.loadPresets = loadPresets;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 type { RouteConfig } from '@docusaurus/types';
|
|
8
|
+
import { type ApplyTrailingSlashParams } from '@docusaurus/utils-common';
|
|
9
|
+
/** Recursively applies trailing slash config to all nested routes. */
|
|
10
|
+
export declare function applyRouteTrailingSlash(route: RouteConfig, params: ApplyTrailingSlashParams): RouteConfig;
|
|
11
|
+
export declare function sortConfig(routeConfigs: RouteConfig[], baseUrl?: string): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
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.sortConfig = exports.applyRouteTrailingSlash = void 0;
|
|
10
|
+
const utils_common_1 = require("@docusaurus/utils-common");
|
|
11
|
+
/** Recursively applies trailing slash config to all nested routes. */
|
|
12
|
+
function applyRouteTrailingSlash(route, params) {
|
|
13
|
+
return {
|
|
14
|
+
...route,
|
|
15
|
+
path: (0, utils_common_1.applyTrailingSlash)(route.path, params),
|
|
16
|
+
...(route.routes && {
|
|
17
|
+
routes: route.routes.map((subroute) => applyRouteTrailingSlash(subroute, params)),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.applyRouteTrailingSlash = applyRouteTrailingSlash;
|
|
22
|
+
function sortConfig(routeConfigs, baseUrl = '/') {
|
|
23
|
+
// Sort the route config. This ensures that route with nested
|
|
24
|
+
// routes is always placed last.
|
|
25
|
+
routeConfigs.sort((a, b) => {
|
|
26
|
+
// Root route should get placed last.
|
|
27
|
+
if (a.path === baseUrl && b.path !== baseUrl) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
if (a.path !== baseUrl && b.path === baseUrl) {
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
if (a.routes && !b.routes) {
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
if (!a.routes && b.routes) {
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
// Higher priority get placed first.
|
|
40
|
+
if (a.priority || b.priority) {
|
|
41
|
+
const priorityA = a.priority || 0;
|
|
42
|
+
const priorityB = b.priority || 0;
|
|
43
|
+
const score = priorityB - priorityA;
|
|
44
|
+
if (score !== 0) {
|
|
45
|
+
return score;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return a.path.localeCompare(b.path);
|
|
49
|
+
});
|
|
50
|
+
routeConfigs.forEach((routeConfig) => {
|
|
51
|
+
routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.sortConfig = sortConfig;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 type { LoadedPlugin, LoadContext } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Make a synthetic plugin to:
|
|
10
|
+
* - Inject site client modules
|
|
11
|
+
* - Inject scripts/stylesheets
|
|
12
|
+
*/
|
|
13
|
+
export declare function createBootstrapPlugin({ siteDir, siteConfig, }: LoadContext): LoadedPlugin;
|
|
14
|
+
/**
|
|
15
|
+
* Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
|
|
16
|
+
* folders. Adds a "fallback" mdx loader for mdx files that are not processed by
|
|
17
|
+
* content plugins. This allows to do things such as importing repo/README.md as
|
|
18
|
+
* a partial from another doc. Not ideal solution, but good enough for now
|
|
19
|
+
*/
|
|
20
|
+
export declare function createMDXFallbackPlugin({ siteDir, siteConfig, }: LoadContext): LoadedPlugin;
|
|
@@ -0,0 +1,112 @@
|
|
|
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.createMDXFallbackPlugin = exports.createBootstrapPlugin = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
|
|
13
|
+
/**
|
|
14
|
+
* Make a synthetic plugin to:
|
|
15
|
+
* - Inject site client modules
|
|
16
|
+
* - Inject scripts/stylesheets
|
|
17
|
+
*/
|
|
18
|
+
function createBootstrapPlugin({ siteDir, siteConfig, }) {
|
|
19
|
+
const { stylesheets, scripts, clientModules: siteConfigClientModules, } = siteConfig;
|
|
20
|
+
return {
|
|
21
|
+
name: 'docusaurus-bootstrap-plugin',
|
|
22
|
+
content: null,
|
|
23
|
+
options: {
|
|
24
|
+
id: 'default',
|
|
25
|
+
},
|
|
26
|
+
version: { type: 'synthetic' },
|
|
27
|
+
path: siteDir,
|
|
28
|
+
getClientModules() {
|
|
29
|
+
return siteConfigClientModules;
|
|
30
|
+
},
|
|
31
|
+
injectHtmlTags: () => {
|
|
32
|
+
const stylesheetsTags = stylesheets.map((source) => typeof source === 'string'
|
|
33
|
+
? `<link rel="stylesheet" href="${source}">`
|
|
34
|
+
: {
|
|
35
|
+
tagName: 'link',
|
|
36
|
+
attributes: {
|
|
37
|
+
rel: 'stylesheet',
|
|
38
|
+
...source,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const scriptsTags = scripts.map((source) => typeof source === 'string'
|
|
42
|
+
? `<script src="${source}"></script>`
|
|
43
|
+
: {
|
|
44
|
+
tagName: 'script',
|
|
45
|
+
attributes: {
|
|
46
|
+
...source,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
headTags: [...stylesheetsTags, ...scriptsTags],
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.createBootstrapPlugin = createBootstrapPlugin;
|
|
56
|
+
/**
|
|
57
|
+
* Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
|
|
58
|
+
* folders. Adds a "fallback" mdx loader for mdx files that are not processed by
|
|
59
|
+
* content plugins. This allows to do things such as importing repo/README.md as
|
|
60
|
+
* a partial from another doc. Not ideal solution, but good enough for now
|
|
61
|
+
*/
|
|
62
|
+
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
63
|
+
return {
|
|
64
|
+
name: 'docusaurus-mdx-fallback-plugin',
|
|
65
|
+
content: null,
|
|
66
|
+
options: {
|
|
67
|
+
id: 'default',
|
|
68
|
+
},
|
|
69
|
+
version: { type: 'synthetic' },
|
|
70
|
+
// Synthetic, the path doesn't matter much
|
|
71
|
+
path: '.',
|
|
72
|
+
configureWebpack(config, isServer, { getJSLoader }) {
|
|
73
|
+
// We need the mdx fallback loader to exclude files that were already
|
|
74
|
+
// processed by content plugins mdx loaders. This works, but a bit
|
|
75
|
+
// hacky... Not sure there's a way to handle that differently in webpack
|
|
76
|
+
function getMDXFallbackExcludedPaths() {
|
|
77
|
+
const rules = config?.module?.rules;
|
|
78
|
+
return rules.flatMap((rule) => {
|
|
79
|
+
const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
|
|
80
|
+
return isMDXRule ? rule.include : [];
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const mdxLoaderOptions = {
|
|
84
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
85
|
+
siteDir,
|
|
86
|
+
// External MDX files are always meant to be imported as partials
|
|
87
|
+
isMDXPartial: () => true,
|
|
88
|
+
// External MDX files might have front matter, just disable the warning
|
|
89
|
+
isMDXPartialFrontMatterWarningDisabled: true,
|
|
90
|
+
remarkPlugins: [remark_admonitions_1.default],
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
module: {
|
|
94
|
+
rules: [
|
|
95
|
+
{
|
|
96
|
+
test: /\.mdx?$/i,
|
|
97
|
+
exclude: getMDXFallbackExcludedPaths(),
|
|
98
|
+
use: [
|
|
99
|
+
getJSLoader({ isServer }),
|
|
100
|
+
{
|
|
101
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
102
|
+
options: mdxLoaderOptions,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
exports.createMDXFallbackPlugin = createMDXFallbackPlugin;
|
package/lib/server/routes.d.ts
CHANGED
|
@@ -4,16 +4,48 @@
|
|
|
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 {
|
|
7
|
+
import type { RouteConfig, RouteChunkNames, ReportingSeverity } from '@docusaurus/types';
|
|
8
8
|
declare type LoadedRoutes = {
|
|
9
|
-
|
|
10
|
-
[chunkName: string]: ChunkRegistry;
|
|
11
|
-
};
|
|
9
|
+
/** Serialized routes config that can be directly emitted into temp file. */
|
|
12
10
|
routesConfig: string;
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/** @see {ChunkNames} */
|
|
12
|
+
routesChunkNames: RouteChunkNames;
|
|
13
|
+
/**
|
|
14
|
+
* A map from chunk name to module paths. Module paths would have backslash
|
|
15
|
+
* escaped already, so they can be directly printed.
|
|
16
|
+
*/
|
|
17
|
+
registry: {
|
|
18
|
+
[chunkName: string]: string;
|
|
15
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Collect all page paths for injecting it later in the plugin lifecycle.
|
|
22
|
+
* This is useful for plugins like sitemaps, redirects etc... Only collects
|
|
23
|
+
* "actual" pages, i.e. those without subroutes, because if a route has
|
|
24
|
+
* subroutes, it is probably a wrapper.
|
|
25
|
+
*/
|
|
16
26
|
routesPaths: string[];
|
|
17
27
|
};
|
|
18
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Generates a unique chunk name that can be used in the chunk registry.
|
|
30
|
+
*
|
|
31
|
+
* @param modulePath A path to generate chunk name from. The actual value has no
|
|
32
|
+
* semantic significance.
|
|
33
|
+
* @param prefix A prefix to append to the chunk name, to avoid name clash.
|
|
34
|
+
* @param preferredName Chunk names default to `modulePath`, and this can supply
|
|
35
|
+
* a more human-readable name.
|
|
36
|
+
* @param shortId When `true`, the chunk name would only be a hash without any
|
|
37
|
+
* other characters. Useful for bundle size. Defaults to `true` in production.
|
|
38
|
+
*/
|
|
39
|
+
export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
|
|
40
|
+
export declare function handleDuplicateRoutes(pluginsRouteConfigs: RouteConfig[], onDuplicateRoutes: ReportingSeverity): void;
|
|
41
|
+
/**
|
|
42
|
+
* Routes are prepared into three temp files:
|
|
43
|
+
*
|
|
44
|
+
* - `routesConfig`, the route config passed to react-router. This file is kept
|
|
45
|
+
* minimal, because it can't be code-splitted.
|
|
46
|
+
* - `routesChunkNames`, a mapping from route paths (hashed) to code-splitted
|
|
47
|
+
* chunk names.
|
|
48
|
+
* - `registry`, a mapping from chunk names to options for react-loadable.
|
|
49
|
+
*/
|
|
50
|
+
export declare function loadRoutes(routeConfigs: RouteConfig[], baseUrl: string, onDuplicateRoutes: ReportingSeverity): LoadedRoutes;
|
|
19
51
|
export {};
|
package/lib/server/routes.js
CHANGED
|
@@ -6,115 +6,205 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadRoutes = exports.handleDuplicateRoutes = exports.genChunkName = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
9
11
|
const utils_1 = require("@docusaurus/utils");
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
|
-
const querystring_1 = require("querystring");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const querystring_1 = tslib_1.__importDefault(require("querystring"));
|
|
14
|
+
const utils_2 = require("./utils");
|
|
15
|
+
/** Indents every line of `str` by one level. */
|
|
16
|
+
function indent(str) {
|
|
17
|
+
return ` ${str.replace(/\n/g, `\n `)}`;
|
|
18
|
+
}
|
|
19
|
+
const chunkNameCache = new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Generates a unique chunk name that can be used in the chunk registry.
|
|
22
|
+
*
|
|
23
|
+
* @param modulePath A path to generate chunk name from. The actual value has no
|
|
24
|
+
* semantic significance.
|
|
25
|
+
* @param prefix A prefix to append to the chunk name, to avoid name clash.
|
|
26
|
+
* @param preferredName Chunk names default to `modulePath`, and this can supply
|
|
27
|
+
* a more human-readable name.
|
|
28
|
+
* @param shortId When `true`, the chunk name would only be a hash without any
|
|
29
|
+
* other characters. Useful for bundle size. Defaults to `true` in production.
|
|
30
|
+
*/
|
|
31
|
+
function genChunkName(modulePath, prefix, preferredName, shortId = process.env.NODE_ENV === 'production') {
|
|
32
|
+
let chunkName = chunkNameCache.get(modulePath);
|
|
33
|
+
if (!chunkName) {
|
|
34
|
+
if (shortId) {
|
|
35
|
+
chunkName = (0, utils_1.simpleHash)(modulePath, 8);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
let str = modulePath;
|
|
39
|
+
if (preferredName) {
|
|
40
|
+
const shortHash = (0, utils_1.simpleHash)(modulePath, 3);
|
|
41
|
+
str = `${preferredName}${shortHash}`;
|
|
42
|
+
}
|
|
43
|
+
const name = str === '/' ? 'index' : (0, utils_1.docuHash)(str);
|
|
44
|
+
chunkName = prefix ? `${prefix}---${name}` : name;
|
|
45
|
+
}
|
|
46
|
+
chunkNameCache.set(modulePath, chunkName);
|
|
47
|
+
}
|
|
48
|
+
return chunkName;
|
|
49
|
+
}
|
|
50
|
+
exports.genChunkName = genChunkName;
|
|
51
|
+
/**
|
|
52
|
+
* Takes a piece of route config, and serializes it into raw JS code. The shape
|
|
53
|
+
* is the same as react-router's `RouteConfig`. Formatting is similar to
|
|
54
|
+
* `JSON.stringify` but without all the quotes.
|
|
55
|
+
*/
|
|
56
|
+
function serializeRouteConfig({ routePath, routeHash, exact, subroutesCodeStrings, props, }) {
|
|
57
|
+
const parts = [
|
|
58
|
+
`path: '${routePath}'`,
|
|
59
|
+
`component: ComponentCreator('${routePath}', '${routeHash}')`,
|
|
60
|
+
];
|
|
61
|
+
if (exact) {
|
|
62
|
+
parts.push(`exact: true`);
|
|
36
63
|
}
|
|
37
|
-
if (
|
|
38
|
-
|
|
64
|
+
if (subroutesCodeStrings) {
|
|
65
|
+
parts.push(`routes: [
|
|
66
|
+
${indent(subroutesCodeStrings.join(',\n'))}
|
|
67
|
+
]`);
|
|
39
68
|
}
|
|
40
|
-
|
|
69
|
+
Object.entries(props).forEach(([propName, propValue]) => {
|
|
70
|
+
// Inspired by https://github.com/armanozak/should-quote/blob/main/packages/should-quote/src/lib/should-quote.ts
|
|
71
|
+
const shouldQuote = ((key) => {
|
|
72
|
+
// Pre-sanitation to prevent injection
|
|
73
|
+
if (/[.,;:}/\s]/.test(key)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
// If this key can be used in an expression like ({a:0}).a
|
|
78
|
+
// eslint-disable-next-line no-eval
|
|
79
|
+
eval(`({${key}:0}).${key}`);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
})(propName);
|
|
86
|
+
// Escape quotes as well
|
|
87
|
+
const key = shouldQuote ? JSON.stringify(propName) : propName;
|
|
88
|
+
parts.push(`${key}: ${JSON.stringify(propValue)}`);
|
|
89
|
+
});
|
|
90
|
+
return `{
|
|
91
|
+
${indent(parts.join(',\n'))}
|
|
92
|
+
}`;
|
|
41
93
|
}
|
|
94
|
+
const isModule = (value) => typeof value === 'string' ||
|
|
95
|
+
(typeof value === 'object' &&
|
|
96
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
97
|
+
!!value?.__import);
|
|
98
|
+
/**
|
|
99
|
+
* Takes a {@link Module} (which is nothing more than a path plus some metadata
|
|
100
|
+
* like query) and returns the string path it represents.
|
|
101
|
+
*/
|
|
42
102
|
function getModulePath(target) {
|
|
43
103
|
if (typeof target === 'string') {
|
|
44
104
|
return target;
|
|
45
105
|
}
|
|
46
|
-
const queryStr = target.query ? `?${querystring_1.stringify(target.query)}` : '';
|
|
106
|
+
const queryStr = target.query ? `?${querystring_1.default.stringify(target.query)}` : '';
|
|
47
107
|
return `${target.path}${queryStr}`;
|
|
48
108
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!lodash_1.isString(routePath) || !component) {
|
|
57
|
-
throw new Error(`Invalid routeConfig (Path must be a string and component is required) \n${JSON.stringify(routeConfig)}`);
|
|
58
|
-
}
|
|
59
|
-
// Collect all page paths for injecting it later in the plugin lifecycle
|
|
60
|
-
// This is useful for plugins like sitemaps, redirects etc...
|
|
61
|
-
// If a route has subroutes, it is not necessarily a valid page path (more likely to be a wrapper)
|
|
62
|
-
if (!subroutes) {
|
|
63
|
-
routesPaths.push(routePath);
|
|
64
|
-
}
|
|
65
|
-
// We hash the route to generate the key, because 2 routes can conflict with
|
|
66
|
-
// each others if they have the same path, ex: parent=/docs, child=/docs
|
|
67
|
-
// see https://github.com/facebook/docusaurus/issues/2917
|
|
68
|
-
const routeHash = utils_1.simpleHash(JSON.stringify(routeConfig), 3);
|
|
69
|
-
const chunkNamesKey = `${routePath}-${routeHash}`;
|
|
70
|
-
routesChunkNames[chunkNamesKey] = {
|
|
71
|
-
...genRouteChunkNames(registry, { component }, 'component', component),
|
|
72
|
-
...genRouteChunkNames(registry, modules, 'module', routePath),
|
|
73
|
-
};
|
|
74
|
-
return createRouteCodeString({
|
|
75
|
-
routePath: routeConfig.path.replace(/'/g, "\\'"),
|
|
76
|
-
routeHash,
|
|
77
|
-
exact,
|
|
78
|
-
subroutesCodeStrings: subroutes === null || subroutes === void 0 ? void 0 : subroutes.map(generateRouteCode),
|
|
79
|
-
});
|
|
109
|
+
function genChunkNames(routeModule, prefix, name, res) {
|
|
110
|
+
if (isModule(routeModule)) {
|
|
111
|
+
// This is a leaf node, no need to recurse
|
|
112
|
+
const modulePath = getModulePath(routeModule);
|
|
113
|
+
const chunkName = genChunkName(modulePath, prefix, name);
|
|
114
|
+
res.registry[chunkName] = (0, utils_1.escapePath)(modulePath);
|
|
115
|
+
return chunkName;
|
|
80
116
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
${NotFoundRouteCode}
|
|
86
|
-
];\n`;
|
|
87
|
-
return {
|
|
88
|
-
registry,
|
|
89
|
-
routesConfig,
|
|
90
|
-
routesChunkNames,
|
|
91
|
-
routesPaths,
|
|
92
|
-
};
|
|
117
|
+
if (Array.isArray(routeModule)) {
|
|
118
|
+
return routeModule.map((val, index) => genChunkNames(val, `${index}`, name, res));
|
|
119
|
+
}
|
|
120
|
+
return lodash_1.default.mapValues(routeModule, (v, key) => genChunkNames(v, key, name, res));
|
|
93
121
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
registry, value, prefix, name) {
|
|
98
|
-
if (!value) {
|
|
99
|
-
return null;
|
|
122
|
+
function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
|
|
123
|
+
if (onDuplicateRoutes === 'ignore') {
|
|
124
|
+
return;
|
|
100
125
|
}
|
|
101
|
-
|
|
102
|
-
|
|
126
|
+
const allRoutes = (0, utils_2.getAllFinalRoutes)(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
|
|
127
|
+
const seenRoutes = new Set();
|
|
128
|
+
const duplicatePaths = allRoutes.filter((route) => {
|
|
129
|
+
if (seenRoutes.has(route)) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
seenRoutes.add(route);
|
|
133
|
+
return false;
|
|
134
|
+
});
|
|
135
|
+
if (duplicatePaths.length > 0) {
|
|
136
|
+
const finalMessage = `Duplicate routes found!
|
|
137
|
+
${duplicatePaths
|
|
138
|
+
.map((duplicateRoute) => `- Attempting to create page at ${duplicateRoute}, but a page already exists at this route.`)
|
|
139
|
+
.join('\n')}
|
|
140
|
+
This could lead to non-deterministic routing behavior.`;
|
|
141
|
+
(0, utils_1.reportMessage)(finalMessage, onDuplicateRoutes);
|
|
103
142
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
143
|
+
}
|
|
144
|
+
exports.handleDuplicateRoutes = handleDuplicateRoutes;
|
|
145
|
+
/**
|
|
146
|
+
* This is the higher level overview of route code generation. For each route
|
|
147
|
+
* config node, it returns the node's serialized form, and mutates `registry`,
|
|
148
|
+
* `routesPaths`, and `routesChunkNames` accordingly.
|
|
149
|
+
*/
|
|
150
|
+
function genRouteCode(routeConfig, res) {
|
|
151
|
+
const { path: routePath, component, modules = {}, context, routes: subroutes, priority, exact, ...props } = routeConfig;
|
|
152
|
+
if (typeof routePath !== 'string' || !component) {
|
|
153
|
+
throw new Error(`Invalid route config: path must be a string and component is required.
|
|
154
|
+
${JSON.stringify(routeConfig)}`);
|
|
114
155
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
156
|
+
if (!subroutes) {
|
|
157
|
+
res.routesPaths.push(routePath);
|
|
158
|
+
}
|
|
159
|
+
const routeHash = (0, utils_1.simpleHash)(JSON.stringify(routeConfig), 3);
|
|
160
|
+
res.routesChunkNames[`${routePath}-${routeHash}`] = {
|
|
161
|
+
// Avoid clash with a prop called "component"
|
|
162
|
+
...genChunkNames({ __comp: component }, 'component', component, res),
|
|
163
|
+
...(context &&
|
|
164
|
+
genChunkNames({ __context: context }, 'context', routePath, res)),
|
|
165
|
+
...genChunkNames(modules, 'module', routePath, res),
|
|
166
|
+
};
|
|
167
|
+
return serializeRouteConfig({
|
|
168
|
+
routePath: routePath.replace(/'/g, "\\'"),
|
|
169
|
+
routeHash,
|
|
170
|
+
subroutesCodeStrings: subroutes?.map((r) => genRouteCode(r, res)),
|
|
171
|
+
exact,
|
|
172
|
+
props,
|
|
118
173
|
});
|
|
119
|
-
return newValue;
|
|
120
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Routes are prepared into three temp files:
|
|
177
|
+
*
|
|
178
|
+
* - `routesConfig`, the route config passed to react-router. This file is kept
|
|
179
|
+
* minimal, because it can't be code-splitted.
|
|
180
|
+
* - `routesChunkNames`, a mapping from route paths (hashed) to code-splitted
|
|
181
|
+
* chunk names.
|
|
182
|
+
* - `registry`, a mapping from chunk names to options for react-loadable.
|
|
183
|
+
*/
|
|
184
|
+
function loadRoutes(routeConfigs, baseUrl, onDuplicateRoutes) {
|
|
185
|
+
handleDuplicateRoutes(routeConfigs, onDuplicateRoutes);
|
|
186
|
+
const res = {
|
|
187
|
+
// To be written by `genRouteCode`
|
|
188
|
+
routesConfig: '',
|
|
189
|
+
routesChunkNames: {},
|
|
190
|
+
registry: {},
|
|
191
|
+
routesPaths: [(0, utils_1.normalizeUrl)([baseUrl, '404.html'])],
|
|
192
|
+
};
|
|
193
|
+
// `genRouteCode` would mutate `res`
|
|
194
|
+
const routeConfigSerialized = routeConfigs
|
|
195
|
+
.map((r) => genRouteCode(r, res))
|
|
196
|
+
.join(',\n');
|
|
197
|
+
res.routesConfig = `import React from 'react';
|
|
198
|
+
import ComponentCreator from '@docusaurus/ComponentCreator';
|
|
199
|
+
|
|
200
|
+
export default [
|
|
201
|
+
${indent(routeConfigSerialized)},
|
|
202
|
+
{
|
|
203
|
+
path: '*',
|
|
204
|
+
component: ComponentCreator('*'),
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
`;
|
|
208
|
+
return res;
|
|
209
|
+
}
|
|
210
|
+
exports.loadRoutes = loadRoutes;
|