@docusaurus/core 0.0.0-4518 → 0.0.0-4524
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/babel/preset.js +5 -4
- package/lib/client/App.js +12 -6
- package/lib/client/LinksCollector.js +1 -1
- package/lib/client/PendingNavigation.d.ts +3 -3
- package/lib/client/PendingNavigation.js +3 -3
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/clientEntry.js +8 -5
- package/lib/client/docusaurus.js +5 -3
- package/lib/client/exports/BrowserOnly.js +1 -1
- package/lib/client/exports/ComponentCreator.js +5 -2
- package/lib/client/exports/Head.js +1 -1
- package/lib/client/exports/Interpolate.js +9 -12
- package/lib/client/exports/Link.js +7 -4
- package/lib/client/exports/Translate.js +2 -1
- package/lib/client/exports/browserContext.js +3 -2
- package/lib/client/exports/docusaurusContext.js +1 -1
- package/lib/client/preload.d.ts +2 -1
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.js +8 -5
- package/lib/client/theme-fallback/Error/index.d.ts +11 -0
- package/lib/client/theme-fallback/Error/index.js +21 -28
- package/lib/client/theme-fallback/Layout/index.d.ts +11 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -18
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +46 -114
- package/lib/client/theme-fallback/NotFound/index.d.ts +9 -0
- package/lib/client/theme-fallback/NotFound/index.js +8 -14
- package/lib/client/theme-fallback/Root/index.d.ts +11 -0
- package/lib/client/theme-fallback/Root/index.js +2 -4
- package/lib/commands/build.js +15 -17
- package/lib/commands/deploy.js +3 -3
- package/lib/commands/serve.js +2 -2
- package/lib/commands/swizzle.js +4 -2
- package/lib/commands/writeHeadingIds.js +10 -11
- package/lib/commands/writeTranslations.js +7 -4
- package/lib/server/brokenLinks.js +14 -9
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +2 -1
- package/lib/server/duplicateRoutes.js +2 -4
- package/lib/server/i18n.js +11 -15
- package/lib/server/index.js +9 -7
- package/lib/server/plugins/index.js +6 -6
- package/lib/server/plugins/init.js +12 -22
- package/lib/server/presets/index.js +2 -2
- package/lib/server/routes.js +2 -1
- package/lib/server/themes/index.js +3 -2
- package/lib/server/translations/translations.js +2 -4
- package/lib/server/translations/translationsExtractor.js +17 -14
- package/lib/server/versions/index.js +4 -2
- package/lib/webpack/base.js +19 -11
- package/lib/webpack/client.js +5 -2
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +11 -0
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +4 -3
- package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -1
- package/lib/webpack/server.js +4 -3
- package/lib/webpack/utils.js +8 -9
- package/package.json +10 -10
|
@@ -4,133 +4,65 @@
|
|
|
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
|
-
|
|
8
7
|
import React from 'react';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
maxWidth: '50%',
|
|
30
|
-
width: '100%',
|
|
31
|
-
}}>
|
|
8
|
+
export default function Loading({ error, retry, pastDelay, }) {
|
|
9
|
+
if (error) {
|
|
10
|
+
return (<div style={{
|
|
11
|
+
textAlign: 'center',
|
|
12
|
+
color: '#fff',
|
|
13
|
+
backgroundColor: '#fa383e',
|
|
14
|
+
borderColor: '#fa383e',
|
|
15
|
+
borderStyle: 'solid',
|
|
16
|
+
borderRadius: '0.25rem',
|
|
17
|
+
borderWidth: '1px',
|
|
18
|
+
boxSizing: 'border-box',
|
|
19
|
+
display: 'block',
|
|
20
|
+
padding: '1rem',
|
|
21
|
+
flex: '0 0 50%',
|
|
22
|
+
marginLeft: '25%',
|
|
23
|
+
marginRight: '25%',
|
|
24
|
+
marginTop: '5rem',
|
|
25
|
+
maxWidth: '50%',
|
|
26
|
+
width: '100%',
|
|
27
|
+
}}>
|
|
32
28
|
<p>{error.message}</p>
|
|
33
29
|
<div>
|
|
34
30
|
<button type="button" onClick={retry}>
|
|
35
31
|
Retry
|
|
36
32
|
</button>
|
|
37
33
|
</div>
|
|
38
|
-
</div>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
width: 128,
|
|
55
|
-
height: 110,
|
|
56
|
-
position: 'absolute',
|
|
57
|
-
top: 'calc(100vh - 64%)',
|
|
58
|
-
}}
|
|
59
|
-
viewBox="0 0 45 45"
|
|
60
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
61
|
-
stroke="#61dafb">
|
|
62
|
-
<g
|
|
63
|
-
fill="none"
|
|
64
|
-
fillRule="evenodd"
|
|
65
|
-
transform="translate(1 1)"
|
|
66
|
-
strokeWidth="2">
|
|
34
|
+
</div>);
|
|
35
|
+
}
|
|
36
|
+
if (pastDelay) {
|
|
37
|
+
return (<div style={{
|
|
38
|
+
display: 'flex',
|
|
39
|
+
justifyContent: 'center',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
height: '100vh',
|
|
42
|
+
}}>
|
|
43
|
+
<svg id="loader" style={{
|
|
44
|
+
width: 128,
|
|
45
|
+
height: 110,
|
|
46
|
+
position: 'absolute',
|
|
47
|
+
top: 'calc(100vh - 64%)',
|
|
48
|
+
}} viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" stroke="#61dafb">
|
|
49
|
+
<g fill="none" fillRule="evenodd" transform="translate(1 1)" strokeWidth="2">
|
|
67
50
|
<circle cx="22" cy="22" r="6" strokeOpacity="0">
|
|
68
|
-
<animate
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
dur="3s"
|
|
72
|
-
values="6;22"
|
|
73
|
-
calcMode="linear"
|
|
74
|
-
repeatCount="indefinite"
|
|
75
|
-
/>
|
|
76
|
-
<animate
|
|
77
|
-
attributeName="stroke-opacity"
|
|
78
|
-
begin="1.5s"
|
|
79
|
-
dur="3s"
|
|
80
|
-
values="1;0"
|
|
81
|
-
calcMode="linear"
|
|
82
|
-
repeatCount="indefinite"
|
|
83
|
-
/>
|
|
84
|
-
<animate
|
|
85
|
-
attributeName="stroke-width"
|
|
86
|
-
begin="1.5s"
|
|
87
|
-
dur="3s"
|
|
88
|
-
values="2;0"
|
|
89
|
-
calcMode="linear"
|
|
90
|
-
repeatCount="indefinite"
|
|
91
|
-
/>
|
|
51
|
+
<animate attributeName="r" begin="1.5s" dur="3s" values="6;22" calcMode="linear" repeatCount="indefinite"/>
|
|
52
|
+
<animate attributeName="stroke-opacity" begin="1.5s" dur="3s" values="1;0" calcMode="linear" repeatCount="indefinite"/>
|
|
53
|
+
<animate attributeName="stroke-width" begin="1.5s" dur="3s" values="2;0" calcMode="linear" repeatCount="indefinite"/>
|
|
92
54
|
</circle>
|
|
93
55
|
<circle cx="22" cy="22" r="6" strokeOpacity="0">
|
|
94
|
-
<animate
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
dur="3s"
|
|
98
|
-
values="6;22"
|
|
99
|
-
calcMode="linear"
|
|
100
|
-
repeatCount="indefinite"
|
|
101
|
-
/>
|
|
102
|
-
<animate
|
|
103
|
-
attributeName="stroke-opacity"
|
|
104
|
-
begin="3s"
|
|
105
|
-
dur="3s"
|
|
106
|
-
values="1;0"
|
|
107
|
-
calcMode="linear"
|
|
108
|
-
repeatCount="indefinite"
|
|
109
|
-
/>
|
|
110
|
-
<animate
|
|
111
|
-
attributeName="stroke-width"
|
|
112
|
-
begin="3s"
|
|
113
|
-
dur="3s"
|
|
114
|
-
values="2;0"
|
|
115
|
-
calcMode="linear"
|
|
116
|
-
repeatCount="indefinite"
|
|
117
|
-
/>
|
|
56
|
+
<animate attributeName="r" begin="3s" dur="3s" values="6;22" calcMode="linear" repeatCount="indefinite"/>
|
|
57
|
+
<animate attributeName="stroke-opacity" begin="3s" dur="3s" values="1;0" calcMode="linear" repeatCount="indefinite"/>
|
|
58
|
+
<animate attributeName="stroke-width" begin="3s" dur="3s" values="2;0" calcMode="linear" repeatCount="indefinite"/>
|
|
118
59
|
</circle>
|
|
119
60
|
<circle cx="22" cy="22" r="8">
|
|
120
|
-
<animate
|
|
121
|
-
attributeName="r"
|
|
122
|
-
begin="0s"
|
|
123
|
-
dur="1.5s"
|
|
124
|
-
values="6;1;2;3;4;5;6"
|
|
125
|
-
calcMode="linear"
|
|
126
|
-
repeatCount="indefinite"
|
|
127
|
-
/>
|
|
61
|
+
<animate attributeName="r" begin="0s" dur="1.5s" values="6;1;2;3;4;5;6" calcMode="linear" repeatCount="indefinite"/>
|
|
128
62
|
</circle>
|
|
129
63
|
</g>
|
|
130
64
|
</svg>
|
|
131
|
-
</div>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return null;
|
|
65
|
+
</div>);
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
136
68
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
declare function NotFound(): JSX.Element;
|
|
9
|
+
export default NotFound;
|
|
@@ -4,25 +4,19 @@
|
|
|
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
|
-
|
|
8
7
|
import React from 'react';
|
|
9
8
|
import Layout from '@theme/Layout';
|
|
10
|
-
|
|
11
9
|
function NotFound() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
height: '50vh',
|
|
20
|
-
fontSize: '20px',
|
|
10
|
+
return (<Layout title="Page Not Found">
|
|
11
|
+
<div style={{
|
|
12
|
+
display: 'flex',
|
|
13
|
+
justifyContent: 'center',
|
|
14
|
+
alignItems: 'center',
|
|
15
|
+
height: '50vh',
|
|
16
|
+
fontSize: '20px',
|
|
21
17
|
}}>
|
|
22
18
|
<h1>Oops, page not found </h1>
|
|
23
19
|
</div>
|
|
24
|
-
</Layout>
|
|
25
|
-
);
|
|
20
|
+
</Layout>);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
export default NotFound;
|
|
@@ -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 { ReactNode } from 'react';
|
|
8
|
+
declare function Root({ children }: {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): ReactNode;
|
|
11
|
+
export default Root;
|
|
@@ -4,7 +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
|
-
|
|
8
7
|
// Wrapper at the very top of the app, that is applied constantly
|
|
9
8
|
// and does not depend on current route (unlike the layout)
|
|
10
9
|
//
|
|
@@ -12,8 +11,7 @@
|
|
|
12
11
|
// and these providers won't reset state when we navigate
|
|
13
12
|
//
|
|
14
13
|
// See https://github.com/facebook/docusaurus/issues/3919
|
|
15
|
-
function Root({children}) {
|
|
16
|
-
|
|
14
|
+
function Root({ children }) {
|
|
15
|
+
return children;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
export default Root;
|
package/lib/commands/build.js
CHANGED
|
@@ -58,22 +58,20 @@ forceTerminate = true) {
|
|
|
58
58
|
if (cliOptions.locale) {
|
|
59
59
|
return tryToBuildLocale({ locale: cliOptions.locale, isLastLocale: true });
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
|
|
64
|
-
}
|
|
65
|
-
// We need the default locale to always be the 1st in the list
|
|
66
|
-
// If we build it last, it would "erase" the localized sites built in sub-folders
|
|
67
|
-
const orderedLocales = [
|
|
68
|
-
i18n.defaultLocale,
|
|
69
|
-
...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
|
|
70
|
-
];
|
|
71
|
-
const results = await (0, utils_2.mapAsyncSequential)(orderedLocales, (locale) => {
|
|
72
|
-
const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
|
|
73
|
-
return tryToBuildLocale({ locale, isLastLocale });
|
|
74
|
-
});
|
|
75
|
-
return results[0];
|
|
61
|
+
if (i18n.locales.length > 1) {
|
|
62
|
+
logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
|
|
76
63
|
}
|
|
64
|
+
// We need the default locale to always be the 1st in the list. If we build it
|
|
65
|
+
// last, it would "erase" the localized sites built in sub-folders
|
|
66
|
+
const orderedLocales = [
|
|
67
|
+
i18n.defaultLocale,
|
|
68
|
+
...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
|
|
69
|
+
];
|
|
70
|
+
const results = await (0, utils_2.mapAsyncSequential)(orderedLocales, (locale) => {
|
|
71
|
+
const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
|
|
72
|
+
return tryToBuildLocale({ locale, isLastLocale });
|
|
73
|
+
});
|
|
74
|
+
return results[0];
|
|
77
75
|
}
|
|
78
76
|
exports.default = build;
|
|
79
77
|
async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
|
|
@@ -93,7 +91,8 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
93
91
|
plugins: [
|
|
94
92
|
// Remove/clean build folders before building bundles.
|
|
95
93
|
new CleanWebpackPlugin_1.default({ verbose: false }),
|
|
96
|
-
// Visualize size of webpack output files with an interactive zoomable
|
|
94
|
+
// Visualize size of webpack output files with an interactive zoomable
|
|
95
|
+
// tree map.
|
|
97
96
|
cliOptions.bundleAnalyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
|
|
98
97
|
// Generate client manifests file that will be used for server bundle.
|
|
99
98
|
new react_loadable_ssr_addon_v5_slorber_1.default({
|
|
@@ -153,7 +152,6 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
153
152
|
if (!plugin.postBuild) {
|
|
154
153
|
return;
|
|
155
154
|
}
|
|
156
|
-
// The plugin may reference `this`. We manually bind it again to prevent any bugs.
|
|
157
155
|
await plugin.postBuild({ ...props, content: plugin.content });
|
|
158
156
|
}));
|
|
159
157
|
await (0, brokenLinks_1.handleBrokenLinks)({
|
package/lib/commands/deploy.js
CHANGED
|
@@ -114,8 +114,8 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
114
114
|
shelljs_1.default.echo('Skipping deploy on a pull request.');
|
|
115
115
|
shelljs_1.default.exit(0);
|
|
116
116
|
}
|
|
117
|
-
// github.io indicates organization repos that deploy via default branch.
|
|
118
|
-
// Organization deploys looks like:
|
|
117
|
+
// github.io indicates organization repos that deploy via default branch.
|
|
118
|
+
// All others use gh-pages. Organization deploys looks like:
|
|
119
119
|
// - Git repo: https://github.com/<organization>/<organization>.github.io
|
|
120
120
|
// - Site url: https://<organization>.github.io
|
|
121
121
|
const isGitHubPagesOrganizationDeploy = projectName.includes('.github.io');
|
|
@@ -196,7 +196,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
if (!cliOptions.skipBuild) {
|
|
199
|
-
// Build
|
|
199
|
+
// Build site, then push to deploymentBranch branch of specified repo.
|
|
200
200
|
try {
|
|
201
201
|
await runDeploy(await (0, build_1.default)(siteDir, cliOptions, false));
|
|
202
202
|
}
|
package/lib/commands/serve.js
CHANGED
|
@@ -44,8 +44,8 @@ async function serve(siteDir, cliOptions) {
|
|
|
44
44
|
res.end();
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
// Remove baseUrl before calling serveHandler
|
|
48
|
-
//
|
|
47
|
+
// Remove baseUrl before calling serveHandler, because /baseUrl/ should
|
|
48
|
+
// serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
|
49
49
|
req.url = (_b = req.url) === null || _b === void 0 ? void 0 : _b.replace(baseUrl, '/');
|
|
50
50
|
(0, serve_handler_1.default)(req, res, {
|
|
51
51
|
cleanUrls: true,
|
package/lib/commands/swizzle.js
CHANGED
|
@@ -185,7 +185,8 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
185
185
|
let score = formattedComponentName.length;
|
|
186
186
|
components.forEach((component) => {
|
|
187
187
|
if (component.toLowerCase() === formattedComponentName.toLowerCase()) {
|
|
188
|
-
// may be components with same lowercase key, try to match closest
|
|
188
|
+
// may be components with same lowercase key, try to match closest
|
|
189
|
+
// component
|
|
189
190
|
const currentScore = (0, leven_1.default)(formattedComponentName, component);
|
|
190
191
|
if (currentScore < score) {
|
|
191
192
|
score = currentScore;
|
|
@@ -202,7 +203,8 @@ async function swizzle(siteDir, themeName, componentName, typescript, danger) {
|
|
|
202
203
|
let fromPath = path_1.default.join(themePath, mostSuitableComponent);
|
|
203
204
|
let toPath = path_1.default.resolve(siteDir, utils_1.THEME_PATH, mostSuitableComponent);
|
|
204
205
|
// Handle single TypeScript/JavaScript file only.
|
|
205
|
-
// E.g: if <fromPath> does not exist, we try to swizzle
|
|
206
|
+
// E.g: if <fromPath> does not exist, we try to swizzle
|
|
207
|
+
// <fromPath>.(ts|tsx|js) instead
|
|
206
208
|
if (!fs_extra_1.default.existsSync(fromPath)) {
|
|
207
209
|
if (fs_extra_1.default.existsSync(`${fromPath}.ts`)) {
|
|
208
210
|
[fromPath, toPath] = [`${fromPath}.ts`, `${toPath}.ts`];
|
|
@@ -48,9 +48,7 @@ function transformMarkdownLine(line, slugger, options) {
|
|
|
48
48
|
if (line.startsWith('##')) {
|
|
49
49
|
return transformMarkdownHeadingLine(line, slugger, options);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
return line;
|
|
53
|
-
}
|
|
51
|
+
return line;
|
|
54
52
|
}
|
|
55
53
|
function transformMarkdownLines(lines, options) {
|
|
56
54
|
let inCode = false;
|
|
@@ -60,12 +58,10 @@ function transformMarkdownLines(lines, options) {
|
|
|
60
58
|
inCode = !inCode;
|
|
61
59
|
return line;
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return line;
|
|
66
|
-
}
|
|
67
|
-
return transformMarkdownLine(line, slugger, options);
|
|
61
|
+
if (inCode) {
|
|
62
|
+
return line;
|
|
68
63
|
}
|
|
64
|
+
return transformMarkdownLine(line, slugger, options);
|
|
69
65
|
});
|
|
70
66
|
}
|
|
71
67
|
function transformMarkdownContent(content, options) {
|
|
@@ -81,9 +77,12 @@ async function transformMarkdownFile(filepath, options) {
|
|
|
81
77
|
}
|
|
82
78
|
return undefined;
|
|
83
79
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
/**
|
|
81
|
+
* We only handle the "paths to watch" because these are the paths where the
|
|
82
|
+
* markdown files are. Also we don't want to transform the site md docs that do
|
|
83
|
+
* not belong to a content plugin. For example ./README.md should not be
|
|
84
|
+
* transformed
|
|
85
|
+
*/
|
|
87
86
|
async function getPathsToWatch(siteDir) {
|
|
88
87
|
const context = await (0, server_1.loadContext)(siteDir);
|
|
89
88
|
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
@@ -13,10 +13,13 @@ const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
|
13
13
|
const translations_1 = require("../server/translations/translations");
|
|
14
14
|
const translationsExtractor_1 = require("../server/translations/translationsExtractor");
|
|
15
15
|
const utils_1 = require("../webpack/utils");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
/**
|
|
17
|
+
* This is a hack, so that @docusaurus/theme-common translations are extracted!
|
|
18
|
+
* A theme doesn't have a way to express that one of its dependency (like
|
|
19
|
+
* @docusaurus/theme-common) also has translations to extract.
|
|
20
|
+
* Instead of introducing a new lifecycle (like `getThemeTranslationPaths()`?)
|
|
21
|
+
* We just make an exception and assume that user is using an official theme
|
|
22
|
+
*/
|
|
20
23
|
async function getExtraSourceCodeFilePaths() {
|
|
21
24
|
try {
|
|
22
25
|
const themeCommonSourceDir = path_1.default.dirname(require.resolve('@docusaurus/theme-common/lib'));
|
|
@@ -39,10 +39,12 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
|
|
|
39
39
|
}
|
|
40
40
|
return pageLinks.map(resolveLink).filter((l) => isBrokenLink(l.resolvedLink));
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The route defs can be recursive, and have a parent match-all route. We don't
|
|
44
|
+
* want to match broken links like /docs/brokenLink against /docs/*. For this
|
|
45
|
+
* reason, we only consider the "final routes", that do not have subroutes.
|
|
46
|
+
* We also need to remove the match all 404 route
|
|
47
|
+
*/
|
|
46
48
|
function filterIntermediateRoutes(routesInput) {
|
|
47
49
|
const routesWithout404 = routesInput.filter((route) => route.path !== '*');
|
|
48
50
|
return (0, utils_2.getAllFinalRoutes)(routesWithout404);
|
|
@@ -67,9 +69,11 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
67
69
|
.map(brokenLinkMessage)
|
|
68
70
|
.join('\n -> linking to ')}`;
|
|
69
71
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
/**
|
|
73
|
+
* If there's a broken link appearing very often, it is probably a broken link
|
|
74
|
+
* on the layout. Add an additional message in such case to help user figure
|
|
75
|
+
* this out. See https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
|
|
76
|
+
*/
|
|
73
77
|
function getLayoutBrokenLinksHelpMessage() {
|
|
74
78
|
const flatList = Object.entries(allBrokenLinks).flatMap(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink })));
|
|
75
79
|
const countedBrokenLinks = (0, lodash_1.countBy)(flatList, (item) => item.brokenLink.link);
|
|
@@ -121,8 +125,9 @@ async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, bas
|
|
|
121
125
|
if (onBrokenLinks === 'ignore') {
|
|
122
126
|
return;
|
|
123
127
|
}
|
|
124
|
-
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
125
|
-
//
|
|
128
|
+
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
129
|
+
// file system. It is not a broken link, it may simply be a link to an
|
|
130
|
+
// existing static file...
|
|
126
131
|
const allCollectedLinksFiltered = await filterExistingFileLinks({
|
|
127
132
|
allCollectedLinks,
|
|
128
133
|
baseUrl,
|
|
@@ -7,6 +7,6 @@
|
|
|
7
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' | 'staticDirectories'>;
|
|
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;
|
|
@@ -29,6 +29,7 @@ exports.DEFAULT_CONFIG = {
|
|
|
29
29
|
themeConfig: {},
|
|
30
30
|
titleDelimiter: '|',
|
|
31
31
|
noIndex: false,
|
|
32
|
+
tagline: '',
|
|
32
33
|
baseUrlIssueBanner: true,
|
|
33
34
|
staticDirectories: [utils_1.STATIC_DIR_NAME],
|
|
34
35
|
};
|
|
@@ -143,7 +144,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
143
144
|
type: utils_validation_1.Joi.string(),
|
|
144
145
|
}).unknown()),
|
|
145
146
|
clientModules: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()),
|
|
146
|
-
tagline: utils_validation_1.Joi.string().allow(''),
|
|
147
|
+
tagline: utils_validation_1.Joi.string().allow('').default(exports.DEFAULT_CONFIG.tagline),
|
|
147
148
|
titleDelimiter: utils_validation_1.Joi.string().default('|'),
|
|
148
149
|
noIndex: utils_validation_1.Joi.bool().default(false),
|
|
149
150
|
webpack: utils_validation_1.Joi.object({
|
|
@@ -16,10 +16,8 @@ function getAllDuplicateRoutes(pluginsRouteConfigs) {
|
|
|
16
16
|
if (Object.prototype.hasOwnProperty.call(seenRoutes, route)) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
19
|
+
seenRoutes[route] = true;
|
|
20
|
+
return false;
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
23
|
exports.getAllDuplicateRoutes = getAllDuplicateRoutes;
|
package/lib/server/i18n.js
CHANGED
|
@@ -61,22 +61,18 @@ function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
|
61
61
|
? // By default, we don't localize the path of defaultLocale
|
|
62
62
|
i18n.currentLocale !== i18n.defaultLocale
|
|
63
63
|
: options.localizePath;
|
|
64
|
-
if (shouldLocalizePath) {
|
|
65
|
-
// FS paths need special care, for Windows support
|
|
66
|
-
if (pathType === 'fs') {
|
|
67
|
-
return path_1.default.join(originalPath, path_1.default.sep, i18n.currentLocale, path_1.default.sep);
|
|
68
|
-
}
|
|
69
|
-
// Url paths
|
|
70
|
-
else if (pathType === 'url') {
|
|
71
|
-
return (0, utils_1.normalizeUrl)([originalPath, '/', i18n.currentLocale, '/']);
|
|
72
|
-
}
|
|
73
|
-
// should never happen
|
|
74
|
-
else {
|
|
75
|
-
throw new Error(`Unhandled path type "${pathType}".`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
64
|
+
if (!shouldLocalizePath) {
|
|
79
65
|
return originalPath;
|
|
80
66
|
}
|
|
67
|
+
// FS paths need special care, for Windows support
|
|
68
|
+
if (pathType === 'fs') {
|
|
69
|
+
return path_1.default.join(originalPath, path_1.default.sep, i18n.currentLocale, path_1.default.sep);
|
|
70
|
+
}
|
|
71
|
+
// Url paths
|
|
72
|
+
if (pathType === 'url') {
|
|
73
|
+
return (0, utils_1.normalizeUrl)([originalPath, '/', i18n.currentLocale, '/']);
|
|
74
|
+
}
|
|
75
|
+
// should never happen
|
|
76
|
+
throw new Error(`Unhandled path type "${pathType}".`);
|
|
81
77
|
}
|
|
82
78
|
exports.localizePath = localizePath;
|
package/lib/server/index.js
CHANGED
|
@@ -150,10 +150,12 @@ function createBootstrapPlugin({ siteConfig, }) {
|
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Configure Webpack fallback mdx loader for md/mdx files out of content-plugin
|
|
155
|
+
* folders. Adds a "fallback" mdx loader for mdx files that are not processed by
|
|
156
|
+
* content plugins. This allows to do things such as importing repo/README.md as
|
|
157
|
+
* a partial from another doc. Not ideal solution, but good enough for now
|
|
158
|
+
*/
|
|
157
159
|
function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
158
160
|
return {
|
|
159
161
|
name: 'docusaurus-mdx-fallback-plugin',
|
|
@@ -161,9 +163,9 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
|
|
|
161
163
|
options: {},
|
|
162
164
|
version: { type: 'synthetic' },
|
|
163
165
|
configureWebpack(config, isServer, { getJSLoader }) {
|
|
164
|
-
// We need the mdx fallback loader to exclude files that were already
|
|
165
|
-
// This works, but a bit
|
|
166
|
-
// Not sure there's a way to handle that differently in webpack
|
|
166
|
+
// We need the mdx fallback loader to exclude files that were already
|
|
167
|
+
// processed by content plugins mdx loaders. This works, but a bit
|
|
168
|
+
// hacky... Not sure there's a way to handle that differently in webpack
|
|
167
169
|
function getMDXFallbackExcludedPaths() {
|
|
168
170
|
var _a;
|
|
169
171
|
const rules = (_a = config === null || config === void 0 ? void 0 : config.module) === null || _a === void 0 ? void 0 : _a.rules;
|
|
@@ -57,9 +57,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
57
57
|
context,
|
|
58
58
|
});
|
|
59
59
|
// 2. Plugin Lifecycle - loadContent.
|
|
60
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
61
|
-
// We could change this in future if there are plugins which
|
|
62
|
-
// run in certain order or depend on others for data.
|
|
60
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
61
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
62
|
+
// need to run in certain order or depend on others for data.
|
|
63
63
|
const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
|
|
64
64
|
const content = plugin.loadContent ? await plugin.loadContent() : null;
|
|
65
65
|
return { ...plugin, content };
|
|
@@ -134,9 +134,9 @@ async function loadPlugins({ pluginConfigs, context, }) {
|
|
|
134
134
|
});
|
|
135
135
|
}));
|
|
136
136
|
// 4. Plugin Lifecycle - routesLoaded.
|
|
137
|
-
// Currently plugins run lifecycle methods in parallel and are not
|
|
138
|
-
// We could change this in future if there are plugins which
|
|
139
|
-
// run in certain order or depend on others for data.
|
|
137
|
+
// Currently plugins run lifecycle methods in parallel and are not
|
|
138
|
+
// order-dependent. We could change this in future if there are plugins which
|
|
139
|
+
// need to run in certain order or depend on others for data.
|
|
140
140
|
await Promise.all(contentLoadedTranslatedPlugins.map(async (plugin) => {
|
|
141
141
|
if (!plugin.routesLoaded) {
|
|
142
142
|
return null;
|