Skip to content

Commit 964c884

Browse files
committed
Merge branch 'main' into feature/redesign-2024
2 parents dca219d + b5aac5c commit 964c884

File tree

9 files changed

+1231
-1251
lines changed

9 files changed

+1231
-1251
lines changed

.eslintrc.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ module.exports = {
1111
requireConfigFile: false,
1212
},
1313
rules: {
14-
// allow reassigning param
15-
'no-param-reassign': [2, { props: false }],
16-
'linebreak-style': ['error', 'unix'],
17-
'import/extensions': ['error', {
18-
js: 'always',
19-
}],
14+
'import/extensions': ['error', { js: 'always' }], // require js file extensions in imports
15+
'linebreak-style': ['error', 'unix'], // enforce unix linebreaks
16+
'no-param-reassign': [2, { props: false }], // allow modifying properties of param
2017
},
2118
};

.stylelintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"extends": ["stylelint-config-standard"]
3-
}
3+
}

404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
btnContainer.append(backBtn);
3030
}
3131
}
32-
sampleRUM('404', { source: document.referrer, target: window.location.href });
32+
sampleRUM('404', { source: document.referrer });
3333
});
3434
</script>
3535
<link rel="stylesheet" href="/styles/styles.css">

package-lock.json

Lines changed: 1135 additions & 1221 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
},
2222
"homepage": "https://github.com/adaptto/adaptto-website",
2323
"devDependencies": {
24-
"@babel/core": "7.23.9",
25-
"@babel/eslint-parser": "7.23.10",
26-
"@esm-bundle/chai": "4.3.4-fix.0",
27-
"@web/test-runner": "0.18.0",
24+
"@babel/core": "7.24.6",
25+
"@babel/eslint-parser": "7.24.6",
26+
"@esm-bundle/chai": "4.3.4",
27+
"@web/test-runner": "0.18.2",
2828
"@web/test-runner-commands": "0.9.0",
29-
"chai": "5.0.3",
30-
"eslint": "8.56.0",
29+
"chai": "5.1.1",
30+
"eslint": "8.57.0",
3131
"eslint-config-airbnb-base": "15.0.0",
3232
"eslint-plugin-import": "2.29.1",
33-
"sinon": "17.0.1",
34-
"stylelint": "16.2.0",
33+
"sinon": "18.0.0",
34+
"stylelint": "16.6.0",
3535
"stylelint-config-standard": "36.0.0"
3636
}
3737
}

