@docusaurus/core 0.0.0-4807 → 0.0.0-4812
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/server/index.js +1 -3
- package/lib/server/plugins/index.d.ts +3 -3
- package/lib/server/plugins/index.js +22 -40
- package/lib/server/translations/translations.d.ts +5 -13
- package/lib/server/translations/translationsExtractor.d.ts +2 -4
- package/lib/webpack/aliases/index.d.ts +1 -3
- package/package.json +10 -10
package/lib/server/index.js
CHANGED
|
@@ -76,9 +76,7 @@ async function load(options) {
|
|
|
76
76
|
const { siteDir } = options;
|
|
77
77
|
const context = await loadContext(options);
|
|
78
78
|
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, ssrTemplate, codeTranslations: siteCodeTranslations, } = context;
|
|
79
|
-
const { plugins, pluginsRouteConfigs, globalData
|
|
80
|
-
// Side-effect to replace the untranslated themeConfig by the translated one
|
|
81
|
-
context.siteConfig.themeConfig = themeConfigTranslated;
|
|
79
|
+
const { plugins, pluginsRouteConfigs, globalData } = await (0, plugins_1.loadPlugins)(context);
|
|
82
80
|
const clientModules = (0, clientModules_1.loadClientModules)(plugins);
|
|
83
81
|
const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
|
|
84
82
|
const { registry, routesChunkNames, routesConfig, routesPaths } = await (0, routes_1.loadRoutes)(pluginsRouteConfigs, baseUrl, siteConfig.onDuplicateRoutes);
|
|
@@ -4,15 +4,15 @@
|
|
|
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 { LoadContext, RouteConfig, GlobalData,
|
|
7
|
+
import type { LoadContext, RouteConfig, GlobalData, LoadedPlugin } from '@docusaurus/types';
|
|
8
8
|
/**
|
|
9
9
|
* Initializes the plugins, runs `loadContent`, `translateContent`,
|
|
10
10
|
* `contentLoaded`, and `translateThemeConfig`. Because `contentLoaded` is
|
|
11
|
-
* side-effect-ful (it generates temp files), so is this function.
|
|
11
|
+
* side-effect-ful (it generates temp files), so is this function. This function
|
|
12
|
+
* would also mutate `context.siteConfig.themeConfig` to translate it.
|
|
12
13
|
*/
|
|
13
14
|
export declare function loadPlugins(context: LoadContext): Promise<{
|
|
14
15
|
plugins: LoadedPlugin[];
|
|
15
16
|
pluginsRouteConfigs: RouteConfig[];
|
|
16
17
|
globalData: GlobalData;
|
|
17
|
-
themeConfigTranslated: ThemeConfig;
|
|
18
18
|
}>;
|
|
@@ -19,7 +19,8 @@ const routeConfig_1 = require("./routeConfig");
|
|
|
19
19
|
/**
|
|
20
20
|
* Initializes the plugins, runs `loadContent`, `translateContent`,
|
|
21
21
|
* `contentLoaded`, and `translateThemeConfig`. Because `contentLoaded` is
|
|
22
|
-
* side-effect-ful (it generates temp files), so is this function.
|
|
22
|
+
* side-effect-ful (it generates temp files), so is this function. This function
|
|
23
|
+
* would also mutate `context.siteConfig.themeConfig` to translate it.
|
|
23
24
|
*/
|
|
24
25
|
async function loadPlugins(context) {
|
|
25
26
|
// 1. Plugin Lifecycle - Initialization/Constructor.
|
|
@@ -29,24 +30,27 @@ async function loadPlugins(context) {
|
|
|
29
30
|
// Currently plugins run lifecycle methods in parallel and are not
|
|
30
31
|
// order-dependent. We could change this in future if there are plugins which
|
|
31
32
|
// need to run in certain order or depend on others for data.
|
|
33
|
+
// This would also translate theme config and content upfront, given the
|
|
34
|
+
// translation files that the plugin declares.
|
|
32
35
|
const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
|
|
33
36
|
const content = await plugin.loadContent?.();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const contentLoadedTranslatedPlugins = await Promise.all(loadedPlugins.map(async (plugin) => {
|
|
37
|
-
const translationFiles = (await plugin?.getTranslationFiles?.({
|
|
38
|
-
content: plugin.content,
|
|
39
|
-
})) ?? [];
|
|
40
|
-
const localizedTranslationFiles = await Promise.all(translationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
37
|
+
const rawTranslationFiles = (await plugin?.getTranslationFiles?.({ content })) ?? [];
|
|
38
|
+
const translationFiles = await Promise.all(rawTranslationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
41
39
|
locale: context.i18n.currentLocale,
|
|
42
40
|
siteDir: context.siteDir,
|
|
43
41
|
translationFile,
|
|
44
42
|
plugin,
|
|
45
43
|
})));
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
const translatedContent = plugin.translateContent?.({ content, translationFiles }) ?? content;
|
|
45
|
+
const translatedThemeConfigSlice = plugin.translateThemeConfig?.({
|
|
46
|
+
themeConfig: context.siteConfig.themeConfig,
|
|
47
|
+
translationFiles,
|
|
48
|
+
});
|
|
49
|
+
// Side-effect to merge theme config translations. A plugin should only
|
|
50
|
+
// translate its own slice of theme config and should make no assumptions
|
|
51
|
+
// about other plugins' keys, so this is safe to run in parallel.
|
|
52
|
+
Object.assign(context.siteConfig.themeConfig, translatedThemeConfigSlice);
|
|
53
|
+
return { ...plugin, content: translatedContent };
|
|
50
54
|
}));
|
|
51
55
|
const allContent = lodash_1.default.chain(loadedPlugins)
|
|
52
56
|
.groupBy((item) => item.name)
|
|
@@ -58,7 +62,7 @@ async function loadPlugins(context) {
|
|
|
58
62
|
// 3. Plugin Lifecycle - contentLoaded.
|
|
59
63
|
const pluginsRouteConfigs = [];
|
|
60
64
|
const globalData = {};
|
|
61
|
-
await Promise.all(
|
|
65
|
+
await Promise.all(loadedPlugins.map(async ({ content, ...plugin }) => {
|
|
62
66
|
if (!plugin.contentLoaded) {
|
|
63
67
|
return;
|
|
64
68
|
}
|
|
@@ -96,43 +100,21 @@ async function loadPlugins(context) {
|
|
|
96
100
|
globalData[plugin.name][pluginId] = data;
|
|
97
101
|
},
|
|
98
102
|
};
|
|
99
|
-
|
|
100
|
-
await plugin.contentLoaded({
|
|
101
|
-
content: translatedContent,
|
|
102
|
-
actions,
|
|
103
|
-
allContent,
|
|
104
|
-
});
|
|
103
|
+
await plugin.contentLoaded({ content, actions, allContent });
|
|
105
104
|
}));
|
|
106
105
|
// 4. Plugin Lifecycle - routesLoaded.
|
|
107
|
-
await Promise.all(
|
|
106
|
+
await Promise.all(loadedPlugins.map(async (plugin) => {
|
|
108
107
|
if (!plugin.routesLoaded) {
|
|
109
108
|
return;
|
|
110
109
|
}
|
|
111
|
-
// TODO remove this deprecated lifecycle soon
|
|
112
|
-
//
|
|
113
|
-
// TODO, 1 user reported usage of this lifecycle! https://github.com/facebook/docusaurus/issues/3918
|
|
110
|
+
// TODO alpha-60: remove this deprecated lifecycle soon
|
|
111
|
+
// 1 user reported usage of this lifecycle: https://github.com/facebook/docusaurus/issues/3918
|
|
114
112
|
logger_1.default.error `Plugin code=${'routesLoaded'} lifecycle is deprecated. If you think we should keep this lifecycle, please report here: url=${'https://github.com/facebook/docusaurus/issues/3918'}`;
|
|
115
113
|
await plugin.routesLoaded(pluginsRouteConfigs);
|
|
116
114
|
}));
|
|
117
115
|
// Sort the route config. This ensures that route with nested
|
|
118
116
|
// routes are always placed last.
|
|
119
117
|
(0, routeConfig_1.sortConfig)(pluginsRouteConfigs, context.siteConfig.baseUrl);
|
|
120
|
-
|
|
121
|
-
const themeConfigTranslated = contentLoadedTranslatedPlugins.reduce((currentThemeConfig, plugin) => {
|
|
122
|
-
const translatedThemeConfigSlice = plugin.translateThemeConfig?.({
|
|
123
|
-
themeConfig: currentThemeConfig,
|
|
124
|
-
translationFiles: plugin.translationFiles,
|
|
125
|
-
});
|
|
126
|
-
return {
|
|
127
|
-
...currentThemeConfig,
|
|
128
|
-
...translatedThemeConfigSlice,
|
|
129
|
-
};
|
|
130
|
-
}, context.siteConfig.themeConfig);
|
|
131
|
-
return {
|
|
132
|
-
plugins: loadedPlugins,
|
|
133
|
-
pluginsRouteConfigs,
|
|
134
|
-
globalData,
|
|
135
|
-
themeConfigTranslated,
|
|
136
|
-
};
|
|
118
|
+
return { plugins: loadedPlugins, pluginsRouteConfigs, globalData };
|
|
137
119
|
}
|
|
138
120
|
exports.loadPlugins = loadPlugins;
|
|
@@ -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 type { TranslationFileContent, TranslationFile,
|
|
7
|
+
import type { TranslationFileContent, TranslationFile, CodeTranslations, InitializedPlugin } from '@docusaurus/types';
|
|
8
8
|
export declare type WriteTranslationsOptions = {
|
|
9
9
|
override?: boolean;
|
|
10
10
|
messagePrefix?: string;
|
|
@@ -25,17 +25,9 @@ export declare function localizePluginTranslationFile({ siteDir, plugin, locale,
|
|
|
25
25
|
plugin: InitializedPlugin;
|
|
26
26
|
translationFile: TranslationFile;
|
|
27
27
|
}): Promise<TranslationFile>;
|
|
28
|
-
export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<
|
|
29
|
-
[msgId: string]: string;
|
|
30
|
-
}>;
|
|
28
|
+
export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<CodeTranslations>;
|
|
31
29
|
export declare function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }: {
|
|
32
|
-
extractedCodeTranslations:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
defaultCodeMessages: {
|
|
36
|
-
[msgId: string]: string;
|
|
37
|
-
};
|
|
38
|
-
}): {
|
|
39
|
-
[msgId: string]: TranslationMessage;
|
|
40
|
-
};
|
|
30
|
+
extractedCodeTranslations: TranslationFileContent;
|
|
31
|
+
defaultCodeMessages: CodeTranslations;
|
|
32
|
+
}): TranslationFileContent;
|
|
41
33
|
export {};
|
|
@@ -5,14 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { type TransformOptions } from '@babel/core';
|
|
8
|
-
import type { InitializedPlugin, TranslationFileContent
|
|
8
|
+
import type { InitializedPlugin, TranslationFileContent } from '@docusaurus/types';
|
|
9
9
|
export declare function globSourceCodeFilePaths(dirPaths: string[]): Promise<string[]>;
|
|
10
10
|
export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitializedPlugin[], babelOptions: TransformOptions, extraSourceCodeFilePaths?: string[]): Promise<TranslationFileContent>;
|
|
11
11
|
declare type SourceCodeFileTranslations = {
|
|
12
12
|
sourceCodeFilePath: string;
|
|
13
|
-
translations:
|
|
14
|
-
[msgId: string]: TranslationMessage;
|
|
15
|
-
};
|
|
13
|
+
translations: TranslationFileContent;
|
|
16
14
|
warnings: string[];
|
|
17
15
|
};
|
|
18
16
|
export declare function extractAllSourceCodeFileTranslations(sourceCodeFilePaths: string[], babelOptions: TransformOptions): Promise<SourceCodeFileTranslations[]>;
|
|
@@ -24,6 +24,4 @@ export declare function loadThemeAliases({ siteDir, plugins, }: {
|
|
|
24
24
|
* instead of naively aliasing this to `client/exports`, we use fine-grained
|
|
25
25
|
* aliases instead.
|
|
26
26
|
*/
|
|
27
|
-
export declare function loadDocusaurusAliases(): Promise<
|
|
28
|
-
[aliasName: string]: string;
|
|
29
|
-
}>;
|
|
27
|
+
export declare function loadDocusaurusAliases(): Promise<ThemeAliases>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-4812",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"@babel/runtime": "^7.17.8",
|
|
42
42
|
"@babel/runtime-corejs3": "^7.17.8",
|
|
43
43
|
"@babel/traverse": "^7.17.3",
|
|
44
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
45
|
-
"@docusaurus/logger": "0.0.0-
|
|
46
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
44
|
+
"@docusaurus/cssnano-preset": "0.0.0-4812",
|
|
45
|
+
"@docusaurus/logger": "0.0.0-4812",
|
|
46
|
+
"@docusaurus/mdx-loader": "0.0.0-4812",
|
|
47
47
|
"@docusaurus/react-loadable": "5.5.2",
|
|
48
|
-
"@docusaurus/utils": "0.0.0-
|
|
49
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
50
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
48
|
+
"@docusaurus/utils": "0.0.0-4812",
|
|
49
|
+
"@docusaurus/utils-common": "0.0.0-4812",
|
|
50
|
+
"@docusaurus/utils-validation": "0.0.0-4812",
|
|
51
51
|
"@slorber/static-site-generator-webpack-plugin": "^4.0.4",
|
|
52
52
|
"@svgr/webpack": "^6.2.1",
|
|
53
53
|
"autoprefixer": "^10.4.4",
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
"webpackbar": "^5.0.2"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
109
|
-
"@docusaurus/types": "0.0.0-
|
|
108
|
+
"@docusaurus/module-type-aliases": "0.0.0-4812",
|
|
109
|
+
"@docusaurus/types": "0.0.0-4812",
|
|
110
110
|
"@types/detect-port": "^1.3.2",
|
|
111
111
|
"@types/nprogress": "^0.2.0",
|
|
112
112
|
"@types/react-dom": "^17.0.14",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"engines": {
|
|
128
128
|
"node": ">=14"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "7b54ca31ae70170874768f01443d6c9b6256054c"
|
|
131
131
|
}
|