Skip to content

Commit

Permalink
Added redirects from /en/api/pc.* to api.playcanvas.com/classes/Engin…
Browse files Browse the repository at this point in the history
…e.* (#573)
  • Loading branch information
marklundin authored Feb 6, 2024
1 parent 7ec9825 commit 09f0a5a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const config = {

plugins: [
[ '@docusaurus/plugin-client-redirects', {
redirects: [
{ from: ['/api', '/en/api'], to: 'https://api.playcanvas.com' },
],
createRedirects: (path) => {

path = path.replace('/user-manual/editor/', '/user-manual/designer/');
Expand Down
56 changes: 56 additions & 0 deletions src/theme/NotFound/Content/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useEffect } from 'react';
import clsx from 'clsx';
import Translate from '@docusaurus/Translate';
import Heading from '@theme/Heading';
import { useLocation } from '@docusaurus/router';

const RedirectRoutes = ({ from, to }) => {
const { pathname } = useLocation();

useEffect(_ => {
const match = pathname.match(from);
if (match) {
const redirectTo = to.replace("$1", match[1]);
window.location.href = redirectTo;
}

}, [pathname, from, to])
}

export default function NotFoundContent({className}) {
return (
<>
<RedirectRoutes
from={/\/en\/api\/pc\.(.*)/}
to={"https://api.playcanvas.com/classes/Engine.$1"} />
<main className={clsx('container margin-vert--xl', className)}>
<div className="row">
<div className="col col--6 col--offset-3">
<Heading as="h1" className="hero__title">
<Translate
id="theme.NotFound.title"
description="The title of the 404 page">
Page Not Found
</Translate>
</Heading>
<p>
<Translate
id="theme.NotFound.p1"
description="The first paragraph of the 404 page">
We could not find what you were looking for.
</Translate>
</p>
<p>
<Translate
id="theme.NotFound.p2"
description="The 2nd paragraph of the 404 page">
Please contact the owner of the site that linked you to the
original URL and let them know their link is broken.
</Translate>
</p>
</div>
</div>
</main>
</>
);
}
19 changes: 19 additions & 0 deletions src/theme/NotFound/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {translate} from '@docusaurus/Translate';
import {PageMetadata} from '@docusaurus/theme-common';
import Layout from '@theme/Layout';
import NotFoundContent from '@theme/NotFound/Content';

export default function Index() {
const title = translate({
id: 'theme.NotFound.title',
message: 'Page Not Found',
});
return (
<>
<PageMetadata title={title} />
<Layout>
<NotFoundContent />
</Layout>
</>
);
}

0 comments on commit 09f0a5a

Please sign in to comment.