Skip to content
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

DEX-15580 - decorate canonical link #414

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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