From 9690b438abca924b27adc8430a56a41997a31f69 Mon Sep 17 00:00:00 2001 From: ext-vradulescu Date: Mon, 20 Nov 2023 16:01:03 +0200 Subject: [PATCH] DEX-15580 - decorate canonical link --- solutions/scripts/lib-franklin.js | 13 +++++++++++++ solutions/scripts/scripts.js | 2 ++ 2 files changed, 15 insertions(+) diff --git a/solutions/scripts/lib-franklin.js b/solutions/scripts/lib-franklin.js index 52487bf11..dcb62ca89 100644 --- a/solutions/scripts/lib-franklin.js +++ b/solutions/scripts/lib-franklin.js @@ -916,6 +916,19 @@ export function setup() { } } +/** +* canonical links shouldn't contain ".html" ( covered by redirects.xlsx ) + * canonical links shouldn't end with "/" +* */ +export function decorateCanonical(doc) { + const linkRelCanonical = doc.head.querySelector('[rel="canonical"]'); + linkRelCanonical.href = linkRelCanonical.href.replace('https://', 'https://www.'); + const lastChar = linkRelCanonical.href.slice(-1); + if (lastChar === '/') { + linkRelCanonical.href = linkRelCanonical.href.slice(0, -1); + } +} + /** * Auto initializiation. */ diff --git a/solutions/scripts/scripts.js b/solutions/scripts/scripts.js index e6e184155..c016f516f 100644 --- a/solutions/scripts/scripts.js +++ b/solutions/scripts/scripts.js @@ -12,6 +12,7 @@ import { loadBlocks, loadCSS, getMetadata, + decorateCanonical, } from './lib-franklin.js'; import { @@ -526,6 +527,7 @@ function loadDelayed() { async function loadPage() { pushPageLoadToDataLayer(); await window.hlx.plugins.load('eager'); + decorateCanonical(document); await loadEager(document); await window.hlx.plugins.load('lazy'); await loadLazy(document);