Skip to content

Commit

Permalink
DEX-15580 - decorate canonical link (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
vradulescu-bd authored Nov 20, 2023
1 parent e2cd5c3 commit f1f14d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions solutions/scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions solutions/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
loadBlocks,
loadCSS,
getMetadata,
decorateCanonical,
} from './lib-franklin.js';

import {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f1f14d4

Please sign in to comment.