chore: migrate website config to createConfigAsync (#8911)

This commit is contained in:
Sébastien Lorber 2023-04-21 12:00:09 +02:00 committed by GitHub
parent 41a52161fd
commit 4a4a8be062
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,8 +88,9 @@ function getLocalizedConfigValue(/** @type {string} */ key) {
return value; return value;
} }
/** @type {import('@docusaurus/types').Config} */ /** @returns {Promise<import('@docusaurus/types').Config>} */
const config = { module.exports = async function createConfigAsync() {
return {
title: 'Docusaurus', title: 'Docusaurus',
tagline: getLocalizedConfigValue('tagline'), tagline: getLocalizedConfigValue('tagline'),
organizationName: 'facebook', organizationName: 'facebook',
@ -152,8 +153,8 @@ const config = {
staticDirectories: [ staticDirectories: [
'static', 'static',
path.join(__dirname, '_dogfooding/_asset-tests'), path.join(__dirname, '_dogfooding/_asset-tests'),
// Adding a non-existent static directory. If user deleted `static` without // Adding a non-existent static directory. If user deleted `static`
// specifying `staticDirectories: []`, build should still work // without specifying `staticDirectories: []`, build should still work
path.join(__dirname, '_dogfooding/non-existent'), path.join(__dirname, '_dogfooding/non-existent'),
], ],
themes: ['live-codeblock', ...dogfoodingThemeInstances], themes: ['live-codeblock', ...dogfoodingThemeInstances],
@ -303,6 +304,8 @@ const config = {
}, },
], ],
'@docusaurus/theme-mermaid', '@docusaurus/theme-mermaid',
(await import('./src/plugins/featureRequests/FeatureRequestsPlugin.mjs'))
.default,
...dogfoodingPluginInstances, ...dogfoodingPluginInstances,
], ],
presets: [ presets: [
@ -321,7 +324,7 @@ const config = {
if (locale !== defaultLocale) { if (locale !== defaultLocale) {
return `https://crowdin.com/project/docusaurus-v2/${locale}`; return `https://crowdin.com/project/docusaurus-v2/${locale}`;
} }
// We want users to submit doc updates to the upstream/next version! // We want users to submit updates to the upstream/next version!
// Otherwise we risk losing the update on the next release. // Otherwise we risk losing the update on the next release.
const nextVersionDocsDirPath = 'docs'; const nextVersionDocsDirPath = 'docs';
return `https://github.com/facebook/docusaurus/edit/main/website/${nextVersionDocsDirPath}/${docPath}`; return `https://github.com/facebook/docusaurus/edit/main/website/${nextVersionDocsDirPath}/${docPath}`;
@ -332,11 +335,17 @@ const config = {
}, },
showLastUpdateAuthor: true, showLastUpdateAuthor: true,
showLastUpdateTime: true, showLastUpdateTime: true,
remarkPlugins: [math, [npm2yarn, {sync: true}]], remarkPlugins: [
rehypePlugins: [], math,
[npm2yarn, {sync: true}],
(await import('./src/remark/configTabs.mjs')).default,
],
rehypePlugins: [(await import('rehype-katex')).default],
disableVersioning: isVersioningDisabled, disableVersioning: isVersioningDisabled,
lastVersion: lastVersion:
isDev || isDeployPreview || isBranchDeploy ? 'current' : undefined, isDev || isDeployPreview || isBranchDeploy
? 'current'
: undefined,
onlyIncludeVersions: (() => { onlyIncludeVersions: (() => {
if (isBuildFast) { if (isBuildFast) {
return ['current']; return ['current'];
@ -429,6 +438,8 @@ const config = {
line: 'This will error', line: 'This will error',
}, },
], ],
theme: (await import('./src/utils/prismLight.mjs')).default,
darkTheme: (await import('./src/utils/prismDark.mjs')).default,
}, },
image: 'img/docusaurus-social-card.jpg', image: 'img/docusaurus-social-card.jpg',
// metadata: [{name: 'twitter:card', content: 'summary'}], // metadata: [{name: 'twitter:card', content: 'summary'}],
@ -653,26 +664,5 @@ const config = {
copyright: `Copyright © ${new Date().getFullYear()} Meta Platforms, Inc. Built with Docusaurus.`, copyright: `Copyright © ${new Date().getFullYear()} Meta Platforms, Inc. Built with Docusaurus.`,
}, },
}), }),
};
}; };
async function createConfig() {
const FeatureRequestsPlugin = (
await import('./src/plugins/featureRequests/FeatureRequestsPlugin.mjs')
).default;
const configTabs = (await import('./src/remark/configTabs.mjs')).default;
const lightTheme = (await import('./src/utils/prismLight.mjs')).default;
const darkTheme = (await import('./src/utils/prismDark.mjs')).default;
const katex = (await import('rehype-katex')).default;
config.plugins?.push(FeatureRequestsPlugin);
// @ts-expect-error: we know it exists, right
config.presets[0][1].docs.remarkPlugins.push(configTabs);
// @ts-expect-error: we know it exists, right
config.themeConfig.prism.theme = lightTheme;
// @ts-expect-error: we know it exists, right
config.themeConfig.prism.darkTheme = darkTheme;
// @ts-expect-error: we know it exists, right
config.presets[0][1].docs.rehypePlugins.push(katex);
return config;
}
module.exports = createConfig;