diff --git a/microsite/docusaurus.config.ts b/microsite/docusaurus.config.ts index c6ceb21085..fcac2973dc 100644 --- a/microsite/docusaurus.config.ts +++ b/microsite/docusaurus.config.ts @@ -21,11 +21,35 @@ import { themes } from 'prism-react-renderer'; import type * as Preset from '@docusaurus/preset-classic'; import { Config } from '@docusaurus/types'; +import RedirectPlugin from '@docusaurus/plugin-client-redirects' + const backstageTheme = themes.vsDark; backstageTheme.plain.backgroundColor = '#232323'; const useVersionedDocs = require('fs').existsSync('versions.json'); +// This patches the redirect plugin to ignore the error when it tries to override existing fields. +// This lets us add redirects that only apply to the next docs, while the stable docs still contain the source path. +const PatchedRedirectPlugin: typeof RedirectPlugin = (ctx, opts) => { + const plugin = RedirectPlugin(ctx, opts); + + return { + ...plugin, + async postBuild(...args) { + try { + await plugin.postBuild(...args); + } catch (error) { + if (error.message === 'The redirect plugin is not supposed to override existing files.') { + // Bit of a hack to make sure all remaining redirects are written, since the write uses Promise.all + await new Promise(resolve => setTimeout(resolve, 1000)); + } else { + throw error + } + } + } + } +} + const config: Config = { title: 'Backstage Software Catalog and Developer Platform', tagline: 'An open source framework for building developer portals', @@ -141,89 +165,89 @@ const config: Config = { }; }, }), - [ - '@docusaurus/plugin-client-redirects', + ctx => PatchedRedirectPlugin(ctx, { + id: '@docusaurus/plugin-client-redirects', + toExtensions: [], + fromExtensions: [], + redirects: [ { - redirects: [ - { - from: '/docs', - to: '/docs/overview/what-is-backstage', - }, - { - from: '/docs/features/software-catalog/software-catalog-overview', - to: '/docs/features/software-catalog/', - }, - { - from: '/docs/features/software-templates/software-templates-index', - to: '/docs/features/software-templates/', - }, - { - from: '/docs/features/techdocs/techdocs-overview', - to: '/docs/features/techdocs/', - }, - { - from: '/docs/features/kubernetes/overview', - to: '/docs/features/kubernetes/', - }, - { - from: '/docs/features/search/search-overview', - to: '/docs/features/search/', - }, - { - from: '/docs/getting-started/running-backstage-locally', - to: '/docs/getting-started/', - }, - { - from: '/docs/features/software-templates/testing-scaffolder-alpha', - to: '/docs/features/software-templates/migrating-to-rjsf-v5', - }, - { - from: '/docs/auth/glossary', - to: '/docs/references/glossary', - }, - { - from: '/docs/overview/glossary', - to: '/docs/references/glossary', - }, - { - from: '/docs/getting-started/create-an-app', - to: '/docs/getting-started/', - }, - { - from: '/docs/getting-started/configuration', - to: '/docs/getting-started/#next-steps', - }, - { - from: '/docs/features/software-templates/authorizing-parameters-steps-and-actions', - to: '/docs/features/software-templates/authorizing-scaffolder-template-details', - }, - { - from: '/docs/local-dev/cli-commands/', - to: '/docs/tooling/cli/commands/', - }, - { - from: '/docs/local-dev/cli-build-system/', - to: '/docs/tooling/cli/build-system/', - }, - { - from: '/docs/local-dev/cli-overview/', - to: '/docs/tooling/cli/overview/', - }, - { - from: '/docs/local-dev/linking-local-packages/', - to: '/docs/tooling/local-dev/linking-local-packages', - }, - { - from: '/docs/local-dev/debugging/', - to: '/docs/tooling/local-dev/debugging', - }, - { - from: '/docs/plugins/url-reader/', - to: '/docs/backend-system/core-services/url-reader', - }, - ], + from: '/docs', + to: '/docs/overview/what-is-backstage', }, - ], + { + from: '/docs/features/software-catalog/software-catalog-overview', + to: '/docs/features/software-catalog/', + }, + { + from: '/docs/features/software-templates/software-templates-index', + to: '/docs/features/software-templates/', + }, + { + from: '/docs/features/techdocs/techdocs-overview', + to: '/docs/features/techdocs/', + }, + { + from: '/docs/features/kubernetes/overview', + to: '/docs/features/kubernetes/', + }, + { + from: '/docs/features/search/search-overview', + to: '/docs/features/search/', + }, + { + from: '/docs/getting-started/running-backstage-locally', + to: '/docs/getting-started/', + }, + { + from: '/docs/features/software-templates/testing-scaffolder-alpha', + to: '/docs/features/software-templates/migrating-to-rjsf-v5', + }, + { + from: '/docs/auth/glossary', + to: '/docs/references/glossary', + }, + { + from: '/docs/overview/glossary', + to: '/docs/references/glossary', + }, + { + from: '/docs/getting-started/create-an-app', + to: '/docs/getting-started/', + }, + { + from: '/docs/getting-started/configuration', + to: '/docs/getting-started/#next-steps', + }, + { + from: '/docs/features/software-templates/authorizing-parameters-steps-and-actions', + to: '/docs/features/software-templates/authorizing-scaffolder-template-details', + }, + { + from: '/docs/local-dev/cli-commands/', + to: '/docs/tooling/cli/commands/', + }, + { + from: '/docs/local-dev/cli-build-system/', + to: '/docs/tooling/cli/build-system/', + }, + { + from: '/docs/local-dev/cli-overview/', + to: '/docs/tooling/cli/overview/', + }, + { + from: '/docs/local-dev/linking-local-packages/', + to: '/docs/tooling/local-dev/linking-local-packages', + }, + { + from: '/docs/local-dev/debugging/', + to: '/docs/tooling/local-dev/debugging', + }, + { + from: '/docs/plugins/url-reader/', + to: '/docs/backend-system/core-services/url-reader', + }, + ] + }), [ 'docusaurus-pushfeedback', {