Skip to content

Commit

Permalink
for link rewriting do not hardcode original host (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsaginor authored Oct 10, 2023
1 parent fbd77a2 commit 98b1c00
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions import/tools/importer/import.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function shouldRewriteLink(href) {

async function updateLink(el, url, rewrites, err) {
let href = el.href;
let hostname = new URL(url).hostname;

// is this an internal link?
if (shouldRewriteLink(href)) {
Expand All @@ -93,7 +94,7 @@ async function updateLink(el, url, rewrites, err) {
rewrites.new.push(`${href}`);
el.setAttribute('href', href);
} else {
const redirect = await getRedirect(`https://www.golfdigest.com${oldPath}`);
const redirect = await getRedirect(`https://${hostname}${oldPath}`);
if (redirect) {
// console.log(`${oldPath} redirected to ${redirect}`);
err.push(`Redirect: [${el.innerHTML}](${el.href}) to ${redirect}`);
Expand All @@ -102,7 +103,7 @@ async function updateLink(el, url, rewrites, err) {
} else {
// console.warn(`Unable to replace link ${el.href} with Franklin path. Item not found in sitemap.`);
try {
href = await fetchLongPath(`https://www.golfdigest.com${oldPath}`);
href = await fetchLongPath(`https://${hostname}${oldPath}`);
} catch(error) {
err.push(`Unble to map: [${el.innerHTML}](${el.href}) ${error.message}`);
console.warn(`${url}: Unable to map ${el.href} to Franklin path. ${error}`);
Expand Down

0 comments on commit 98b1c00

Please sign in to comment.