@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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 +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +29 -38
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +19 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +5 -9
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +13 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- 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 +1 -1
- package/lib/client/exports/Interpolate.js +16 -22
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +24 -19
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +14 -10
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +22 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/docusaurusContext.d.ts +12 -0
- package/lib/client/exports/docusaurusContext.js +25 -0
- 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 +3 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.js +1 -5
- 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/flat.d.ts +2 -2
- package/lib/client/flat.js +8 -11
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -3
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +39 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -7
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +6 -6
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +102 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +3 -3
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +13 -19
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +93 -83
- 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 +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -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 +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +103 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +41 -43
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +35 -14
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +1 -1
- package/lib/server/brokenLinks.js +57 -38
- package/lib/server/client-modules/index.d.ts +1 -1
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +7 -4
- package/lib/server/configValidation.d.ts +2 -2
- package/lib/server/configValidation.js +43 -28
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +2 -4
- package/lib/server/html-tags/index.d.ts +1 -1
- package/lib/server/html-tags/index.js +1 -1
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +32 -46
- package/lib/server/index.d.ts +2 -2
- package/lib/server/index.js +147 -68
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +2 -2
- package/lib/server/plugins/index.js +34 -35
- package/lib/server/plugins/init.d.ts +12 -2
- package/lib/server/plugins/init.js +48 -58
- package/lib/server/plugins/pluginIds.d.ts +1 -1
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +12 -13
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +50 -29
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +22 -14
- package/lib/server/themes/index.d.ts +3 -3
- package/lib/server/themes/index.js +26 -26
- package/lib/server/translations/translations.d.ts +7 -1
- package/lib/server/translations/translations.js +30 -45
- package/lib/server/translations/translationsExtractor.d.ts +9 -3
- package/lib/server/translations/translationsExtractor.js +159 -120
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +4 -4
- package/lib/webpack/base.js +38 -33
- 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 +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +9 -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 +3 -2
- package/lib/webpack/utils.d.ts +7 -29
- package/lib/webpack/utils.js +54 -171
- package/package.json +74 -69
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- 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/loadSetup.js +0 -25
- package/lib/server/versions/__tests/index.test.js +0 -25
- 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.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -9,12 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.handleBrokenLinks = exports.filterExistingFileLinks = exports.getBrokenLinksErrorMessage = exports.getAllBrokenLinks = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const react_router_config_1 = require("react-router-config");
|
|
12
|
-
const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
13
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
14
|
const utils_1 = require("@docusaurus/utils");
|
|
16
15
|
const utils_2 = require("./utils");
|
|
17
16
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
17
|
+
const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
|
|
18
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
18
19
|
function toReactRouterRoutes(routes) {
|
|
19
20
|
// @ts-expect-error: types incompatible???
|
|
20
21
|
return routes;
|
|
@@ -29,32 +30,32 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
|
|
|
29
30
|
// we must resolve the links before using matchRoutes
|
|
30
31
|
// resolvePathname is used internally by ReactRouter
|
|
31
32
|
function resolveLink(link) {
|
|
32
|
-
const resolvedLink =
|
|
33
|
+
const resolvedLink = (0, utils_1.resolvePathname)(onlyPathname(link), pagePath);
|
|
33
34
|
return { link, resolvedLink };
|
|
34
35
|
}
|
|
35
36
|
function isBrokenLink(link) {
|
|
36
37
|
const matchedRoutes = [link, decodeURI(link)]
|
|
37
|
-
.map((l) => react_router_config_1.matchRoutes(toReactRouterRoutes(routes), l))
|
|
38
|
+
.map((l) => (0, react_router_config_1.matchRoutes)(toReactRouterRoutes(routes), l))
|
|
38
39
|
.reduce((prev, cur) => prev.concat(cur));
|
|
39
40
|
return matchedRoutes.length === 0;
|
|
40
41
|
}
|
|
41
42
|
return pageLinks.map(resolveLink).filter((l) => isBrokenLink(l.resolvedLink));
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The route defs can be recursive, and have a parent match-all route. We don't
|
|
46
|
+
* want to match broken links like /docs/brokenLink against /docs/*. For this
|
|
47
|
+
* reason, we only consider the "final routes", that do not have subroutes.
|
|
48
|
+
* We also need to remove the match all 404 route
|
|
49
|
+
*/
|
|
47
50
|
function filterIntermediateRoutes(routesInput) {
|
|
48
51
|
const routesWithout404 = routesInput.filter((route) => route.path !== '*');
|
|
49
|
-
return utils_2.getAllFinalRoutes(routesWithout404);
|
|
52
|
+
return (0, utils_2.getAllFinalRoutes)(routesWithout404);
|
|
50
53
|
}
|
|
51
54
|
function getAllBrokenLinks({ allCollectedLinks, routes, }) {
|
|
52
55
|
const filteredRoutes = filterIntermediateRoutes(routes);
|
|
53
|
-
const allBrokenLinks = lodash_1.mapValues(allCollectedLinks, (pageLinks, pagePath) => {
|
|
54
|
-
return getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes });
|
|
55
|
-
});
|
|
56
|
+
const allBrokenLinks = lodash_1.default.mapValues(allCollectedLinks, (pageLinks, pagePath) => getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes }));
|
|
56
57
|
// remove pages without any broken link
|
|
57
|
-
return lodash_1.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
58
|
+
return lodash_1.default.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
58
59
|
}
|
|
59
60
|
exports.getAllBrokenLinks = getAllBrokenLinks;
|
|
60
61
|
function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
@@ -66,16 +67,20 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
66
67
|
return `${brokenLink.link}${showResolvedLink ? ` (resolved as: ${brokenLink.resolvedLink})` : ''}`;
|
|
67
68
|
}
|
|
68
69
|
function pageBrokenLinksMessage(pagePath, brokenLinks) {
|
|
69
|
-
return
|
|
70
|
+
return `
|
|
71
|
+
- On source page path = ${pagePath}:
|
|
72
|
+
-> linking to ${brokenLinks
|
|
70
73
|
.map(brokenLinkMessage)
|
|
71
74
|
.join('\n -> linking to ')}`;
|
|
72
75
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
/**
|
|
77
|
+
* If there's a broken link appearing very often, it is probably a broken link
|
|
78
|
+
* on the layout. Add an additional message in such case to help user figure
|
|
79
|
+
* this out. See https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
|
|
80
|
+
*/
|
|
76
81
|
function getLayoutBrokenLinksHelpMessage() {
|
|
77
|
-
const flatList =
|
|
78
|
-
const countedBrokenLinks = lodash_1.countBy(flatList, (item) => item.brokenLink.link);
|
|
82
|
+
const flatList = Object.entries(allBrokenLinks).flatMap(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink })));
|
|
83
|
+
const countedBrokenLinks = lodash_1.default.countBy(flatList, (item) => item.brokenLink.link);
|
|
79
84
|
const FrequencyThreshold = 5; // Is this a good value?
|
|
80
85
|
const frequentLinks = Object.entries(countedBrokenLinks)
|
|
81
86
|
.filter(([, count]) => count >= FrequencyThreshold)
|
|
@@ -83,30 +88,40 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
83
88
|
if (frequentLinks.length === 0) {
|
|
84
89
|
return '';
|
|
85
90
|
}
|
|
86
|
-
return
|
|
91
|
+
return logger_1.default.interpolate `
|
|
92
|
+
|
|
93
|
+
It looks like some of the broken links we found appear in many pages of your site.
|
|
94
|
+
Maybe those broken links appear on all pages through your site layout?
|
|
95
|
+
We recommend that you check your theme configuration for such links (particularly, theme navbar and footer).
|
|
96
|
+
Frequent broken links are linking to:${frequentLinks}
|
|
97
|
+
`;
|
|
87
98
|
}
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
return `Docusaurus found broken links!
|
|
100
|
+
|
|
101
|
+
Please check the pages of your site in the list below, and make sure you don't reference any path that does not exist.
|
|
102
|
+
Note: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.${getLayoutBrokenLinksHelpMessage()}
|
|
103
|
+
|
|
104
|
+
Exhaustive list of all broken links found:
|
|
105
|
+
${Object.entries(allBrokenLinks)
|
|
106
|
+
.map(([pagePath, brokenLinks]) => pageBrokenLinksMessage(pagePath, brokenLinks))
|
|
107
|
+
.join('\n')}
|
|
108
|
+
`;
|
|
93
109
|
}
|
|
94
110
|
exports.getBrokenLinksErrorMessage = getBrokenLinksErrorMessage;
|
|
95
|
-
function isExistingFile(filePath) {
|
|
111
|
+
async function isExistingFile(filePath) {
|
|
96
112
|
try {
|
|
97
|
-
return fs_extra_1.default.
|
|
113
|
+
return (await fs_extra_1.default.stat(filePath)).isFile();
|
|
98
114
|
}
|
|
99
|
-
catch
|
|
115
|
+
catch {
|
|
100
116
|
return false;
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
// If a file actually exist on the file system, we know the link is valid
|
|
104
120
|
// even if docusaurus does not know about this file, so we don't report it
|
|
105
121
|
async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, }) {
|
|
106
|
-
|
|
107
|
-
function linkFileExists(link) {
|
|
122
|
+
async function linkFileExists(link) {
|
|
108
123
|
// /baseUrl/javadoc/ -> /outDir/javadoc
|
|
109
|
-
const baseFilePath = utils_1.removeSuffix(`${outDir}/${utils_1.removePrefix(link, baseUrl)}`, '/');
|
|
124
|
+
const baseFilePath = onlyPathname((0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/'));
|
|
110
125
|
// -> /outDir/javadoc
|
|
111
126
|
// -> /outDir/javadoc.html
|
|
112
127
|
// -> /outDir/javadoc/index.html
|
|
@@ -115,19 +130,23 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
|
|
|
115
130
|
filePathsToTry.push(`${baseFilePath}.html`);
|
|
116
131
|
filePathsToTry.push(path_1.default.join(baseFilePath, 'index.html'));
|
|
117
132
|
}
|
|
118
|
-
|
|
133
|
+
for (const file of filePathsToTry) {
|
|
134
|
+
if (await isExistingFile(file)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
119
139
|
}
|
|
120
|
-
return lodash_1.mapValues(allCollectedLinks, (links) =>
|
|
121
|
-
return links.filter((link) => !linkFileExists(link));
|
|
122
|
-
});
|
|
140
|
+
return (0, combine_promises_1.default)(lodash_1.default.mapValues(allCollectedLinks, async (links) => (await Promise.all(links.map(async (link) => ((await linkFileExists(link)) ? '' : link)))).filter(Boolean)));
|
|
123
141
|
}
|
|
124
142
|
exports.filterExistingFileLinks = filterExistingFileLinks;
|
|
125
143
|
async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, baseUrl, outDir, }) {
|
|
126
144
|
if (onBrokenLinks === 'ignore') {
|
|
127
145
|
return;
|
|
128
146
|
}
|
|
129
|
-
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
130
|
-
//
|
|
147
|
+
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
148
|
+
// file system. It is not a broken link, it may simply be a link to an
|
|
149
|
+
// existing static file...
|
|
131
150
|
const allCollectedLinksFiltered = await filterExistingFileLinks({
|
|
132
151
|
allCollectedLinks,
|
|
133
152
|
baseUrl,
|
|
@@ -139,7 +158,7 @@ async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, bas
|
|
|
139
158
|
});
|
|
140
159
|
const errorMessage = getBrokenLinksErrorMessage(allBrokenLinks);
|
|
141
160
|
if (errorMessage) {
|
|
142
|
-
utils_1.reportMessage(errorMessage, onBrokenLinks);
|
|
161
|
+
(0, utils_1.reportMessage)(errorMessage, onBrokenLinks);
|
|
143
162
|
}
|
|
144
163
|
}
|
|
145
164
|
exports.handleBrokenLinks = handleBrokenLinks;
|
|
@@ -4,5 +4,5 @@
|
|
|
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 { Plugin } from '@docusaurus/types';
|
|
7
|
+
import type { Plugin } from '@docusaurus/types';
|
|
8
8
|
export default function loadClientModules(plugins: Plugin<unknown>[]): string[];
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
function loadClientModules(plugins) {
|
|
10
|
-
return []
|
|
11
|
-
.map((plugin) => { var _a, _b; return (_b = (_a = plugin.getClientModules) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; })
|
|
12
|
-
.filter(Boolean));
|
|
10
|
+
return plugins.flatMap((plugin) => plugin.getClientModules?.() ?? []);
|
|
13
11
|
}
|
|
14
12
|
exports.default = loadClientModules;
|
package/lib/server/config.d.ts
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
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 { DocusaurusConfig } from '@docusaurus/types';
|
|
8
|
-
export default function loadConfig(configPath: string): DocusaurusConfig
|
|
7
|
+
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
8
|
+
export default function loadConfig(configPath: string): Promise<DocusaurusConfig>;
|
package/lib/server/config.js
CHANGED
|
@@ -10,11 +10,14 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
11
|
const import_fresh_1 = tslib_1.__importDefault(require("import-fresh"));
|
|
12
12
|
const configValidation_1 = require("./configValidation");
|
|
13
|
-
function loadConfig(configPath) {
|
|
14
|
-
if (!fs_extra_1.default.
|
|
13
|
+
async function loadConfig(configPath) {
|
|
14
|
+
if (!(await fs_extra_1.default.pathExists(configPath))) {
|
|
15
15
|
throw new Error(`Config file at "${configPath}" not found.`);
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
17
|
+
const importedConfig = (0, import_fresh_1.default)(configPath);
|
|
18
|
+
const loadedConfig = importedConfig instanceof Function
|
|
19
|
+
? await importedConfig()
|
|
20
|
+
: await importedConfig;
|
|
21
|
+
return (0, configValidation_1.validateConfig)(loadedConfig);
|
|
19
22
|
}
|
|
20
23
|
exports.default = loadConfig;
|
|
@@ -4,9 +4,9 @@
|
|
|
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 { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
|
|
7
|
+
import type { DocusaurusConfig, I18nConfig } from '@docusaurus/types';
|
|
8
8
|
import { Joi } from '@docusaurus/utils-validation';
|
|
9
9
|
export declare const DEFAULT_I18N_CONFIG: I18nConfig;
|
|
10
|
-
export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'baseUrlIssueBanner'>;
|
|
10
|
+
export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'onBrokenLinks' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories'>;
|
|
11
11
|
export declare const ConfigSchema: Joi.ObjectSchema<any>;
|
|
12
12
|
export declare function validateConfig(config: Partial<DocusaurusConfig>): DocusaurusConfig;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateConfig = exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
|
|
10
|
-
const
|
|
10
|
+
const utils_1 = require("@docusaurus/utils");
|
|
11
11
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
12
|
const DEFAULT_I18N_LOCALE = 'en';
|
|
13
13
|
exports.DEFAULT_I18N_CONFIG = {
|
|
@@ -27,19 +27,30 @@ exports.DEFAULT_CONFIG = {
|
|
|
27
27
|
themeConfig: {},
|
|
28
28
|
titleDelimiter: '|',
|
|
29
29
|
noIndex: false,
|
|
30
|
+
tagline: '',
|
|
30
31
|
baseUrlIssueBanner: true,
|
|
32
|
+
staticDirectories: [utils_1.STATIC_DIR_NAME],
|
|
31
33
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
function createPluginSchema(theme = false) {
|
|
35
|
+
return (utils_validation_1.Joi.alternatives()
|
|
36
|
+
.try(utils_validation_1.Joi.function(), utils_validation_1.Joi.array().ordered(utils_validation_1.Joi.function().required(), utils_validation_1.Joi.object().required()), utils_validation_1.Joi.string(), utils_validation_1.Joi.array()
|
|
37
|
+
.ordered(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required())
|
|
38
|
+
.length(2), utils_validation_1.Joi.bool().equal(false))
|
|
39
|
+
// @ts-expect-error: bad lib def, doesn't recognize an array of reports
|
|
40
|
+
.error((errors) => {
|
|
41
|
+
errors.forEach((error) => {
|
|
42
|
+
const validConfigExample = theme
|
|
43
|
+
? `Example valid theme config:
|
|
44
|
+
{
|
|
45
|
+
themes: [
|
|
46
|
+
["@docusaurus/theme-classic",options],
|
|
47
|
+
"./myTheme",
|
|
48
|
+
["./myTheme",{someOption: 42}],
|
|
49
|
+
function myTheme() { },
|
|
50
|
+
[function myTheme() { },options]
|
|
51
|
+
],
|
|
52
|
+
};`
|
|
53
|
+
: `Example valid plugin config:
|
|
43
54
|
{
|
|
44
55
|
plugins: [
|
|
45
56
|
["@docusaurus/plugin-content-docs",options],
|
|
@@ -48,15 +59,20 @@ Example valid plugin config:
|
|
|
48
59
|
function myPlugin() { },
|
|
49
60
|
[function myPlugin() { },options]
|
|
50
61
|
],
|
|
51
|
-
}
|
|
62
|
+
};`;
|
|
63
|
+
error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value as path [${error.path}].
|
|
64
|
+
${validConfigExample}
|
|
52
65
|
`;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
|
|
66
|
+
});
|
|
67
|
+
return errors;
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
const PluginSchema = createPluginSchema(false);
|
|
71
|
+
const ThemeSchema = createPluginSchema(true);
|
|
57
72
|
const PresetSchema = utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.string(), utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required(), utils_validation_1.Joi.object().required()).length(2));
|
|
58
73
|
const LocaleConfigSchema = utils_validation_1.Joi.object({
|
|
59
74
|
label: utils_validation_1.Joi.string(),
|
|
75
|
+
htmlLang: utils_validation_1.Joi.string(),
|
|
60
76
|
direction: utils_validation_1.Joi.string().equal('ltr', 'rtl').default('ltr'),
|
|
61
77
|
});
|
|
62
78
|
const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
@@ -68,7 +84,7 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
|
68
84
|
})
|
|
69
85
|
.optional()
|
|
70
86
|
.default(exports.DEFAULT_I18N_CONFIG);
|
|
71
|
-
const SiteUrlSchema = utils_validation_1.URISchema.required().custom(
|
|
87
|
+
const SiteUrlSchema = utils_validation_1.URISchema.required().custom((value, helpers) => {
|
|
72
88
|
try {
|
|
73
89
|
const { pathname } = new URL(value);
|
|
74
90
|
if (pathname !== '/') {
|
|
@@ -77,14 +93,14 @@ const SiteUrlSchema = utils_validation_1.URISchema.required().custom(function (v
|
|
|
77
93
|
});
|
|
78
94
|
}
|
|
79
95
|
}
|
|
80
|
-
catch
|
|
96
|
+
catch { }
|
|
81
97
|
return value;
|
|
82
98
|
}, 'siteUrlCustomValidation');
|
|
83
99
|
// TODO move to @docusaurus/utils-validation
|
|
84
100
|
exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
85
101
|
baseUrl: utils_validation_1.Joi.string()
|
|
86
102
|
.required()
|
|
87
|
-
.regex(
|
|
103
|
+
.regex(/\/$/m)
|
|
88
104
|
.message('{{#label}} must be a string with a trailing slash.'),
|
|
89
105
|
baseUrlIssueBanner: utils_validation_1.Joi.boolean().default(exports.DEFAULT_CONFIG.baseUrlIssueBanner),
|
|
90
106
|
favicon: utils_validation_1.Joi.string().optional(),
|
|
@@ -102,7 +118,11 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
102
118
|
.equal('ignore', 'log', 'warn', 'error', 'throw')
|
|
103
119
|
.default(exports.DEFAULT_CONFIG.onDuplicateRoutes),
|
|
104
120
|
organizationName: utils_validation_1.Joi.string().allow(''),
|
|
121
|
+
staticDirectories: utils_validation_1.Joi.array()
|
|
122
|
+
.items(utils_validation_1.Joi.string())
|
|
123
|
+
.default(exports.DEFAULT_CONFIG.staticDirectories),
|
|
105
124
|
projectName: utils_validation_1.Joi.string().allow(''),
|
|
125
|
+
deploymentBranch: utils_validation_1.Joi.string().optional(),
|
|
106
126
|
customFields: utils_validation_1.Joi.object().unknown().default(exports.DEFAULT_CONFIG.customFields),
|
|
107
127
|
githubHost: utils_validation_1.Joi.string(),
|
|
108
128
|
plugins: utils_validation_1.Joi.array().items(PluginSchema).default(exports.DEFAULT_CONFIG.plugins),
|
|
@@ -122,7 +142,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
122
142
|
type: utils_validation_1.Joi.string(),
|
|
123
143
|
}).unknown()),
|
|
124
144
|
clientModules: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
|
|
125
|
-
tagline: utils_validation_1.Joi.string().allow(''),
|
|
145
|
+
tagline: utils_validation_1.Joi.string().allow('').default(exports.DEFAULT_CONFIG.tagline),
|
|
126
146
|
titleDelimiter: utils_validation_1.Joi.string().default('|'),
|
|
127
147
|
noIndex: utils_validation_1.Joi.bool().default(false),
|
|
128
148
|
webpack: utils_validation_1.Joi.object({
|
|
@@ -138,13 +158,8 @@ function validateConfig(config) {
|
|
|
138
158
|
const { error, warning, value } = exports.ConfigSchema.validate(config, {
|
|
139
159
|
abortEarly: false,
|
|
140
160
|
});
|
|
141
|
-
utils_validation_1.printWarning(warning);
|
|
161
|
+
(0, utils_validation_1.printWarning)(warning);
|
|
142
162
|
if (error) {
|
|
143
|
-
utils_validation_1.logValidationBugReportHint();
|
|
144
|
-
if (utils_validation_1.isValidationDisabledEscapeHatch) {
|
|
145
|
-
console.error(error);
|
|
146
|
-
return config;
|
|
147
|
-
}
|
|
148
163
|
const unknownFields = error.details.reduce((formattedError, err) => {
|
|
149
164
|
if (err.type === 'object.unknown') {
|
|
150
165
|
return `${formattedError}"${err.path}",`;
|
|
@@ -155,7 +170,7 @@ function validateConfig(config) {
|
|
|
155
170
|
? `${accumulatedErr}${err.message}\n`
|
|
156
171
|
: accumulatedErr, '');
|
|
157
172
|
formattedError = unknownFields
|
|
158
|
-
? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${
|
|
173
|
+
? `${formattedError}These field(s) (${unknownFields}) are not recognized in ${utils_1.DEFAULT_CONFIG_FILE_NAME}.\nIf you still want these fields to be in your configuration, put them in the "customFields" field.\nSee https://docusaurus.io/docs/docusaurus.config.js/#customfields`
|
|
159
174
|
: formattedError;
|
|
160
175
|
throw new Error(formattedError);
|
|
161
176
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
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 { ReportingSeverity, RouteConfig } from '@docusaurus/types';
|
|
7
|
+
import type { ReportingSeverity, RouteConfig } from '@docusaurus/types';
|
|
8
8
|
export declare function getAllDuplicateRoutes(pluginsRouteConfigs: RouteConfig[]): string[];
|
|
9
9
|
export declare function getDuplicateRoutesMessage(allDuplicateRoutes: string[]): string;
|
|
10
10
|
export declare function handleDuplicateRoutes(pluginsRouteConfigs: RouteConfig[], onDuplicateRoutes: ReportingSeverity): void;
|
|
@@ -1,19 +1,23 @@
|
|
|
1
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
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.handleDuplicateRoutes = exports.getDuplicateRoutesMessage = exports.getAllDuplicateRoutes = void 0;
|
|
4
10
|
const utils_1 = require("@docusaurus/utils");
|
|
5
11
|
const utils_2 = require("./utils");
|
|
6
12
|
function getAllDuplicateRoutes(pluginsRouteConfigs) {
|
|
7
|
-
const allRoutes = utils_2.getAllFinalRoutes(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
|
|
13
|
+
const allRoutes = (0, utils_2.getAllFinalRoutes)(pluginsRouteConfigs).map((routeConfig) => routeConfig.path);
|
|
8
14
|
const seenRoutes = {};
|
|
9
15
|
return allRoutes.filter((route) => {
|
|
10
16
|
if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
|
|
11
17
|
return true;
|
|
12
18
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
19
|
+
seenRoutes[route] = true;
|
|
20
|
+
return false;
|
|
17
21
|
});
|
|
18
22
|
}
|
|
19
23
|
exports.getAllDuplicateRoutes = getAllDuplicateRoutes;
|
|
@@ -32,7 +36,7 @@ function handleDuplicateRoutes(pluginsRouteConfigs, onDuplicateRoutes) {
|
|
|
32
36
|
const message = getDuplicateRoutesMessage(duplicatePaths);
|
|
33
37
|
if (message) {
|
|
34
38
|
const finalMessage = `Duplicate routes found!\n${message}\nThis could lead to non-deterministic routing behavior`;
|
|
35
|
-
utils_1.reportMessage(finalMessage, onDuplicateRoutes);
|
|
39
|
+
(0, utils_1.reportMessage)(finalMessage, onDuplicateRoutes);
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
exports.handleDuplicateRoutes = handleDuplicateRoutes;
|
|
@@ -7,15 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
10
|
const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
|
|
12
11
|
const void_1 = tslib_1.__importDefault(require("html-tags/void"));
|
|
13
12
|
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
14
13
|
function assertIsHtmlTagObject(val) {
|
|
15
|
-
if (!
|
|
14
|
+
if (typeof val !== 'object' || !val) {
|
|
16
15
|
throw new Error(`"${val}" is not a valid HTML tag object.`);
|
|
17
16
|
}
|
|
18
|
-
// @ts-expect-error: If tagName doesn't exist, it will throw.
|
|
19
17
|
if (typeof val.tagName !== 'string') {
|
|
20
18
|
throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string.`);
|
|
21
19
|
}
|
|
@@ -33,7 +31,7 @@ function htmlTagObjectToString(tagDefinition) {
|
|
|
33
31
|
if (tagAttributes[attributeName] === true) {
|
|
34
32
|
return attributeName;
|
|
35
33
|
}
|
|
36
|
-
return `${attributeName}="${escape_html_1.default(tagAttributes[attributeName])}"`;
|
|
34
|
+
return `${attributeName}="${(0, escape_html_1.default)(tagAttributes[attributeName])}"`;
|
|
37
35
|
});
|
|
38
36
|
return `<${[tagDefinition.tagName].concat(attributes).join(' ')}>${(!isVoidTag && tagDefinition.innerHTML) || ''}${isVoidTag ? '' : `</${tagDefinition.tagName}>`}`;
|
|
39
37
|
}
|
|
@@ -4,6 +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 { InjectedHtmlTags, HtmlTags, LoadedPlugin } from '@docusaurus/types';
|
|
7
|
+
import type { InjectedHtmlTags, HtmlTags, LoadedPlugin } from '@docusaurus/types';
|
|
8
8
|
export declare function createHtmlTagsString(tags: HtmlTags): string;
|
|
9
9
|
export declare function loadHtmlTags(plugins: LoadedPlugin[]): InjectedHtmlTags;
|
|
@@ -10,7 +10,7 @@ exports.loadHtmlTags = exports.createHtmlTagsString = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const htmlTags_1 = tslib_1.__importDefault(require("./htmlTags"));
|
|
12
12
|
function toString(val) {
|
|
13
|
-
return typeof val === 'string' ? val : htmlTags_1.default(val);
|
|
13
|
+
return typeof val === 'string' ? val : (0, htmlTags_1.default)(val);
|
|
14
14
|
}
|
|
15
15
|
function createHtmlTagsString(tags) {
|
|
16
16
|
return Array.isArray(tags) ? tags.map(toString).join('\n') : toString(tags);
|
package/lib/server/i18n.d.ts
CHANGED
|
@@ -4,9 +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
|
-
import { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
7
|
+
import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
8
8
|
export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
|
|
9
|
-
export declare function shouldWarnAboutNodeVersion(version: number, locales: string[]): boolean;
|
|
10
9
|
export declare function loadI18n(config: DocusaurusConfig, options?: {
|
|
11
10
|
locale?: string;
|
|
12
11
|
}): Promise<I18n>;
|
package/lib/server/i18n.js
CHANGED
|
@@ -1,58 +1,49 @@
|
|
|
1
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
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.localizePath = exports.loadI18n = exports.
|
|
9
|
+
exports.localizePath = exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
|
|
4
10
|
const tslib_1 = require("tslib");
|
|
5
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
12
|
const utils_1 = require("@docusaurus/utils");
|
|
7
13
|
const rtl_detect_1 = require("rtl-detect");
|
|
8
|
-
const
|
|
9
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
10
15
|
function getDefaultLocaleLabel(locale) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (typeof Intl.DisplayNames !== 'undefined') {
|
|
15
|
-
// @ts-expect-error: wait for TS support of ES2021 feature
|
|
16
|
-
return new Intl.DisplayNames([locale], { type: 'language' }).of(locale);
|
|
16
|
+
const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
|
|
17
|
+
if (!languageName) {
|
|
18
|
+
return locale;
|
|
17
19
|
}
|
|
18
|
-
return locale;
|
|
20
|
+
return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
|
|
19
21
|
}
|
|
20
22
|
function getDefaultLocaleConfig(locale) {
|
|
21
23
|
return {
|
|
22
24
|
label: getDefaultLocaleLabel(locale),
|
|
23
|
-
direction: rtl_detect_1.getLangDir(locale),
|
|
25
|
+
direction: (0, rtl_detect_1.getLangDir)(locale),
|
|
26
|
+
htmlLang: locale,
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
29
|
exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
|
|
27
|
-
function shouldWarnAboutNodeVersion(version, locales) {
|
|
28
|
-
const isOnlyEnglish = locales.length === 1 && locales.includes('en');
|
|
29
|
-
const isOlderNodeVersion = version < 14;
|
|
30
|
-
return isOlderNodeVersion && !isOnlyEnglish;
|
|
31
|
-
}
|
|
32
|
-
exports.shouldWarnAboutNodeVersion = shouldWarnAboutNodeVersion;
|
|
33
30
|
async function loadI18n(config, options = {}) {
|
|
34
|
-
var _a;
|
|
35
31
|
const { i18n: i18nConfig } = config;
|
|
36
|
-
const currentLocale =
|
|
32
|
+
const currentLocale = options.locale ?? i18nConfig.defaultLocale;
|
|
37
33
|
if (!i18nConfig.locales.includes(currentLocale)) {
|
|
38
|
-
|
|
39
|
-
Note: Docusaurus only support running one locale at a time
|
|
34
|
+
logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
|
|
35
|
+
Note: Docusaurus only support running one locale at a time.`;
|
|
40
36
|
}
|
|
41
37
|
const locales = i18nConfig.locales.includes(currentLocale)
|
|
42
38
|
? i18nConfig.locales
|
|
43
39
|
: i18nConfig.locales.concat(currentLocale);
|
|
44
|
-
if (shouldWarnAboutNodeVersion(constants_1.NODE_MAJOR_VERSION, locales)) {
|
|
45
|
-
console.warn(chalk_1.default.yellow(`To use Docusaurus i18n, it is strongly advised to use Node.js 14 or later (instead of ${constants_1.NODE_MAJOR_VERSION}).`));
|
|
46
|
-
}
|
|
47
40
|
function getLocaleConfig(locale) {
|
|
48
41
|
return {
|
|
49
42
|
...getDefaultLocaleConfig(locale),
|
|
50
43
|
...i18nConfig.localeConfigs[locale],
|
|
51
44
|
};
|
|
52
45
|
}
|
|
53
|
-
const localeConfigs = locales.reduce((acc, locale) => {
|
|
54
|
-
return { ...acc, [locale]: getLocaleConfig(locale) };
|
|
55
|
-
}, {});
|
|
46
|
+
const localeConfigs = locales.reduce((acc, locale) => ({ ...acc, [locale]: getLocaleConfig(locale) }), {});
|
|
56
47
|
return {
|
|
57
48
|
defaultLocale: i18nConfig.defaultLocale,
|
|
58
49
|
locales,
|
|
@@ -62,26 +53,21 @@ Note: Docusaurus only support running one locale at a time.`));
|
|
|
62
53
|
}
|
|
63
54
|
exports.loadI18n = loadI18n;
|
|
64
55
|
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
65
|
-
const shouldLocalizePath =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (shouldLocalizePath) {
|
|
70
|
-
// FS paths need special care, for Windows support
|
|
71
|
-
if (pathType === 'fs') {
|
|
72
|
-
return path_1.default.join(originalPath, path_1.default.sep, i18n.currentLocale, path_1.default.sep);
|
|
73
|
-
}
|
|
74
|
-
// Url paths
|
|
75
|
-
else if (pathType === 'url') {
|
|
76
|
-
return utils_1.normalizeUrl([originalPath, '/', i18n.currentLocale, '/']);
|
|
77
|
-
}
|
|
78
|
-
// should never happen
|
|
79
|
-
else {
|
|
80
|
-
throw new Error(`Unhandled path type "${pathType}".`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
56
|
+
const shouldLocalizePath =
|
|
57
|
+
// By default, we don't localize the path of defaultLocale
|
|
58
|
+
options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
|
59
|
+
if (!shouldLocalizePath) {
|
|
84
60
|
return originalPath;
|
|
85
61
|
}
|
|
62
|
+
// FS paths need special care, for Windows support
|
|
63
|
+
if (pathType === 'fs') {
|
|
64
|
+
return path_1.default.join(originalPath, i18n.currentLocale);
|
|
65
|
+
}
|
|
66
|
+
// Url paths; add a trailing slash so it's a valid base URL
|
|
67
|
+
if (pathType === 'url') {
|
|
68
|
+
return (0, utils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
|
|
69
|
+
}
|
|
70
|
+
// should never happen
|
|
71
|
+
throw new Error(`Unhandled path type "${pathType}".`);
|
|
86
72
|
}
|
|
87
73
|
exports.localizePath = localizePath;
|
package/lib/server/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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 { DocusaurusConfig, LoadContext, PluginConfig, Props } from '@docusaurus/types';
|
|
7
|
+
import type { DocusaurusConfig, LoadContext, PluginConfig, Props } from '@docusaurus/types';
|
|
8
8
|
export declare type LoadContextOptions = {
|
|
9
9
|
customOutDir?: string;
|
|
10
10
|
customConfigFilePath?: string;
|
|
@@ -19,5 +19,5 @@ export declare function loadSiteConfig({ siteDir, customConfigFilePath, }: {
|
|
|
19
19
|
siteConfigPath: string;
|
|
20
20
|
}>;
|
|
21
21
|
export declare function loadContext(siteDir: string, options?: LoadContextOptions): Promise<LoadContext>;
|
|
22
|
-
export declare function loadPluginConfigs(context: LoadContext): PluginConfig[]
|
|
22
|
+
export declare function loadPluginConfigs(context: LoadContext): Promise<PluginConfig[]>;
|
|
23
23
|
export declare function load(siteDir: string, options?: LoadContextOptions): Promise<Props>;
|