-
Notifications
You must be signed in to change notification settings - Fork 1
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
404 page redirects fitting vanity paths to the long-form url #270
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,7 @@ | |
</style> | ||
</head> | ||
|
||
<body> | ||
<body hidden> | ||
<header></header> | ||
<main class="error"> | ||
<section> | ||
|
@@ -179,12 +179,22 @@ <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"; | ||
import sitemap from "/import/tools/importer/data/sitemap.json" assert {type: 'json'} | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the user clicks on the back button, does he end up in an infinite loop in this case ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, I have not found that to be the case |
||
} else { | ||
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); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,17 @@ const LCP_BLOCKS = [...Object.values(ARTICLE_TEMPLATES), 'hero']; // add your LC | |
|
||
const range = document.createRange(); | ||
|
||
// getting real path, and adjusting canonical link to use the vanity path | ||
const canonicalLinkTag = document.head.querySelector('link[rel="canonical"]'); | ||
if (canonicalLinkTag) { | ||
const longPathMetadata = document.createElement('meta'); | ||
longPathMetadata.setAttribute('property', 'hlx:long-form-path'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
longPathMetadata.content = canonicalLinkTag?.href; | ||
document.head.appendChild(longPathMetadata); | ||
window.canonicalLocation = canonicalLinkTag.href; | ||
canonicalLinkTag.href = window.location.href; | ||
} | ||
|
||
export function replaceLinksWithEmbed(block) { | ||
const embeds = ['youtube', 'brightcove', 'instagram', 'ceros']; | ||
block.querySelectorAll(embeds.map((embed) => `a:only-child[href*="${embed}"]`).join(',')).forEach((embedLink) => { | ||
|
@@ -398,7 +409,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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't work on firefox and other browsers see https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
firefox should now be supported