Skip to content

Commit

Permalink
docs: add /docs redirects to _all_ redirect paths (#2839)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
thomasheartman committed Jan 5, 2023
1 parent 5fa73b9 commit 89c6c09
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions website/docusaurus.config.js
@@ -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',
Expand Down Expand Up @@ -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',
},
{
Expand Down Expand Up @@ -322,7 +356,6 @@ module.exports = {
'/sdks',
'/user_guide/client-sdk',
'/client-sdk',
'/docs/user_guide/connect_sdk',
'/user_guide/connect_sdk',
'/sdks/community',
],
Expand Down Expand Up @@ -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',
},
{
Expand Down Expand Up @@ -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 &&
Expand Down

0 comments on commit 89c6c09

Please sign in to comment.