Skip to content
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

fix(ci/preview): add custom 404 page for PR preview pages #37769

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>404 Page Not Found</title>
<script src="/en-US/404/index.js"></script>
</head>
<body>
<h1>404 Page Not Found</h1>
OnkarRuikar marked this conversation as resolved.
Show resolved Hide resolved
<p><strong>Note:</strong> This is a GitHub pull request preview, and this page is not a part of the pull request.</p>
</body>
</html>
13 changes: 13 additions & 0 deletions .github/workflows/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function getContentsAfterHost() {
const full = location.href;
const path = location.pathname;

return full.substring(full.indexOf(path));
}

window.addEventListener("DOMContentLoaded", () => {
const link = document.createElement("a");
link.href = `https://developer.mozilla.org${getContentsAfterHost()}`;
link.textContent = "View on MDN production server";
document.body.appendChild(link);
});
5 changes: 5 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ jobs:
run: |
# Exclude the .map files, as they're used for debugging JS and CSS.
rsync -a --exclude "*.map" node_modules/@mdn/yari/client/build/ $BUILD_OUT_ROOT

# Add the custom 404 page to provide production links to the unbuilt documents
cp -v ./.github/workflows/404.html ${BUILD_OUT_ROOT}/en-us/404/index.html
cp -v ./.github/workflows/404.js ${BUILD_OUT_ROOT}/en-us/404/index.js

# Show the final disk usage size of the build.
du -sh $BUILD_OUT_ROOT

Expand Down
Loading