scripts/aem.js

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Adobe. All rights reserved.
2+
* Copyright 2024 Adobe. All rights reserved.
33
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License. You may obtain a copy
55
* of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -22,6 +22,9 @@
2222
* for instance the href of a link, or a search term
2323
*/
2424
function sampleRUM(checkpoint, data = {}) {
25+
const SESSION_STORAGE_KEY = 'aem-rum';
26+
sampleRUM.baseURL = sampleRUM.baseURL
27+
|| new URL(window.RUM_BASE == null ? 'https://rum.hlx.page' : window.RUM_BASE, window.location);
2528
sampleRUM.defer = sampleRUM.defer || [];
2629
const defer = (fnname) => {
2730
sampleRUM[fnname] = sampleRUM[fnname] || ((...args) => sampleRUM.defer.push({ fnname, args }));
@@ -53,12 +56,21 @@ function sampleRUM(checkpoint, data = {}) {
5356
.join('');
5457
const random = Math.random();
5558
const isSelected = random * weight < 1;
56-
const firstReadTime = Date.now();
59+
const firstReadTime = window.performance ? window.performance.timeOrigin : Date.now();
5760
const urlSanitizers = {
5861
full: () => window.location.href,
5962
origin: () => window.location.origin,
6063
path: () => window.location.href.replace(/\?.*$/, ''),
6164
};
65+
// eslint-disable-next-line max-len
66+
const rumSessionStorage = sessionStorage.getItem(SESSION_STORAGE_KEY)
67+
? JSON.parse(sessionStorage.getItem(SESSION_STORAGE_KEY))
68+
: {};
69+
// eslint-disable-next-line max-len
70+
rumSessionStorage.pages = (rumSessionStorage.pages ? rumSessionStorage.pages : 0)
71+
+ 1
72+
/* noise */ + (Math.floor(Math.random() * 20) - 10);
73+
sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(rumSessionStorage));
6274
// eslint-disable-next-line object-curly-newline, max-len
6375
window.hlx.rum = {
6476
weight,
@@ -68,8 +80,10 @@ function sampleRUM(checkpoint, data = {}) {
6880
firstReadTime,
6981
sampleRUM,
7082
sanitizeURL: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'],
83+
rumSessionStorage,
7184
};
7285
}
86+
7387
const { weight, id, firstReadTime } = window.hlx.rum;
7488
if (window.hlx && window.hlx.rum && window.hlx.rum.isSelected) {
7589
const knownProperties = [
@@ -85,32 +99,35 @@ function sampleRUM(checkpoint, data = {}) {
8599
'FID',
86100
'LCP',
87101
'INP',
102+
'TTFB',
88103
];
89104
const sendPing = (pdata = data) => {
105+
// eslint-disable-next-line max-len
106+
const t = Math.round(
107+
window.performance ? window.performance.now() : Date.now() - firstReadTime,
108+
);
90109
// eslint-disable-next-line object-curly-newline, max-len, no-use-before-define
91110
const body = JSON.stringify(
92111
{
93-
weight,
94-
id,
95-
referer: window.hlx.rum.sanitizeURL(),
96-
checkpoint,
97-
t: Date.now() - firstReadTime,
98-
...data,
112+
weight, id, referer: window.hlx.rum.sanitizeURL(), checkpoint, t, ...data,
99113
},
100114
knownProperties,
101115
);
102-
const url = `https://rum.hlx.page/.rum/${weight}`;
103-
// eslint-disable-next-line no-unused-expressions
116+
const url = new URL(`.rum/${weight}`, sampleRUM.baseURL).href;
104117
navigator.sendBeacon(url, body);
105118
// eslint-disable-next-line no-console
106119
console.debug(`ping:${checkpoint}`, pdata);
107120
};
108121
sampleRUM.cases = sampleRUM.cases || {
122+
load: () => sampleRUM('pagesviewed', { source: window.hlx.rum.rumSessionStorage.pages }) || true,
109123
cwv: () => sampleRUM.cwv(data) || true,
110124
lazy: () => {
111125
// use classic script to avoid CORS issues
112126
const script = document.createElement('script');
113-
script.src = 'https://rum.hlx.page/.rum/@adobe/helix-rum-enhancer@^1/src/index.js';
127+
script.src = new URL(
128+
'.rum/@adobe/helix-rum-enhancer@^1/src/index.js',
129+
sampleRUM.baseURL,
130+
).href;
114131
document.head.appendChild(script);
115132
return true;
116133
},
@@ -355,6 +372,48 @@ function decorateTemplateAndTheme() {
355372
if (theme) addClasses(document.body, theme);
356373
}
357374

375+
/**
376+
* Wrap inline text content of block cells within a <p> tag.
377+
* @param {Element} block the block element
378+
*/
379+
function wrapTextNodes(block) {
380+
const validWrappers = [
381+
'P',
382+
'PRE',
383+
'UL',
384+
'OL',
385+
'PICTURE',
386+
'TABLE',
387+
'H1',
388+
'H2',
389+
'H3',
390+
'H4',
391+
'H5',
392+
'H6',
393+
];
394+
395+
const wrap = (el) => {
396+
const wrapper = document.createElement('p');
397+
wrapper.append(...el.childNodes);
398+
el.append(wrapper);
399+
};
400+
401+
block.querySelectorAll(':scope > div > div').forEach((blockColumn) => {
402+
if (blockColumn.hasChildNodes()) {
403+
const hasWrapper = !!blockColumn.firstElementChild
404+
&& validWrappers.some((tagName) => blockColumn.firstElementChild.tagName === tagName);
405+
if (!hasWrapper) {
406+
wrap(blockColumn);
407+
} else if (
408+
blockColumn.firstElementChild.tagName === 'PICTURE'
409+
&& (blockColumn.children.length > 1 || !!blockColumn.textContent.trim())
410+
) {
411+
wrap(blockColumn);
412+
}
413+
}
414+
});
415+
}
416+
358417
/**
359418
* Decorates paragraphs containing a single link as buttons.
360419
* @param {Element} element container element
@@ -618,6 +677,7 @@ function decorateBlock(block) {
618677
block.classList.add('block');
619678
block.dataset.blockName = shortBlockName;
620679
block.dataset.blockStatus = 'initialized';
680+
wrapTextNodes(block);
621681
const blockWrapper = block.parentElement;
622682
blockWrapper.classList.add(`${shortBlockName}-wrapper`);
623683
const section = block.closest('.section');
@@ -706,4 +766,5 @@ export {
706766
toClassName,
707767
updateSectionsStatus,
708768
waitForLCP,
769+
wrapTextNodes,
709770
};

scripts/services/Link.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const adaptToSiteUrlRegex = /^https?:\/\/([^/.]+--adaptto-website--adaptto.hlx.(page|live)|adapt.to|franklin.adaptto.de|localhost:\d+)(\/.+)$/;
2-
const adaptToSiteUrlPathnameGroup = 3;
1+
const adaptToSiteUrlRegex = /^https?:\/\/([^/.]+--adaptto-website--adaptto.(hlx|aem).(page|live)|adapt.to|localhost:\d+)(\/.+)$/;
2+
const adaptToSiteUrlPathnameGroup = 4;
33
const downloadUrlRegex = /^.+\.(pdf|zip)$/;
44

55
/**

scripts/utils/datetime.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const locale = 'en-GB';
22
const timeOptions = { hour: '2-digit', minute: '2-digit', timeZone: 'UTC' };
33
const dateFullOptions = { dateStyle: 'full' };
4+
const datePatternWithoutComma = /^(\w+) (\d+ \w+ \d+)$/;
45

56
/**
67
* Format date in full format.
@@ -9,7 +10,13 @@ const dateFullOptions = { dateStyle: 'full' };
910
* @returns {string} Formatted date
1011
*/
1112
export function formatDateFull(date) {
12-
return date.toLocaleDateString(locale, dateFullOptions);
13+
const formattedDate = date.toLocaleDateString(locale, dateFullOptions);
14+
// insert comma after day name if not already present
15+
const match = datePatternWithoutComma.exec(formattedDate);
16+
if (match) {
17+
return `${match[1]}, ${match[2]}`;
18+
}
19+
return formattedDate;
1320
}
1421

1522
/**

test/scripts/services/LinkHandler.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('services/LinkHandler', () => {
99
it('rewriteUrl', () => {
1010
expect(rewriteUrl('https://adapt.to/mypath')).to.eq('/mypath');
1111
expect(rewriteUrl('https://experimental-download-links--adaptto-website--adaptto.hlx.page/2021/schedule')).to.eq('/2021/schedule');
12+
expect(rewriteUrl('https://experimental-download-links--adaptto-website--adaptto.aem.page/2021/schedule')).to.eq('/2021/schedule');
1213
expect(rewriteUrl('https://main--adaptto-website--adaptto.hlx.live/2021/schedule#day1')).to.eq('/2021/schedule#day1');
1314
expect(rewriteUrl('https://localhost:2000/2021/schedule#day1')).to.eq('/2021/schedule#day1');
1415
expect(rewriteUrl('https://my.host.com/mypath')).to.eq('https://my.host.com/mypath');

0 commit comments

Comments
 (0)