1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

docs: add /docs redirects to _all_ redirect paths (#2839)

## What

For each defined doc redirect path (that doesn't start with `/docs/`),
this PR adds an additional redirect that starts with `/docs`. The rest
of the path is otherwise identical.

For instance, if we have a redirect that goes from `/user_guide/x`, then
this change will ensure that we also have redirect that goes from
`/docs/user_guide/x`.

## Why

As reported by Roman, we've had some 404s recently when people have
tried to access pages that used to exist (wayyyy back) and that used to
redirect.

The reason these redirects stopped working is that we changed the url
structure recently. Before then, the `createRedirects` function would go
and create redirects that started with `/docs/` for all the paths that
required it. However, now that we've changed the structure of the URLs,
a blanket implementation like that won't work anymore.

Luckily, though, we already have all the redirects for pages we have
moved (just not redirecting from the `/docs/...` paths), so we can map
over the paths and add the missing redirects.
This commit is contained in:
Thomas Heartman 2023-01-05 21:47:04 +01:00 committed by GitHub
parent 5fa73b929a
commit 89c6c09db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,42 @@
const { readmes } = require('./readme-fns');
// for a given redirect object, modify it's `from` property such that for every
// path that doesn't start with `/docs/`, a corresponding path that _does_ start
// with `/docs/` is added.
//
// For instance, given the object
//
// {
// to: '/new/path',
// from: ['/old/path', '/docs/other/old/path'],
// }
//
// it will produce
//
// {
// to: '/new/path',
// from: ['/old/path', '/docs/old/path', '/docs/other/old/path'],
// }
//
const addDocsRoutePrefix = ({ from, ...rest }) => {
const addDocs = (from) => {
if (Array.isArray(from)) {
// if `from` is a list, then check each entry
return from.flatMap(addDocs);
} else {
if (from.startsWith('/docs/')) {
return [from];
} else {
return [from, `/docs${from}`];
}
}
};
return {
...rest,
from: addDocs(from),
};
};
/** @type {import('@docusaurus/types').DocusaurusConfig} */
module.exports = {
title: 'Unleash',
@ -235,10 +272,7 @@ module.exports = {
to: '/reference/deploy/getting-started',
},
{
from: [
'/docs/deploy/configuring_unleash',
'/deploy/configuring_unleash',
],
from: '/deploy/configuring_unleash',
to: '/reference/deploy/configuring-unleash',
},
{
@ -322,7 +356,6 @@ module.exports = {
'/sdks',
'/user_guide/client-sdk',
'/client-sdk',
'/docs/user_guide/connect_sdk',
'/user_guide/connect_sdk',
'/sdks/community',
],
@ -462,7 +495,7 @@ module.exports = {
to: '/reference/api/legacy/unleash/admin/context',
},
{
from: ['/api/admin/events', '/docs/api/admin/events'],
from: '/api/admin/events',
to: '/reference/api/legacy/unleash/admin/events',
},
{
@ -529,7 +562,11 @@ module.exports = {
from: '/api/internal/health',
to: '/reference/api/legacy/unleash/internal/health',
},
],
{
from: '/help',
to: '/',
},
].map(addDocsRoutePrefix), // add /docs prefixes
createRedirects: function (toPath) {
if (
toPath.indexOf('/docs/') === -1 &&