Skip to content

Commit

Permalink
404 page redirects fitting vanity paths to the long-form url (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
DriftingSands authored Sep 28, 2023
1 parent 24a2a00 commit 1386005
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</style>
</head>

<body>
<body hidden>
<header></header>
<main class="error">
<section>
Expand All @@ -179,12 +179,29 @@ <h1>TAKE A MULLIGAN</h1>
</main>
<footer></footer>
<script type="module">
import { createOptimizedPicture } from "./scripts/lib-franklin.js";
const imageUrl = "/media_10b8f0c21a329ee5ab764abf34d64a94de757ea2a.png";
const imageAlt = "Tiger Woods regretting a bad shot";
const pictureElement = createOptimizedPicture(imageUrl, imageAlt);
const imageContainer = document.querySelector(".error-image");
imageContainer.appendChild(pictureElement);
import { createOptimizedPicture } from "/scripts/lib-franklin.js";

const display404 = () => {
document.body.hidden = false

const imageUrl = "/media_10b8f0c21a329ee5ab764abf34d64a94de757ea2a.png";
const imageAlt = "Tiger Woods regretting a bad shot";
const pictureElement = createOptimizedPicture(imageUrl, imageAlt);
const imageContainer = document.querySelector(".error-image");
imageContainer.appendChild(pictureElement);
}

fetch('/import/tools/importer/data/sitemap.json').then(response => response.json()).then((sitemap) => {
const pathLocation = sitemap.find((obj) => Object.hasOwn(obj, window.location.pathname))
if (pathLocation) {
const drivePath = '/content-v2/' + pathLocation[window.location.pathname].replace('/content/golfdigest-com/en/', '').replace('.html', '')
window.location.assign(drivePath)
} else {
display404()
}
}).catch(error => {
display404()
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export function addFavIcons() {
`;

// Remove placeholder
document.head.querySelector('head link[rel="icon"]').remove();
document.head.querySelector('head link[rel="icon"]')?.remove();

// Add favicons
document.head.insertAdjacentHTML('beforeend', favicons);
Expand Down

0 comments on commit 1386005

Please sign in to comment.