@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.16
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.mjs +280 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +32 -41
- 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 +5 -9
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +17 -23
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +14 -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 +36 -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 +15 -21
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +29 -17
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +15 -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 +4 -8
- 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 +59 -61
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +32 -21
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +115 -71
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +30 -16
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +100 -89
- 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 +57 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +165 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +77 -0
- package/lib/{client/exports → commands/swizzle}/context.d.ts +2 -4
- 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/commands/swizzle/tables.d.ts +9 -0
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +105 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +44 -46
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +36 -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 +38 -33
- 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 +10 -7
- package/lib/server/configValidation.d.ts +4 -2
- package/lib/server/configValidation.js +63 -32
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +8 -9
- package/lib/server/html-tags/index.d.ts +2 -2
- package/lib/server/html-tags/index.js +3 -3
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +31 -46
- package/lib/server/index.d.ts +9 -2
- package/lib/server/index.js +165 -87
- package/lib/server/loadSetup.d.ts +2 -3
- package/lib/server/loadSetup.js +5 -5
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
- package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
- package/lib/server/plugins/index.d.ts +3 -4
- package/lib/server/plugins/index.js +53 -37
- package/lib/server/plugins/init.d.ts +11 -5
- package/lib/server/plugins/init.js +40 -47
- package/lib/server/plugins/pluginIds.d.ts +2 -2
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +14 -14
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +51 -28
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +24 -15
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +36 -24
- package/lib/server/translations/translations.d.ts +10 -5
- package/lib/server/translations/translations.js +27 -35
- package/lib/server/translations/translationsExtractor.d.ts +9 -4
- package/lib/server/translations/translationsExtractor.js +160 -119
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +8 -10
- 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 +54 -38
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +15 -21
- 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 +10 -16
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +5 -6
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +18 -11
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
- package/lib/webpack/utils.d.ts +9 -30
- package/lib/webpack/utils.js +58 -171
- package/package.json +76 -69
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5732
- package/lib/client/.tsbuildinfo +0 -4171
- 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/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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type SwizzlePlugin } from './common';
|
|
8
|
+
export declare function pluginToThemeName(plugin: SwizzlePlugin): string | undefined;
|
|
9
|
+
export declare function getPluginByThemeName(plugins: SwizzlePlugin[], themeName: string): SwizzlePlugin;
|
|
10
|
+
export declare function getThemeNames(plugins: SwizzlePlugin[]): string[];
|
|
11
|
+
export declare function getThemeName({ themeNameParam, themeNames, list, }: {
|
|
12
|
+
themeNameParam: string | undefined;
|
|
13
|
+
themeNames: string[];
|
|
14
|
+
list: boolean | undefined;
|
|
15
|
+
}): Promise<string>;
|
|
16
|
+
export declare function getThemePath({ plugins, themeName, typescript, }: {
|
|
17
|
+
plugins: SwizzlePlugin[];
|
|
18
|
+
themeName: string;
|
|
19
|
+
typescript: boolean | undefined;
|
|
20
|
+
}): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
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.getThemePath = exports.getThemeName = exports.getThemeNames = exports.getPluginByThemeName = exports.pluginToThemeName = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
|
+
const leven_1 = (0, tslib_1.__importDefault)(require("leven"));
|
|
13
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
14
|
+
const prompts_1 = require("./prompts");
|
|
15
|
+
const common_1 = require("./common");
|
|
16
|
+
function pluginToThemeName(plugin) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (plugin.instance.getThemePath) {
|
|
19
|
+
return ((_a = plugin.instance.version.name) !== null && _a !== void 0 ? _a : plugin.instance.name);
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
exports.pluginToThemeName = pluginToThemeName;
|
|
24
|
+
function getPluginByThemeName(plugins, themeName) {
|
|
25
|
+
const plugin = plugins.find((p) => pluginToThemeName(p) === themeName);
|
|
26
|
+
if (!plugin) {
|
|
27
|
+
throw new Error(`Theme ${themeName} not found`);
|
|
28
|
+
}
|
|
29
|
+
return plugin;
|
|
30
|
+
}
|
|
31
|
+
exports.getPluginByThemeName = getPluginByThemeName;
|
|
32
|
+
function getThemeNames(plugins) {
|
|
33
|
+
const themeNames = lodash_1.default.uniq(
|
|
34
|
+
// The fact that getThemePath is attached to the plugin instance makes
|
|
35
|
+
// this code impossible to optimize. If this is a static method, we don't
|
|
36
|
+
// need to initialize all plugins just to filter which are themes
|
|
37
|
+
// Benchmark: loadContext-58ms; initPlugins-323ms
|
|
38
|
+
plugins.map((plugin) => pluginToThemeName(plugin)).filter(Boolean));
|
|
39
|
+
// Opinionated ordering: user is most likely to swizzle:
|
|
40
|
+
// - the classic theme
|
|
41
|
+
// - official themes
|
|
42
|
+
// - official plugins
|
|
43
|
+
return lodash_1.default.orderBy(themeNames, [
|
|
44
|
+
(t) => t === '@docusaurus/theme-classic',
|
|
45
|
+
(t) => t.includes('@docusaurus/theme'),
|
|
46
|
+
(t) => t.includes('@docusaurus'),
|
|
47
|
+
], ['desc', 'desc', 'desc']);
|
|
48
|
+
}
|
|
49
|
+
exports.getThemeNames = getThemeNames;
|
|
50
|
+
// Returns a valid value if recovering is possible
|
|
51
|
+
function handleInvalidThemeName({ themeNameParam, themeNames, }) {
|
|
52
|
+
// Trying to recover invalid value
|
|
53
|
+
// We look for potential matches that only differ in casing.
|
|
54
|
+
const differentCaseMatch = (0, common_1.findStringIgnoringCase)(themeNameParam, themeNames);
|
|
55
|
+
if (differentCaseMatch) {
|
|
56
|
+
logger_1.default.warn `Theme name=${themeNameParam} doesn't exist.`;
|
|
57
|
+
logger_1.default.info `name=${differentCaseMatch} will be used instead of name=${themeNameParam}.`;
|
|
58
|
+
return differentCaseMatch;
|
|
59
|
+
}
|
|
60
|
+
// TODO recover from short theme-names here: "classic" => "@docusaurus/theme-classic"
|
|
61
|
+
// No recovery value is possible: print error
|
|
62
|
+
const suggestion = themeNames.find((name) => (0, leven_1.default)(name, themeNameParam) < 4);
|
|
63
|
+
logger_1.default.error `Theme name=${themeNameParam} not found. ${suggestion
|
|
64
|
+
? logger_1.default.interpolate `Did you mean name=${suggestion}?`
|
|
65
|
+
: logger_1.default.interpolate `Themes available for swizzle: ${themeNames}`}`;
|
|
66
|
+
return process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
async function validateThemeName({ themeNameParam, themeNames, }) {
|
|
69
|
+
const isValidName = themeNames.includes(themeNameParam);
|
|
70
|
+
if (!isValidName) {
|
|
71
|
+
return handleInvalidThemeName({
|
|
72
|
+
themeNameParam,
|
|
73
|
+
themeNames,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return themeNameParam;
|
|
77
|
+
}
|
|
78
|
+
async function getThemeName({ themeNameParam, themeNames, list, }) {
|
|
79
|
+
if (list && !themeNameParam) {
|
|
80
|
+
logger_1.default.info `Themes available for swizzle: name=${themeNames}`;
|
|
81
|
+
return process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
return themeNameParam
|
|
84
|
+
? validateThemeName({ themeNameParam, themeNames })
|
|
85
|
+
: (0, prompts_1.askThemeName)(themeNames);
|
|
86
|
+
}
|
|
87
|
+
exports.getThemeName = getThemeName;
|
|
88
|
+
function getThemePath({ plugins, themeName, typescript, }) {
|
|
89
|
+
var _a, _b, _c, _d;
|
|
90
|
+
const pluginInstance = getPluginByThemeName(plugins, themeName);
|
|
91
|
+
const themePath = typescript
|
|
92
|
+
? (_b = (_a = pluginInstance.instance).getTypeScriptThemePath) === null || _b === void 0 ? void 0 : _b.call(_a)
|
|
93
|
+
: (_d = (_c = pluginInstance.instance).getThemePath) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
94
|
+
if (!themePath) {
|
|
95
|
+
logger_1.default.warn(typescript
|
|
96
|
+
? logger_1.default.interpolate `name=${themeName} does not provide TypeScript theme code via ${'getTypeScriptThemePath()'}.`
|
|
97
|
+
: // This is... technically possible to happen, e.g. returning undefined
|
|
98
|
+
// from getThemePath. Plugins may intentionally or unintentionally
|
|
99
|
+
// disguise as themes?
|
|
100
|
+
logger_1.default.interpolate `name=${themeName} does not provide any theme code.`);
|
|
101
|
+
return process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
return themePath;
|
|
104
|
+
}
|
|
105
|
+
exports.getThemePath = getThemePath;
|
|
@@ -4,9 +4,12 @@
|
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
7
|
+
import { type Slugger } from '@docusaurus/utils';
|
|
8
|
+
declare type Options = {
|
|
9
|
+
maintainCase?: boolean;
|
|
10
|
+
overwrite?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function transformMarkdownHeadingLine(line: string, slugger: Slugger, options?: Options): string;
|
|
13
|
+
export declare function transformMarkdownContent(content: string, options?: Options): string;
|
|
14
|
+
export default function writeHeadingIds(siteDir: string, files?: string[], options?: Options): Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -6,105 +6,103 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.transformMarkdownContent = exports.
|
|
9
|
+
exports.transformMarkdownContent = exports.transformMarkdownHeadingLine = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
-
const
|
|
13
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
11
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
14
13
|
const server_1 = require("../server");
|
|
15
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
16
|
-
const lodash_1 = require("lodash");
|
|
14
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
17
15
|
const utils_1 = require("@docusaurus/utils");
|
|
18
16
|
const utils_2 = require("../server/utils");
|
|
19
17
|
function unwrapMarkdownLinks(line) {
|
|
20
|
-
return line.replace(/\[([^\]]+)\]\([^)]+\)/g, (match, p1) => p1);
|
|
18
|
+
return line.replace(/\[(?<alt>[^\]]+)\]\([^)]+\)/g, (match, p1) => p1);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
function addHeadingId(line, slugger) {
|
|
20
|
+
function addHeadingId(line, slugger, maintainCase) {
|
|
24
21
|
let headingLevel = 0;
|
|
25
22
|
while (line.charAt(headingLevel) === '#') {
|
|
26
23
|
headingLevel += 1;
|
|
27
24
|
}
|
|
28
25
|
const headingText = line.slice(headingLevel).trimEnd();
|
|
29
26
|
const headingHashes = line.slice(0, headingLevel);
|
|
30
|
-
const slug = slugger
|
|
27
|
+
const slug = slugger
|
|
28
|
+
.slug(unwrapMarkdownLinks(headingText).trim(), { maintainCase })
|
|
29
|
+
.replace(/^-+/, '')
|
|
30
|
+
.replace(/-+$/, '');
|
|
31
31
|
return `${headingHashes}${headingText} {#${slug}}`;
|
|
32
32
|
}
|
|
33
|
-
function transformMarkdownHeadingLine(line, slugger) {
|
|
33
|
+
function transformMarkdownHeadingLine(line, slugger, options = { maintainCase: false, overwrite: false }) {
|
|
34
|
+
const { maintainCase = false, overwrite = false } = options;
|
|
34
35
|
if (!line.startsWith('#')) {
|
|
35
|
-
throw new Error(`Line is not a
|
|
36
|
+
throw new Error(`Line is not a Markdown heading: ${line}.`);
|
|
36
37
|
}
|
|
37
|
-
const parsedHeading = utils_1.parseMarkdownHeadingId(line);
|
|
38
|
-
// Do not process if id is already
|
|
39
|
-
if (parsedHeading.id) {
|
|
38
|
+
const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(line);
|
|
39
|
+
// Do not process if id is already there
|
|
40
|
+
if (parsedHeading.id && !overwrite) {
|
|
40
41
|
return line;
|
|
41
42
|
}
|
|
42
|
-
return addHeadingId(
|
|
43
|
+
return addHeadingId(parsedHeading.text, slugger, maintainCase);
|
|
43
44
|
}
|
|
44
45
|
exports.transformMarkdownHeadingLine = transformMarkdownHeadingLine;
|
|
45
|
-
function transformMarkdownLine(line, slugger) {
|
|
46
|
+
function transformMarkdownLine(line, slugger, options) {
|
|
46
47
|
// Ignore h1 headings on purpose, as we don't create anchor links for those
|
|
47
48
|
if (line.startsWith('##')) {
|
|
48
|
-
return transformMarkdownHeadingLine(line, slugger);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return line;
|
|
49
|
+
return transformMarkdownHeadingLine(line, slugger, options);
|
|
52
50
|
}
|
|
51
|
+
return line;
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
function transformMarkdownLines(lines) {
|
|
53
|
+
function transformMarkdownLines(lines, options) {
|
|
56
54
|
let inCode = false;
|
|
57
|
-
const slugger =
|
|
55
|
+
const slugger = (0, utils_1.createSlugger)();
|
|
58
56
|
return lines.map((line) => {
|
|
59
57
|
if (line.startsWith('```')) {
|
|
60
58
|
inCode = !inCode;
|
|
61
59
|
return line;
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return line;
|
|
66
|
-
}
|
|
67
|
-
return transformMarkdownLine(line, slugger);
|
|
61
|
+
if (inCode) {
|
|
62
|
+
return line;
|
|
68
63
|
}
|
|
64
|
+
return transformMarkdownLine(line, slugger, options);
|
|
69
65
|
});
|
|
70
66
|
}
|
|
71
|
-
function transformMarkdownContent(content) {
|
|
72
|
-
return transformMarkdownLines(content.split('\n')).join('\n');
|
|
67
|
+
function transformMarkdownContent(content, options) {
|
|
68
|
+
return transformMarkdownLines(content.split('\n'), options).join('\n');
|
|
73
69
|
}
|
|
74
70
|
exports.transformMarkdownContent = transformMarkdownContent;
|
|
75
|
-
async function transformMarkdownFile(filepath) {
|
|
71
|
+
async function transformMarkdownFile(filepath, options) {
|
|
76
72
|
const content = await fs_extra_1.default.readFile(filepath, 'utf8');
|
|
77
|
-
const updatedContent = transformMarkdownLines(content.split('\n')).join('\n');
|
|
73
|
+
const updatedContent = transformMarkdownLines(content.split('\n'), options).join('\n');
|
|
78
74
|
if (content !== updatedContent) {
|
|
79
75
|
await fs_extra_1.default.writeFile(filepath, updatedContent);
|
|
80
76
|
return filepath;
|
|
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
|
-
const context = await server_1.loadContext(siteDir);
|
|
89
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
90
|
-
const plugins = await init_1.default({
|
|
87
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
88
|
+
const pluginConfigs = await (0, server_1.loadPluginConfigs)(context);
|
|
89
|
+
const plugins = await (0, init_1.default)({
|
|
91
90
|
pluginConfigs,
|
|
92
91
|
context,
|
|
93
92
|
});
|
|
94
|
-
return
|
|
93
|
+
return plugins.flatMap((plugin) => { var _a, _b; return (_b = (_a = plugin === null || plugin === void 0 ? void 0 : plugin.getPathsToWatch) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : []; });
|
|
95
94
|
}
|
|
96
|
-
async function writeHeadingIds(siteDir) {
|
|
97
|
-
const markdownFiles = await utils_2.safeGlobby(await getPathsToWatch(siteDir), {
|
|
95
|
+
async function writeHeadingIds(siteDir, files, options) {
|
|
96
|
+
const markdownFiles = await (0, utils_2.safeGlobby)(files !== null && files !== void 0 ? files : (await getPathsToWatch(siteDir)), {
|
|
98
97
|
expandDirectories: ['**/*.{md,mdx}'],
|
|
99
98
|
});
|
|
100
|
-
const result = await Promise.all(markdownFiles.map(transformMarkdownFile));
|
|
99
|
+
const result = await Promise.all(markdownFiles.map((p) => transformMarkdownFile(p, options)));
|
|
101
100
|
const pathsModified = result.filter(Boolean);
|
|
102
101
|
if (pathsModified.length) {
|
|
103
|
-
|
|
104
|
-
- ${pathsModified.join('\n- ')}`));
|
|
102
|
+
logger_1.default.success `Heading ids added to Markdown files (number=${`${pathsModified.length}/${markdownFiles.length}`} files): ${pathsModified}`;
|
|
105
103
|
}
|
|
106
104
|
else {
|
|
107
|
-
|
|
105
|
+
logger_1.default.warn `number=${markdownFiles.length} Markdown files already have explicit heading IDs. If you intend to overwrite the existing heading IDs, use the code=${'--overwrite'} option.`;
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
exports.default = writeHeadingIds;
|
|
@@ -4,8 +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 { ConfigOptions } from '@docusaurus/types';
|
|
8
|
-
import { WriteTranslationsOptions } from '../server/translations/translations';
|
|
7
|
+
import type { ConfigOptions } from '@docusaurus/types';
|
|
8
|
+
import { type WriteTranslationsOptions } from '../server/translations/translations';
|
|
9
9
|
export default function writeTranslations(siteDir: string, options: WriteTranslationsOptions & ConfigOptions & {
|
|
10
10
|
locale?: string;
|
|
11
11
|
}): Promise<void>;
|
|
@@ -1,11 +1,34 @@
|
|
|
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
|
const tslib_1 = require("tslib");
|
|
10
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
4
11
|
const server_1 = require("../server");
|
|
5
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
12
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
6
13
|
const translations_1 = require("../server/translations/translations");
|
|
7
14
|
const translationsExtractor_1 = require("../server/translations/translationsExtractor");
|
|
8
15
|
const utils_1 = require("../webpack/utils");
|
|
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
|
+
*/
|
|
23
|
+
async function getExtraSourceCodeFilePaths() {
|
|
24
|
+
try {
|
|
25
|
+
const themeCommonSourceDir = path_1.default.dirname(require.resolve('@docusaurus/theme-common/lib'));
|
|
26
|
+
return (0, translationsExtractor_1.globSourceCodeFilePaths)([themeCommonSourceDir]);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
|
30
|
+
}
|
|
31
|
+
}
|
|
9
32
|
async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }) {
|
|
10
33
|
var _a;
|
|
11
34
|
if (plugin.getTranslationFiles) {
|
|
@@ -14,7 +37,7 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
14
37
|
content,
|
|
15
38
|
});
|
|
16
39
|
await Promise.all(translationFiles.map(async (translationFile) => {
|
|
17
|
-
await translations_1.writePluginTranslations({
|
|
40
|
+
await (0, translations_1.writePluginTranslations)({
|
|
18
41
|
siteDir,
|
|
19
42
|
plugin,
|
|
20
43
|
translationFile,
|
|
@@ -26,32 +49,31 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
26
49
|
}
|
|
27
50
|
async function writeTranslations(siteDir, options) {
|
|
28
51
|
var _a;
|
|
29
|
-
const context = await server_1.loadContext(siteDir, {
|
|
52
|
+
const context = await (0, server_1.loadContext)(siteDir, {
|
|
30
53
|
customConfigFilePath: options.config,
|
|
31
54
|
locale: options.locale,
|
|
32
55
|
});
|
|
33
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
34
|
-
const plugins = init_1.default({
|
|
56
|
+
const pluginConfigs = await (0, server_1.loadPluginConfigs)(context);
|
|
57
|
+
const plugins = await (0, init_1.default)({
|
|
35
58
|
pluginConfigs,
|
|
36
59
|
context,
|
|
37
60
|
});
|
|
38
61
|
const locale = (_a = options.locale) !== null && _a !== void 0 ? _a : context.i18n.defaultLocale;
|
|
39
62
|
if (!context.i18n.locales.includes(locale)) {
|
|
40
|
-
throw new Error(`Can't write-translation for locale that is not in the locale configuration file.
|
|
41
|
-
|
|
42
|
-
Available locales=[${context.i18n.locales.join(',')}]`);
|
|
63
|
+
throw new Error(`Can't write-translation for locale "${locale}" that is not in the locale configuration file.
|
|
64
|
+
Available locales are: ${context.i18n.locales.join(',')}.`);
|
|
43
65
|
}
|
|
44
|
-
const babelOptions = utils_1.getBabelOptions({
|
|
66
|
+
const babelOptions = (0, utils_1.getBabelOptions)({
|
|
45
67
|
isServer: true,
|
|
46
|
-
babelOptions: utils_1.getCustomBabelConfigFilePath(siteDir),
|
|
68
|
+
babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
|
|
47
69
|
});
|
|
48
|
-
const extractedCodeTranslations = await translationsExtractor_1.extractSiteSourceCodeTranslations(siteDir, plugins, babelOptions);
|
|
49
|
-
const defaultCodeMessages = await translations_1.getPluginsDefaultCodeTranslationMessages(plugins);
|
|
50
|
-
const codeTranslations = translations_1.applyDefaultCodeTranslations({
|
|
70
|
+
const extractedCodeTranslations = await (0, translationsExtractor_1.extractSiteSourceCodeTranslations)(siteDir, plugins, babelOptions, await getExtraSourceCodeFilePaths());
|
|
71
|
+
const defaultCodeMessages = await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins);
|
|
72
|
+
const codeTranslations = (0, translations_1.applyDefaultCodeTranslations)({
|
|
51
73
|
extractedCodeTranslations,
|
|
52
74
|
defaultCodeMessages,
|
|
53
75
|
});
|
|
54
|
-
await translations_1.writeCodeTranslations({ siteDir, locale }, codeTranslations, options);
|
|
76
|
+
await (0, translations_1.writeCodeTranslations)({ siteDir, locale }, codeTranslations, options);
|
|
55
77
|
await Promise.all(plugins.map(async (plugin) => {
|
|
56
78
|
await writePluginTranslationFiles({ siteDir, plugin, locale, options });
|
|
57
79
|
}));
|
package/lib/index.d.ts
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
import build from './commands/build';
|
|
8
|
+
import clear from './commands/clear';
|
|
9
|
+
import deploy from './commands/deploy';
|
|
10
|
+
import externalCommand from './commands/external';
|
|
11
|
+
import serve from './commands/serve';
|
|
12
|
+
import start from './commands/start';
|
|
13
|
+
import swizzle from './commands/swizzle';
|
|
14
|
+
import writeHeadingIds from './commands/writeHeadingIds';
|
|
15
|
+
import writeTranslations from './commands/writeTranslations';
|
|
16
|
+
export { build, clear, deploy, externalCommand, serve, start, swizzle, writeHeadingIds, writeTranslations, };
|
package/lib/index.js
CHANGED
|
@@ -6,22 +6,23 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
exports.writeTranslations = exports.writeHeadingIds = exports.swizzle = exports.start = exports.serve = exports.externalCommand = exports.deploy = exports.clear = exports.build = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const build_1 = (0, tslib_1.__importDefault)(require("./commands/build"));
|
|
12
|
+
exports.build = build_1.default;
|
|
13
|
+
const clear_1 = (0, tslib_1.__importDefault)(require("./commands/clear"));
|
|
14
|
+
exports.clear = clear_1.default;
|
|
15
|
+
const deploy_1 = (0, tslib_1.__importDefault)(require("./commands/deploy"));
|
|
16
|
+
exports.deploy = deploy_1.default;
|
|
17
|
+
const external_1 = (0, tslib_1.__importDefault)(require("./commands/external"));
|
|
18
|
+
exports.externalCommand = external_1.default;
|
|
19
|
+
const serve_1 = (0, tslib_1.__importDefault)(require("./commands/serve"));
|
|
20
|
+
exports.serve = serve_1.default;
|
|
21
|
+
const start_1 = (0, tslib_1.__importDefault)(require("./commands/start"));
|
|
22
|
+
exports.start = start_1.default;
|
|
23
|
+
const swizzle_1 = (0, tslib_1.__importDefault)(require("./commands/swizzle"));
|
|
24
|
+
exports.swizzle = swizzle_1.default;
|
|
25
|
+
const writeHeadingIds_1 = (0, tslib_1.__importDefault)(require("./commands/writeHeadingIds"));
|
|
26
|
+
exports.writeHeadingIds = writeHeadingIds_1.default;
|
|
27
|
+
const writeTranslations_1 = (0, tslib_1.__importDefault)(require("./commands/writeTranslations"));
|
|
28
|
+
exports.writeTranslations = writeTranslations_1.default;
|
|
@@ -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 { RouteConfig, ReportingSeverity } from '@docusaurus/types';
|
|
7
|
+
import type { RouteConfig, ReportingSeverity } from '@docusaurus/types';
|
|
8
8
|
declare type BrokenLink = {
|
|
9
9
|
link: string;
|
|
10
10
|
resolvedLink: string;
|
|
@@ -9,12 +9,12 @@ 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
|
|
13
|
-
const
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
15
14
|
const utils_1 = require("@docusaurus/utils");
|
|
16
15
|
const utils_2 = require("./utils");
|
|
17
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
17
|
+
const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
|
|
18
18
|
function toReactRouterRoutes(routes) {
|
|
19
19
|
// @ts-expect-error: types incompatible???
|
|
20
20
|
return routes;
|
|
@@ -29,32 +29,32 @@ function getPageBrokenLinks({ pagePath, pageLinks, routes, }) {
|
|
|
29
29
|
// we must resolve the links before using matchRoutes
|
|
30
30
|
// resolvePathname is used internally by ReactRouter
|
|
31
31
|
function resolveLink(link) {
|
|
32
|
-
const resolvedLink =
|
|
32
|
+
const resolvedLink = (0, utils_1.resolvePathname)(onlyPathname(link), pagePath);
|
|
33
33
|
return { link, resolvedLink };
|
|
34
34
|
}
|
|
35
35
|
function isBrokenLink(link) {
|
|
36
36
|
const matchedRoutes = [link, decodeURI(link)]
|
|
37
|
-
.map((l) => react_router_config_1.matchRoutes(toReactRouterRoutes(routes), l))
|
|
37
|
+
.map((l) => (0, react_router_config_1.matchRoutes)(toReactRouterRoutes(routes), l))
|
|
38
38
|
.reduce((prev, cur) => prev.concat(cur));
|
|
39
39
|
return matchedRoutes.length === 0;
|
|
40
40
|
}
|
|
41
41
|
return pageLinks.map(resolveLink).filter((l) => isBrokenLink(l.resolvedLink));
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
/**
|
|
44
|
+
* The route defs can be recursive, and have a parent match-all route. We don't
|
|
45
|
+
* want to match broken links like /docs/brokenLink against /docs/*. For this
|
|
46
|
+
* reason, we only consider the "final routes", that do not have subroutes.
|
|
47
|
+
* We also need to remove the match all 404 route
|
|
48
|
+
*/
|
|
47
49
|
function filterIntermediateRoutes(routesInput) {
|
|
48
50
|
const routesWithout404 = routesInput.filter((route) => route.path !== '*');
|
|
49
|
-
return utils_2.getAllFinalRoutes(routesWithout404);
|
|
51
|
+
return (0, utils_2.getAllFinalRoutes)(routesWithout404);
|
|
50
52
|
}
|
|
51
53
|
function getAllBrokenLinks({ allCollectedLinks, routes, }) {
|
|
52
54
|
const filteredRoutes = filterIntermediateRoutes(routes);
|
|
53
|
-
const allBrokenLinks = lodash_1.mapValues(allCollectedLinks, (pageLinks, pagePath) => {
|
|
54
|
-
return getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes });
|
|
55
|
-
});
|
|
55
|
+
const allBrokenLinks = lodash_1.default.mapValues(allCollectedLinks, (pageLinks, pagePath) => getPageBrokenLinks({ pageLinks, pagePath, routes: filteredRoutes }));
|
|
56
56
|
// remove pages without any broken link
|
|
57
|
-
return lodash_1.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
57
|
+
return lodash_1.default.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
|
58
58
|
}
|
|
59
59
|
exports.getAllBrokenLinks = getAllBrokenLinks;
|
|
60
60
|
function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
@@ -70,12 +70,14 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
70
70
|
.map(brokenLinkMessage)
|
|
71
71
|
.join('\n -> linking to ')}`;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
/**
|
|
74
|
+
* If there's a broken link appearing very often, it is probably a broken link
|
|
75
|
+
* on the layout. Add an additional message in such case to help user figure
|
|
76
|
+
* this out. See https://github.com/facebook/docusaurus/issues/3567#issuecomment-706973805
|
|
77
|
+
*/
|
|
76
78
|
function getLayoutBrokenLinksHelpMessage() {
|
|
77
|
-
const flatList =
|
|
78
|
-
const countedBrokenLinks = lodash_1.countBy(flatList, (item) => item.brokenLink.link);
|
|
79
|
+
const flatList = Object.entries(allBrokenLinks).flatMap(([pagePage, brokenLinks]) => brokenLinks.map((brokenLink) => ({ pagePage, brokenLink })));
|
|
80
|
+
const countedBrokenLinks = lodash_1.default.countBy(flatList, (item) => item.brokenLink.link);
|
|
79
81
|
const FrequencyThreshold = 5; // Is this a good value?
|
|
80
82
|
const frequentLinks = Object.entries(countedBrokenLinks)
|
|
81
83
|
.filter(([, count]) => count >= FrequencyThreshold)
|
|
@@ -92,21 +94,20 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
|
|
|
92
94
|
`);
|
|
93
95
|
}
|
|
94
96
|
exports.getBrokenLinksErrorMessage = getBrokenLinksErrorMessage;
|
|
95
|
-
function isExistingFile(filePath) {
|
|
97
|
+
async function isExistingFile(filePath) {
|
|
96
98
|
try {
|
|
97
|
-
return fs_extra_1.default.
|
|
99
|
+
return (await fs_extra_1.default.stat(filePath)).isFile();
|
|
98
100
|
}
|
|
99
|
-
catch
|
|
101
|
+
catch {
|
|
100
102
|
return false;
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
// If a file actually exist on the file system, we know the link is valid
|
|
104
106
|
// even if docusaurus does not know about this file, so we don't report it
|
|
105
107
|
async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, }) {
|
|
106
|
-
|
|
107
|
-
function linkFileExists(link) {
|
|
108
|
+
async function linkFileExists(link) {
|
|
108
109
|
// /baseUrl/javadoc/ -> /outDir/javadoc
|
|
109
|
-
const baseFilePath = utils_1.removeSuffix(`${outDir}/${utils_1.removePrefix(link, baseUrl)}`, '/');
|
|
110
|
+
const baseFilePath = (0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/');
|
|
110
111
|
// -> /outDir/javadoc
|
|
111
112
|
// -> /outDir/javadoc.html
|
|
112
113
|
// -> /outDir/javadoc/index.html
|
|
@@ -115,19 +116,23 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
|
|
|
115
116
|
filePathsToTry.push(`${baseFilePath}.html`);
|
|
116
117
|
filePathsToTry.push(path_1.default.join(baseFilePath, 'index.html'));
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
+
for (const file of filePathsToTry) {
|
|
120
|
+
if (await isExistingFile(file)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
119
125
|
}
|
|
120
|
-
return lodash_1.mapValues(allCollectedLinks, (links) =>
|
|
121
|
-
return links.filter((link) => !linkFileExists(link));
|
|
122
|
-
});
|
|
126
|
+
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
127
|
}
|
|
124
128
|
exports.filterExistingFileLinks = filterExistingFileLinks;
|
|
125
129
|
async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, baseUrl, outDir, }) {
|
|
126
130
|
if (onBrokenLinks === 'ignore') {
|
|
127
131
|
return;
|
|
128
132
|
}
|
|
129
|
-
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
130
|
-
//
|
|
133
|
+
// If we link to a file like /myFile.zip, and the file actually exist for the
|
|
134
|
+
// file system. It is not a broken link, it may simply be a link to an
|
|
135
|
+
// existing static file...
|
|
131
136
|
const allCollectedLinksFiltered = await filterExistingFileLinks({
|
|
132
137
|
allCollectedLinks,
|
|
133
138
|
baseUrl,
|
|
@@ -139,7 +144,7 @@ async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, bas
|
|
|
139
144
|
});
|
|
140
145
|
const errorMessage = getBrokenLinksErrorMessage(allBrokenLinks);
|
|
141
146
|
if (errorMessage) {
|
|
142
|
-
utils_1.reportMessage(errorMessage, onBrokenLinks);
|
|
147
|
+
(0, utils_1.reportMessage)(errorMessage, onBrokenLinks);
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
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[];
|