@docusaurus/core 2.0.0-beta.16 → 2.0.0-beta.19
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 +14 -12
- package/bin/docusaurus.mjs +41 -93
- package/lib/babel/preset.js +2 -2
- package/lib/client/.eslintrc.js +2 -3
- package/lib/client/App.d.ts +1 -1
- package/lib/client/App.js +15 -7
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts} +10 -5
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +14 -9
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +34 -0
- package/lib/client/LinksCollector.d.ts +1 -1
- package/lib/client/LinksCollector.js +4 -5
- package/lib/client/PendingNavigation.d.ts +8 -17
- package/lib/client/PendingNavigation.js +39 -70
- package/lib/{server/loadSetup.d.ts → client/SiteMetadataDefaults.d.ts} +2 -2
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/client/{exports/browserContext.d.ts → browserContext.d.ts} +0 -0
- package/lib/client/{exports/browserContext.js → browserContext.js} +0 -0
- package/lib/client/clientEntry.js +3 -4
- package/lib/client/docusaurus.d.ts +5 -5
- package/lib/client/docusaurus.js +26 -33
- package/lib/client/{exports/docusaurusContext.d.ts → docusaurusContext.d.ts} +0 -0
- package/lib/client/{exports/docusaurusContext.js → docusaurusContext.js} +0 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -4
- package/lib/client/exports/BrowserOnly.js +2 -2
- package/lib/client/exports/ComponentCreator.js +65 -40
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/ErrorBoundary.js +4 -5
- package/lib/client/exports/Interpolate.d.ts +1 -1
- package/lib/client/exports/Interpolate.js +18 -41
- package/lib/client/exports/Link.d.ts +3 -15
- package/lib/client/exports/Link.js +24 -30
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +3 -3
- package/lib/client/exports/useBaseUrl.js +8 -9
- package/lib/client/exports/useDocusaurusContext.js +1 -1
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +5 -5
- package/lib/client/exports/useIsBrowser.js +1 -1
- package/lib/{server/client-modules/index.d.ts → client/exports/useRouteContext.d.ts} +2 -2
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +12 -5
- package/lib/client/normalizeLocation.js +13 -8
- package/lib/client/prefetch.js +10 -28
- package/lib/client/preload.d.ts +1 -3
- package/lib/client/preload.js +5 -11
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.js +19 -18
- package/lib/client/theme-fallback/Error/index.js +7 -1
- package/lib/client/theme-fallback/Layout/index.d.ts +1 -1
- package/lib/client/theme-fallback/Layout/index.js +2 -17
- package/lib/client/theme-fallback/Loading/index.js +2 -0
- package/lib/client/theme-fallback/NotFound/index.js +13 -5
- package/lib/client/theme-fallback/Root/index.d.ts +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -1
- 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 +48 -30
- package/lib/commands/clear.d.ts +1 -1
- package/lib/commands/clear.js +6 -5
- package/lib/commands/deploy.d.ts +5 -5
- package/lib/commands/deploy.js +21 -45
- package/lib/commands/external.d.ts +1 -1
- package/lib/commands/external.js +6 -11
- package/lib/commands/serve.d.ts +7 -2
- package/lib/commands/serve.js +18 -19
- package/lib/commands/start.d.ts +8 -2
- package/lib/commands/start.js +33 -30
- package/lib/commands/swizzle/actions.d.ts +2 -2
- package/lib/commands/swizzle/actions.js +10 -10
- package/lib/commands/swizzle/common.d.ts +3 -3
- package/lib/commands/swizzle/common.js +8 -9
- package/lib/commands/swizzle/components.js +48 -13
- package/lib/commands/swizzle/config.js +21 -15
- package/lib/commands/swizzle/context.js +6 -12
- package/lib/commands/swizzle/index.d.ts +2 -2
- package/lib/commands/swizzle/index.js +5 -4
- package/lib/commands/swizzle/prompts.js +2 -2
- package/lib/commands/swizzle/tables.js +10 -13
- package/lib/commands/swizzle/themes.js +9 -8
- package/lib/commands/writeHeadingIds.d.ts +2 -9
- package/lib/commands/writeHeadingIds.js +11 -69
- package/lib/commands/writeTranslations.d.ts +3 -4
- package/lib/commands/writeTranslations.js +10 -14
- package/lib/index.d.ts +9 -10
- package/lib/index.js +18 -19
- package/lib/server/brokenLinks.d.ts +3 -16
- package/lib/server/brokenLinks.js +37 -31
- 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 -9
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +39 -13
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/{choosePort.js → server/getHostPort.js} +24 -41
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +2 -11
- package/lib/server/i18n.js +7 -28
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +62 -229
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +65 -132
- package/lib/server/plugins/init.d.ts +6 -15
- package/lib/server/plugins/init.js +25 -83
- package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
- package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
- package/lib/server/plugins/pluginIds.d.ts +4 -0
- package/lib/server/plugins/pluginIds.js +6 -4
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/{presets/index.js → plugins/presets.js} +21 -20
- package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +3 -1
- 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 +169 -102
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +5 -14
- package/lib/server/translations/translations.js +23 -39
- package/lib/server/translations/translationsExtractor.d.ts +2 -2
- package/lib/server/translations/translationsExtractor.js +16 -19
- package/lib/server/utils.js +1 -1
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +0 -1
- package/lib/webpack/base.js +12 -30
- package/lib/webpack/client.js +7 -8
- package/lib/webpack/plugins/ChunkAssetPlugin.js +7 -7
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
- package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -2
- package/lib/webpack/plugins/LogPlugin.js +2 -2
- package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
- package/lib/webpack/plugins/WaitPlugin.js +3 -3
- package/lib/webpack/server.d.ts +2 -2
- package/lib/webpack/server.js +10 -8
- package/lib/webpack/utils.d.ts +9 -3
- package/lib/webpack/utils.js +20 -25
- package/package.json +38 -41
- package/lib/choosePort.d.ts +0 -11
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -9
- package/lib/client/client-lifecycles-dispatcher.js +0 -23
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/commandUtils.d.ts +0 -9
- package/lib/commands/commandUtils.js +0 -21
- package/lib/server/client-modules/index.js +0 -12
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -42
- package/lib/server/html-tags/htmlTags.js +0 -38
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/themes/alias.d.ts +0 -9
- package/lib/server/themes/alias.js +0 -48
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/index.d.ts +0 -9
- package/lib/server/versions/index.js +0 -51
|
@@ -6,53 +6,27 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getHostPort = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
/**
|
|
11
|
-
* This feature was heavily inspired by create-react-app and
|
|
12
|
-
* uses many of the same utility functions to implement it.
|
|
13
|
-
*/
|
|
14
11
|
const child_process_1 = require("child_process");
|
|
15
|
-
const detect_port_1 =
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const prompts_1 =
|
|
19
|
-
const isInteractive = process.stdout.isTTY;
|
|
12
|
+
const detect_port_1 = tslib_1.__importDefault(require("detect-port"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const prompts_1 = tslib_1.__importDefault(require("prompts"));
|
|
20
16
|
const execOptions = {
|
|
21
17
|
encoding: 'utf8',
|
|
22
|
-
stdio: [
|
|
23
|
-
'pipe',
|
|
24
|
-
'pipe',
|
|
25
|
-
'ignore', // stderr
|
|
26
|
-
],
|
|
18
|
+
stdio: [/* stdin */ 'pipe', /* stdout */ 'pipe', /* stderr */ 'ignore'],
|
|
27
19
|
};
|
|
28
|
-
// Clears console
|
|
29
20
|
function clearConsole() {
|
|
30
21
|
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
|
|
31
22
|
}
|
|
32
|
-
// Gets process id of what is on port
|
|
33
|
-
function getProcessIdOnPort(port) {
|
|
34
|
-
return (0, child_process_1.execSync)(`lsof -i:${port} -P -t -sTCP:LISTEN`, execOptions)
|
|
35
|
-
.toString()
|
|
36
|
-
.split('\n')[0]
|
|
37
|
-
.trim();
|
|
38
|
-
}
|
|
39
|
-
// Gets process command
|
|
40
|
-
function getProcessCommand(processId) {
|
|
41
|
-
const command = (0, child_process_1.execSync)(`ps -o command -p ${processId} | sed -n 2p`, execOptions);
|
|
42
|
-
return command.toString().replace(/\n$/, '');
|
|
43
|
-
}
|
|
44
|
-
// Gets directory of a process from its process id
|
|
45
|
-
function getDirectoryOfProcessById(processId) {
|
|
46
|
-
return (0, child_process_1.execSync)(`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`, execOptions)
|
|
47
|
-
.toString()
|
|
48
|
-
.trim();
|
|
49
|
-
}
|
|
50
|
-
// Gets process on port
|
|
51
23
|
function getProcessForPort(port) {
|
|
52
24
|
try {
|
|
53
|
-
const processId =
|
|
54
|
-
|
|
55
|
-
|
|
25
|
+
const processId = (0, child_process_1.execSync)(`lsof -i:${port} -P -t -sTCP:LISTEN`, execOptions)
|
|
26
|
+
.split('\n')[0]
|
|
27
|
+
.trim();
|
|
28
|
+
const directory = (0, child_process_1.execSync)(`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`, execOptions).trim();
|
|
29
|
+
const command = (0, child_process_1.execSync)(`ps -o command -p ${processId} | sed -n 2p`, execOptions).replace(/\n$/, '');
|
|
56
30
|
return logger_1.default.interpolate `code=${command} subdue=${`(pid ${processId})`} in path=${directory}`;
|
|
57
31
|
}
|
|
58
32
|
catch {
|
|
@@ -60,8 +34,9 @@ function getProcessForPort(port) {
|
|
|
60
34
|
}
|
|
61
35
|
}
|
|
62
36
|
/**
|
|
63
|
-
* Detects if program is running on port and prompts user
|
|
64
|
-
*
|
|
37
|
+
* Detects if program is running on port, and prompts user to choose another if
|
|
38
|
+
* port is already being used. This feature was heavily inspired by
|
|
39
|
+
* create-react-app and uses many of the same utility functions to implement it.
|
|
65
40
|
*/
|
|
66
41
|
async function choosePort(host, defaultPort) {
|
|
67
42
|
try {
|
|
@@ -69,7 +44,9 @@ async function choosePort(host, defaultPort) {
|
|
|
69
44
|
if (port === defaultPort) {
|
|
70
45
|
return port;
|
|
71
46
|
}
|
|
72
|
-
const
|
|
47
|
+
const isRoot = process.getuid?.() === 0;
|
|
48
|
+
const isInteractive = process.stdout.isTTY;
|
|
49
|
+
const message = process.platform !== 'win32' && defaultPort < 1024 && !isRoot
|
|
73
50
|
? `Admin permissions are required to run a server on a port below 1024.`
|
|
74
51
|
: `Something is already running on port ${defaultPort}.`;
|
|
75
52
|
if (!isInteractive) {
|
|
@@ -93,4 +70,10 @@ Would you like to run the app on another port instead?`),
|
|
|
93
70
|
throw err;
|
|
94
71
|
}
|
|
95
72
|
}
|
|
96
|
-
|
|
73
|
+
async function getHostPort(options) {
|
|
74
|
+
const host = options.host ?? 'localhost';
|
|
75
|
+
const basePort = options.port ? parseInt(options.port, 10) : utils_1.DEFAULT_PORT;
|
|
76
|
+
const port = await choosePort(host, basePort);
|
|
77
|
+
return { host, port };
|
|
78
|
+
}
|
|
79
|
+
exports.getHostPort = getHostPort;
|
|
@@ -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 { Props, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Runs the `injectHtmlTags` lifecycle, and aggregates all plugins' tags into
|
|
10
|
+
* directly render-able HTML markup.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadHtmlTags(plugins: LoadedPlugin[]): Pick<Props, 'headTags' | 'preBodyTags' | 'postBodyTags'>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.loadHtmlTags = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const html_tags_1 = tslib_1.__importDefault(require("html-tags"));
|
|
12
|
+
const void_1 = tslib_1.__importDefault(require("html-tags/void"));
|
|
13
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
|
+
function assertIsHtmlTagObject(val) {
|
|
16
|
+
if (typeof val !== 'object' || !val) {
|
|
17
|
+
throw new Error(`"${val}" is not a valid HTML tag object.`);
|
|
18
|
+
}
|
|
19
|
+
if (typeof val.tagName !== 'string') {
|
|
20
|
+
throw new Error(`${JSON.stringify(val)} is not a valid HTML tag object. "tagName" must be defined as a string.`);
|
|
21
|
+
}
|
|
22
|
+
if (!html_tags_1.default.includes(val.tagName)) {
|
|
23
|
+
throw new Error(`Error loading ${JSON.stringify(val)}, "${val.tagName}" is not a valid HTML tag.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function htmlTagObjectToString(tag) {
|
|
27
|
+
assertIsHtmlTagObject(tag);
|
|
28
|
+
const isVoidTag = void_1.default.includes(tag.tagName);
|
|
29
|
+
const tagAttributes = tag.attributes ?? {};
|
|
30
|
+
const attributes = Object.keys(tagAttributes)
|
|
31
|
+
.map((attr) => {
|
|
32
|
+
const value = tagAttributes[attr];
|
|
33
|
+
if (typeof value === 'boolean') {
|
|
34
|
+
return value ? attr : undefined;
|
|
35
|
+
}
|
|
36
|
+
return `${attr}="${(0, escape_html_1.default)(value)}"`;
|
|
37
|
+
})
|
|
38
|
+
.filter((str) => Boolean(str));
|
|
39
|
+
const openingTag = `<${[tag.tagName].concat(attributes).join(' ')}>`;
|
|
40
|
+
const innerHTML = (!isVoidTag && tag.innerHTML) || '';
|
|
41
|
+
const closingTag = isVoidTag ? '' : `</${tag.tagName}>`;
|
|
42
|
+
return openingTag + innerHTML + closingTag;
|
|
43
|
+
}
|
|
44
|
+
function createHtmlTagsString(tags) {
|
|
45
|
+
return (Array.isArray(tags) ? tags : [tags])
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.map((val) => (typeof val === 'string' ? val : htmlTagObjectToString(val)))
|
|
48
|
+
.join('\n');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Runs the `injectHtmlTags` lifecycle, and aggregates all plugins' tags into
|
|
52
|
+
* directly render-able HTML markup.
|
|
53
|
+
*/
|
|
54
|
+
function loadHtmlTags(plugins) {
|
|
55
|
+
const pluginHtmlTags = plugins.map((plugin) => plugin.injectHtmlTags?.({ content: plugin.content }) ?? {});
|
|
56
|
+
const tagTypes = ['headTags', 'preBodyTags', 'postBodyTags'];
|
|
57
|
+
return Object.fromEntries(lodash_1.default.zip(tagTypes, tagTypes.map((type) => pluginHtmlTags
|
|
58
|
+
.map((tags) => createHtmlTagsString(tags[type]))
|
|
59
|
+
.join('\n')
|
|
60
|
+
.trim())));
|
|
61
|
+
}
|
|
62
|
+
exports.loadHtmlTags = loadHtmlTags;
|
package/lib/server/i18n.d.ts
CHANGED
|
@@ -5,15 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
|
|
8
|
+
import type { LoadContextOptions } from './index';
|
|
8
9
|
export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
|
|
9
|
-
export declare function loadI18n(config: DocusaurusConfig, options
|
|
10
|
-
locale?: string;
|
|
11
|
-
}): Promise<I18n>;
|
|
12
|
-
export declare function localizePath({ pathType, path: originalPath, i18n, options, }: {
|
|
13
|
-
pathType: 'fs' | 'url';
|
|
14
|
-
path: string;
|
|
15
|
-
i18n: I18n;
|
|
16
|
-
options?: {
|
|
17
|
-
localizePath?: boolean;
|
|
18
|
-
};
|
|
19
|
-
}): string;
|
|
10
|
+
export declare function loadI18n(config: DocusaurusConfig, options: Pick<LoadContextOptions, 'locale'>): Promise<I18n>;
|
package/lib/server/i18n.js
CHANGED
|
@@ -6,12 +6,10 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
|
-
const utils_1 = require("@docusaurus/utils");
|
|
13
11
|
const rtl_detect_1 = require("rtl-detect");
|
|
14
|
-
const logger_1 =
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
13
|
function getDefaultLocaleLabel(locale) {
|
|
16
14
|
const languageName = new Intl.DisplayNames(locale, { type: 'language' }).of(locale);
|
|
17
15
|
return (languageName.charAt(0).toLocaleUpperCase(locale) + languageName.substring(1));
|
|
@@ -21,13 +19,14 @@ function getDefaultLocaleConfig(locale) {
|
|
|
21
19
|
label: getDefaultLocaleLabel(locale),
|
|
22
20
|
direction: (0, rtl_detect_1.getLangDir)(locale),
|
|
23
21
|
htmlLang: locale,
|
|
22
|
+
// If the locale name includes -u-ca-xxx the calendar will be defined
|
|
23
|
+
calendar: new Intl.Locale(locale).calendar ?? 'gregory',
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
|
|
27
|
-
async function loadI18n(config, options
|
|
28
|
-
var _a;
|
|
27
|
+
async function loadI18n(config, options) {
|
|
29
28
|
const { i18n: i18nConfig } = config;
|
|
30
|
-
const currentLocale =
|
|
29
|
+
const currentLocale = options.locale ?? i18nConfig.defaultLocale;
|
|
31
30
|
if (!i18nConfig.locales.includes(currentLocale)) {
|
|
32
31
|
logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
|
|
33
32
|
Note: Docusaurus only support running one locale at a time.`;
|
|
@@ -41,7 +40,7 @@ Note: Docusaurus only support running one locale at a time.`;
|
|
|
41
40
|
...i18nConfig.localeConfigs[locale],
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
const localeConfigs = locales.
|
|
43
|
+
const localeConfigs = Object.fromEntries(locales.map((locale) => [locale, getLocaleConfig(locale)]));
|
|
45
44
|
return {
|
|
46
45
|
defaultLocale: i18nConfig.defaultLocale,
|
|
47
46
|
locales,
|
|
@@ -50,23 +49,3 @@ Note: Docusaurus only support running one locale at a time.`;
|
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
exports.loadI18n = loadI18n;
|
|
53
|
-
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
54
|
-
var _a;
|
|
55
|
-
const shouldLocalizePath =
|
|
56
|
-
// By default, we don't localize the path of defaultLocale
|
|
57
|
-
(_a = options.localizePath) !== null && _a !== void 0 ? _a : i18n.currentLocale !== i18n.defaultLocale;
|
|
58
|
-
if (!shouldLocalizePath) {
|
|
59
|
-
return originalPath;
|
|
60
|
-
}
|
|
61
|
-
// FS paths need special care, for Windows support
|
|
62
|
-
if (pathType === 'fs') {
|
|
63
|
-
return path_1.default.join(originalPath, i18n.currentLocale);
|
|
64
|
-
}
|
|
65
|
-
// Url paths; add a trailing slash so it's a valid base URL
|
|
66
|
-
if (pathType === 'url') {
|
|
67
|
-
return (0, utils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
|
|
68
|
-
}
|
|
69
|
-
// should never happen
|
|
70
|
-
throw new Error(`Unhandled path type "${pathType}".`);
|
|
71
|
-
}
|
|
72
|
-
exports.localizePath = localizePath;
|
package/lib/server/index.d.ts
CHANGED
|
@@ -4,20 +4,35 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { LoadContext, Props } from '@docusaurus/types';
|
|
8
8
|
export declare type LoadContextOptions = {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** Usually the CWD; can be overridden with command argument. */
|
|
10
|
+
siteDir: string;
|
|
11
|
+
/** Custom output directory. Can be customized with `--out-dir` option */
|
|
12
|
+
outDir?: string;
|
|
13
|
+
/** Custom config path. Can be customized with `--config` option */
|
|
14
|
+
config?: string;
|
|
15
|
+
/** Default is `i18n.defaultLocale` */
|
|
11
16
|
locale?: string;
|
|
17
|
+
/**
|
|
18
|
+
* `true` means the paths will have the locale prepended; `false` means they
|
|
19
|
+
* won't (useful for `yarn build -l zh-Hans` where the output should be
|
|
20
|
+
* emitted into `build/` instead of `build/zh-Hans/`); `undefined` is like the
|
|
21
|
+
* "smart" option where only non-default locale paths are localized
|
|
22
|
+
*/
|
|
12
23
|
localizePath?: boolean;
|
|
13
24
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Loading context is the very first step in site building. Its options are
|
|
27
|
+
* directly acquired from CLI options. It mainly loads `siteConfig` and the i18n
|
|
28
|
+
* context (which includes code translations). The `LoadContext` will be passed
|
|
29
|
+
* to plugin constructors.
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadContext(options: LoadContextOptions): Promise<LoadContext>;
|
|
32
|
+
/**
|
|
33
|
+
* This is the crux of the Docusaurus server-side. It reads everything it needs—
|
|
34
|
+
* code translations, config file, plugin modules... Plugins then use their
|
|
35
|
+
* lifecycles to generate content and other data. It is side-effect-ful because
|
|
36
|
+
* it generates temp files in the `.docusaurus` folder for the bundler.
|
|
37
|
+
*/
|
|
38
|
+
export declare function load(options: LoadContextOptions): Promise<Props>;
|