Skip to content

Add javascript to 404 page that redirects all /live/... urls to the playtorch.dev website #1084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
62 changes: 62 additions & 0 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,68 @@

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" charset="utf-8">
const FALLBACK_URL = '';
const REDIRECT_STYLE = {
// Redirect completely, appending the path to the newly specified location.
// This is useful for project renames or moving to a different org.
FULL: 0,
// Redirect to the specific location, losing path information
// This is useful when you just want to capture the audience to known working page.
SIMPLE: 1,
// Redirect to the project's 404 page, injecting the original URL.
FOUROHFOUR_DEFAULT: 2,
// Redirect to the specified path, replacing ${from} with the original URL.
FOUROHFOUR_CUSTOM: 3,
};

const PROJECTS = {
live: {
location: 'https://playtorch.dev/',
style: REDIRECT_STYLE.FULL,
},
};

// eg "https://facebook.github.io/flux/docs/overview/"
const ORIGINAL_URL = window.location.href;
// eg [ "", "flux", "docs", "overview", "" ]
const PATH_PARTS = window.location.pathname.split('/');
// eg "flux"
const PROJECT = PATH_PARTS[1];
// eg "docs/overview/"
const SUBPATH = PATH_PARTS.slice(2).join('/');


// Perform the redirect only for explicitly defined projects.
// Otherwise show the 404 page below
if (PROJECTS.hasOwnProperty(PROJECT)) {
let newUrl = '';
let project = PROJECTS[PROJECT];
switch (project.style) {
case REDIRECT_STYLE.FULL:
newUrl = project.location + SUBPATH;
break;
case REDIRECT_STYLE.SIMPLE:
newUrl = project.location;
break;
case REDIRECT_STYLE.FOUROHFOUR_DEFAULT:
newUrl = project.location + '404.html?from=' + ORIGINAL_URL;
break;
case REDIRECT_STYLE.FOUROHFOUR_CUSTOM:
newUrl = project.location.replace('${from}', ORIGINAL_URL);
break;
default:
newUrl = FALLBACK_URL;
}

if (newUrl !== '') {
window.location.href = newUrl;
}
}

</script>
</head>
<body>
<div style="text-align: center;">
<img src="{{ site.baseurl }}/assets/images/404_sign.png" />
Expand Down
Empty file removed live/.nojekyll
Empty file.
29 changes: 0 additions & 29 deletions live/404.html

This file was deleted.

175 changes: 0 additions & 175 deletions live/_src/api/cli.md

This file was deleted.

1 change: 0 additions & 1 deletion live/_src/api/core/_category_.yml

This file was deleted.

2 changes: 0 additions & 2 deletions live/_src/api/core/classes/_category_.yml

This file was deleted.

110 changes: 0 additions & 110 deletions live/_src/api/core/classes/cameraview.camera.md

This file was deleted.

Loading