Skip to content

Commit

Permalink
MWPW-139365 - SEO Tab Canonical Fix (#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
auniverseaway authored Nov 16, 2023
2 parents 2233f92 + d01ffb5 commit 4e71c61
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions libs/blocks/preflight/panels/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,32 @@ async function checkTitle() {
}

async function checkCanon() {
const canon = document.querySelector("link[rel='canonical']");
const result = { ...canonResult.value };
const { href } = canon;

try {
const resp = await fetch(href, { method: 'HEAD' });
if (!resp.ok) {
result.icon = fail;
result.description = 'Reason: Error with canonical reference.';
}
if (resp.ok) {
if (resp.status >= 300 && resp.status <= 308) {
const canon = document.querySelector("link[rel='canonical']");
if (!canon) {
result.icon = pass;
result.description = 'Canonical is self-referencing.';
} else {
const { href } = canon;
try {
const resp = await fetch(href, { method: 'HEAD' });
if (!resp.ok) {
result.icon = fail;
result.description = 'Reason: Canonical reference redirects.';
} else {
result.icon = pass;
result.description = 'Canonical referenced is valid.';
result.description = 'Reason: Error with canonical reference.';
}
if (resp.ok) {
if (resp.status >= 300 && resp.status <= 308) {
result.icon = fail;
result.description = 'Reason: Canonical reference redirects.';
} else {
result.icon = pass;
result.description = 'Canonical referenced is valid.';
}
}
} catch (e) {
result.icon = limbo;
result.description = 'Canonical cannot be crawled.';
}
} catch (e) {
result.icon = limbo;
result.description = 'Canonical cannot be crawled.';
}
canonResult.value = result;
return result.icon;
Expand Down

0 comments on commit 4e71c61

Please sign in to comment.