@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +29 -38
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +19 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +5 -9
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +13 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +1 -1
- package/lib/client/exports/Interpolate.js +16 -22
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +24 -19
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +14 -10
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +22 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/docusaurusContext.d.ts +12 -0
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +3 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/flat.d.ts +2 -2
- package/lib/client/flat.js +8 -11
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -3
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +39 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -7
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +6 -6
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +102 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +3 -3
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +13 -19
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +93 -83
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +103 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +41 -43
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +35 -14
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +1 -1
- package/lib/server/brokenLinks.js +57 -38
- package/lib/server/client-modules/index.d.ts +1 -1
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +7 -4
- package/lib/server/configValidation.d.ts +2 -2
- package/lib/server/configValidation.js +43 -28
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +2 -4
- package/lib/server/html-tags/index.d.ts +1 -1
- package/lib/server/html-tags/index.js +1 -1
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +32 -46
- package/lib/server/index.d.ts +2 -2
- package/lib/server/index.js +147 -68
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +2 -2
- package/lib/server/plugins/index.js +34 -35
- package/lib/server/plugins/init.d.ts +12 -2
- package/lib/server/plugins/init.js +48 -58
- package/lib/server/plugins/pluginIds.d.ts +1 -1
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +12 -13
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +50 -29
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +22 -14
- package/lib/server/themes/index.d.ts +3 -3
- package/lib/server/themes/index.js +26 -26
- package/lib/server/translations/translations.d.ts +7 -1
- package/lib/server/translations/translations.js +30 -45
- package/lib/server/translations/translationsExtractor.d.ts +9 -3
- package/lib/server/translations/translationsExtractor.js +159 -120
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +4 -4
- package/lib/webpack/base.js +38 -33
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +9 -8
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +7 -29
- package/lib/webpack/utils.js +54 -171
- package/package.json +74 -69
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -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,103 @@
|
|
|
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 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const leven_1 = tslib_1.__importDefault(require("leven"));
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const prompts_1 = require("./prompts");
|
|
15
|
+
const common_1 = require("./common");
|
|
16
|
+
function pluginToThemeName(plugin) {
|
|
17
|
+
if (plugin.instance.getThemePath) {
|
|
18
|
+
return (plugin.instance.version.name ?? plugin.instance.name);
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
exports.pluginToThemeName = pluginToThemeName;
|
|
23
|
+
function getPluginByThemeName(plugins, themeName) {
|
|
24
|
+
const plugin = plugins.find((p) => pluginToThemeName(p) === themeName);
|
|
25
|
+
if (!plugin) {
|
|
26
|
+
throw new Error(`Theme ${themeName} not found`);
|
|
27
|
+
}
|
|
28
|
+
return plugin;
|
|
29
|
+
}
|
|
30
|
+
exports.getPluginByThemeName = getPluginByThemeName;
|
|
31
|
+
function getThemeNames(plugins) {
|
|
32
|
+
const themeNames = lodash_1.default.uniq(
|
|
33
|
+
// The fact that getThemePath is attached to the plugin instance makes
|
|
34
|
+
// this code impossible to optimize. If this is a static method, we don't
|
|
35
|
+
// need to initialize all plugins just to filter which are themes
|
|
36
|
+
// Benchmark: loadContext-58ms; initPlugins-323ms
|
|
37
|
+
plugins.map((plugin) => pluginToThemeName(plugin)).filter(Boolean));
|
|
38
|
+
// Opinionated ordering: user is most likely to swizzle:
|
|
39
|
+
// - the classic theme
|
|
40
|
+
// - official themes
|
|
41
|
+
// - official plugins
|
|
42
|
+
return lodash_1.default.orderBy(themeNames, [
|
|
43
|
+
(t) => t === '@docusaurus/theme-classic',
|
|
44
|
+
(t) => t.includes('@docusaurus/theme'),
|
|
45
|
+
(t) => t.includes('@docusaurus'),
|
|
46
|
+
], ['desc', 'desc', 'desc']);
|
|
47
|
+
}
|
|
48
|
+
exports.getThemeNames = getThemeNames;
|
|
49
|
+
// Returns a valid value if recovering is possible
|
|
50
|
+
function handleInvalidThemeName({ themeNameParam, themeNames, }) {
|
|
51
|
+
// Trying to recover invalid value
|
|
52
|
+
// We look for potential matches that only differ in casing.
|
|
53
|
+
const differentCaseMatch = (0, common_1.findStringIgnoringCase)(themeNameParam, themeNames);
|
|
54
|
+
if (differentCaseMatch) {
|
|
55
|
+
logger_1.default.warn `Theme name=${themeNameParam} doesn't exist.`;
|
|
56
|
+
logger_1.default.info `name=${differentCaseMatch} will be used instead of name=${themeNameParam}.`;
|
|
57
|
+
return differentCaseMatch;
|
|
58
|
+
}
|
|
59
|
+
// TODO recover from short theme-names here: "classic" => "@docusaurus/theme-classic"
|
|
60
|
+
// No recovery value is possible: print error
|
|
61
|
+
const suggestion = themeNames.find((name) => (0, leven_1.default)(name, themeNameParam) < 4);
|
|
62
|
+
logger_1.default.error `Theme name=${themeNameParam} not found. ${suggestion
|
|
63
|
+
? logger_1.default.interpolate `Did you mean name=${suggestion}?`
|
|
64
|
+
: logger_1.default.interpolate `Themes available for swizzle: ${themeNames}`}`;
|
|
65
|
+
return process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
async function validateThemeName({ themeNameParam, themeNames, }) {
|
|
68
|
+
const isValidName = themeNames.includes(themeNameParam);
|
|
69
|
+
if (!isValidName) {
|
|
70
|
+
return handleInvalidThemeName({
|
|
71
|
+
themeNameParam,
|
|
72
|
+
themeNames,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return themeNameParam;
|
|
76
|
+
}
|
|
77
|
+
async function getThemeName({ themeNameParam, themeNames, list, }) {
|
|
78
|
+
if (list && !themeNameParam) {
|
|
79
|
+
logger_1.default.info `Themes available for swizzle: name=${themeNames}`;
|
|
80
|
+
return process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
return themeNameParam
|
|
83
|
+
? validateThemeName({ themeNameParam, themeNames })
|
|
84
|
+
: (0, prompts_1.askThemeName)(themeNames);
|
|
85
|
+
}
|
|
86
|
+
exports.getThemeName = getThemeName;
|
|
87
|
+
function getThemePath({ plugins, themeName, typescript, }) {
|
|
88
|
+
const pluginInstance = getPluginByThemeName(plugins, themeName);
|
|
89
|
+
const themePath = typescript
|
|
90
|
+
? pluginInstance.instance.getTypeScriptThemePath?.()
|
|
91
|
+
: pluginInstance.instance.getThemePath?.();
|
|
92
|
+
if (!themePath) {
|
|
93
|
+
logger_1.default.warn(typescript
|
|
94
|
+
? logger_1.default.interpolate `name=${themeName} does not provide TypeScript theme code via ${'getTypeScriptThemePath()'}.`
|
|
95
|
+
: // This is... technically possible to happen, e.g. returning undefined
|
|
96
|
+
// from getThemePath. Plugins may intentionally or unintentionally
|
|
97
|
+
// disguise as themes?
|
|
98
|
+
logger_1.default.interpolate `name=${themeName} does not provide any theme code.`);
|
|
99
|
+
return process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
return themePath;
|
|
102
|
+
}
|
|
103
|
+
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
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
-
const
|
|
13
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
13
|
const server_1 = require("../server");
|
|
15
14
|
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
16
|
-
const lodash_1 = require("lodash");
|
|
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
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) => plugin?.getPathsToWatch?.() ?? []);
|
|
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 ?? (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,20 +1,42 @@
|
|
|
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 = tslib_1.__importDefault(require("path"));
|
|
4
11
|
const server_1 = require("../server");
|
|
5
12
|
const init_1 = 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
|
-
var _a;
|
|
11
33
|
if (plugin.getTranslationFiles) {
|
|
12
|
-
const content = await
|
|
34
|
+
const content = await plugin.loadContent?.();
|
|
13
35
|
const translationFiles = await plugin.getTranslationFiles({
|
|
14
36
|
content,
|
|
15
37
|
});
|
|
16
38
|
await Promise.all(translationFiles.map(async (translationFile) => {
|
|
17
|
-
await translations_1.writePluginTranslations({
|
|
39
|
+
await (0, translations_1.writePluginTranslations)({
|
|
18
40
|
siteDir,
|
|
19
41
|
plugin,
|
|
20
42
|
translationFile,
|
|
@@ -25,32 +47,31 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
25
47
|
}
|
|
26
48
|
}
|
|
27
49
|
async function writeTranslations(siteDir, options) {
|
|
28
|
-
|
|
29
|
-
const context = await server_1.loadContext(siteDir, {
|
|
50
|
+
const context = await (0, server_1.loadContext)(siteDir, {
|
|
30
51
|
customConfigFilePath: options.config,
|
|
31
52
|
locale: options.locale,
|
|
32
53
|
});
|
|
33
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
34
|
-
const plugins = init_1.default({
|
|
54
|
+
const pluginConfigs = await (0, server_1.loadPluginConfigs)(context);
|
|
55
|
+
const plugins = await (0, init_1.default)({
|
|
35
56
|
pluginConfigs,
|
|
36
57
|
context,
|
|
37
58
|
});
|
|
38
|
-
const locale =
|
|
59
|
+
const locale = options.locale ?? context.i18n.defaultLocale;
|
|
39
60
|
if (!context.i18n.locales.includes(locale)) {
|
|
40
61
|
throw new Error(`Can't write-translation for locale "${locale}" that is not in the locale configuration file.
|
|
41
62
|
Available locales are: ${context.i18n.locales.join(',')}.`);
|
|
42
63
|
}
|
|
43
|
-
const babelOptions = utils_1.getBabelOptions({
|
|
64
|
+
const babelOptions = (0, utils_1.getBabelOptions)({
|
|
44
65
|
isServer: true,
|
|
45
|
-
babelOptions: utils_1.getCustomBabelConfigFilePath(siteDir),
|
|
66
|
+
babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
|
|
46
67
|
});
|
|
47
|
-
const extractedCodeTranslations = await translationsExtractor_1.extractSiteSourceCodeTranslations(siteDir, plugins, babelOptions);
|
|
48
|
-
const defaultCodeMessages = await translations_1.getPluginsDefaultCodeTranslationMessages(plugins);
|
|
49
|
-
const codeTranslations = translations_1.applyDefaultCodeTranslations({
|
|
68
|
+
const extractedCodeTranslations = await (0, translationsExtractor_1.extractSiteSourceCodeTranslations)(siteDir, plugins, babelOptions, await getExtraSourceCodeFilePaths());
|
|
69
|
+
const defaultCodeMessages = await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins);
|
|
70
|
+
const codeTranslations = (0, translations_1.applyDefaultCodeTranslations)({
|
|
50
71
|
extractedCodeTranslations,
|
|
51
72
|
defaultCodeMessages,
|
|
52
73
|
});
|
|
53
|
-
await translations_1.writeCodeTranslations({ siteDir, locale }, codeTranslations, options);
|
|
74
|
+
await (0, translations_1.writeCodeTranslations)({ siteDir, locale }, codeTranslations, options);
|
|
54
75
|
await Promise.all(plugins.map(async (plugin) => {
|
|
55
76
|
await writePluginTranslationFiles({ siteDir, plugin, locale, options });
|
|
56
77
|
}));
|
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 = tslib_1.__importDefault(require("./commands/build"));
|
|
12
|
+
exports.build = build_1.default;
|
|
13
|
+
const clear_1 = tslib_1.__importDefault(require("./commands/clear"));
|
|
14
|
+
exports.clear = clear_1.default;
|
|
15
|
+
const deploy_1 = tslib_1.__importDefault(require("./commands/deploy"));
|
|
16
|
+
exports.deploy = deploy_1.default;
|
|
17
|
+
const external_1 = tslib_1.__importDefault(require("./commands/external"));
|
|
18
|
+
exports.externalCommand = external_1.default;
|
|
19
|
+
const serve_1 = tslib_1.__importDefault(require("./commands/serve"));
|
|
20
|
+
exports.serve = serve_1.default;
|
|
21
|
+
const start_1 = tslib_1.__importDefault(require("./commands/start"));
|
|
22
|
+
exports.start = start_1.default;
|
|
23
|
+
const swizzle_1 = tslib_1.__importDefault(require("./commands/swizzle"));
|
|
24
|
+
exports.swizzle = swizzle_1.default;
|
|
25
|
+
const writeHeadingIds_1 = tslib_1.__importDefault(require("./commands/writeHeadingIds"));
|
|
26
|
+
exports.writeHeadingIds = writeHeadingIds_1.default;
|
|
27
|
+
const writeTranslations_1 = 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;
|