Skip to content

Commit

Permalink
Merge branch 'main' into feature/redesign-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jun 3, 2024
2 parents dca219d + b5aac5c commit 964c884
Show file tree
Hide file tree
Showing 9 changed files with 1,231 additions and 1,251 deletions.
9 changes: 3 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ module.exports = {
requireConfigFile: false,
},
rules: {
// allow reassigning param
'no-param-reassign': [2, { props: false }],
'linebreak-style': ['error', 'unix'],
'import/extensions': ['error', {
js: 'always',
}],
'import/extensions': ['error', { js: 'always' }], // require js file extensions in imports
'linebreak-style': ['error', 'unix'], // enforce unix linebreaks
'no-param-reassign': [2, { props: false }], // allow modifying properties of param
},
};
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["stylelint-config-standard"]
}
}
2 changes: 1 addition & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
btnContainer.append(backBtn);
}
}
sampleRUM('404', { source: document.referrer, target: window.location.href });
sampleRUM('404', { source: document.referrer });
});
</script>
<link rel="stylesheet" href="/styles/styles.css">
Expand Down
2,356 changes: 1,135 additions & 1,221 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
},
"homepage": "https://github.com/adaptto/adaptto-website",
"devDependencies": {
"@babel/core": "7.23.9",
"@babel/eslint-parser": "7.23.10",
"@esm-bundle/chai": "4.3.4-fix.0",
"@web/test-runner": "0.18.0",
"@babel/core": "7.24.6",
"@babel/eslint-parser": "7.24.6",
"@esm-bundle/chai": "4.3.4",
"@web/test-runner": "0.18.2",
"@web/test-runner-commands": "0.9.0",
"chai": "5.0.3",
"eslint": "8.56.0",
"chai": "5.1.1",
"eslint": "8.57.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.29.1",
"sinon": "17.0.1",
"stylelint": "16.2.0",
"sinon": "18.0.0",
"stylelint": "16.6.0",
"stylelint-config-standard": "36.0.0"
}
}
83 changes: 72 additions & 11 deletions scripts/aem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -22,6 +22,9 @@
* for instance the href of a link, or a search term
*/
function sampleRUM(checkpoint, data = {}) {
const SESSION_STORAGE_KEY = 'aem-rum';
sampleRUM.baseURL = sampleRUM.baseURL
|| new URL(window.RUM_BASE == null ? 'https://rum.hlx.page' : window.RUM_BASE, window.location);
sampleRUM.defer = sampleRUM.defer || [];
const defer = (fnname) => {
sampleRUM[fnname] = sampleRUM[fnname] || ((...args) => sampleRUM.defer.push({ fnname, args }));
Expand Down Expand Up @@ -53,12 +56,21 @@ function sampleRUM(checkpoint, data = {}) {
.join('');
const random = Math.random();
const isSelected = random * weight < 1;
const firstReadTime = Date.now();
const firstReadTime = window.performance ? window.performance.timeOrigin : Date.now();
const urlSanitizers = {
full: () => window.location.href,
origin: () => window.location.origin,
path: () => window.location.href.replace(/\?.*$/, ''),
};
// eslint-disable-next-line max-len
const rumSessionStorage = sessionStorage.getItem(SESSION_STORAGE_KEY)
? JSON.parse(sessionStorage.getItem(SESSION_STORAGE_KEY))
: {};
// eslint-disable-next-line max-len
rumSessionStorage.pages = (rumSessionStorage.pages ? rumSessionStorage.pages : 0)
+ 1
/* noise */ + (Math.floor(Math.random() * 20) - 10);
sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(rumSessionStorage));
// eslint-disable-next-line object-curly-newline, max-len
window.hlx.rum = {
weight,
Expand All @@ -68,8 +80,10 @@ function sampleRUM(checkpoint, data = {}) {
firstReadTime,
sampleRUM,
sanitizeURL: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'],
rumSessionStorage,
};
}

const { weight, id, firstReadTime } = window.hlx.rum;
if (window.hlx && window.hlx.rum && window.hlx.rum.isSelected) {
const knownProperties = [
Expand All @@ -85,32 +99,35 @@ function sampleRUM(checkpoint, data = {}) {
'FID',
'LCP',
'INP',
'TTFB',
];
const sendPing = (pdata = data) => {
// eslint-disable-next-line max-len
const t = Math.round(
window.performance ? window.performance.now() : Date.now() - firstReadTime,
);
// eslint-disable-next-line object-curly-newline, max-len, no-use-before-define
const body = JSON.stringify(
{
weight,
id,
referer: window.hlx.rum.sanitizeURL(),
checkpoint,
t: Date.now() - firstReadTime,
...data,
weight, id, referer: window.hlx.rum.sanitizeURL(), checkpoint, t, ...data,
},
knownProperties,
);
const url = `https://rum.hlx.page/.rum/${weight}`;
// eslint-disable-next-line no-unused-expressions
const url = new URL(`.rum/${weight}`, sampleRUM.baseURL).href;
navigator.sendBeacon(url, body);
// eslint-disable-next-line no-console
console.debug(`ping:${checkpoint}`, pdata);
};
sampleRUM.cases = sampleRUM.cases || {
load: () => sampleRUM('pagesviewed', { source: window.hlx.rum.rumSessionStorage.pages }) || true,
cwv: () => sampleRUM.cwv(data) || true,
lazy: () => {
// use classic script to avoid CORS issues
const script = document.createElement('script');
script.src = 'https://rum.hlx.page/.rum/@adobe/helix-rum-enhancer@^1/src/index.js';
script.src = new URL(
'.rum/@adobe/helix-rum-enhancer@^1/src/index.js',
sampleRUM.baseURL,
).href;
document.head.appendChild(script);
return true;
},
Expand Down Expand Up @@ -355,6 +372,48 @@ function decorateTemplateAndTheme() {
if (theme) addClasses(document.body, theme);
}

/**
* Wrap inline text content of block cells within a <p> tag.
* @param {Element} block the block element
*/
function wrapTextNodes(block) {
const validWrappers = [
'P',
'PRE',
'UL',
'OL',
'PICTURE',
'TABLE',
'H1',
'H2',
'H3',
'H4',
'H5',
'H6',
];

const wrap = (el) => {
const wrapper = document.createElement('p');
wrapper.append(...el.childNodes);
el.append(wrapper);
};

block.querySelectorAll(':scope > div > div').forEach((blockColumn) => {
if (blockColumn.hasChildNodes()) {
const hasWrapper = !!blockColumn.firstElementChild
&& validWrappers.some((tagName) => blockColumn.firstElementChild.tagName === tagName);
if (!hasWrapper) {
wrap(blockColumn);
} else if (
blockColumn.firstElementChild.tagName === 'PICTURE'
&& (blockColumn.children.length > 1 || !!blockColumn.textContent.trim())
) {
wrap(blockColumn);
}
}
});
}

/**
* Decorates paragraphs containing a single link as buttons.
* @param {Element} element container element
Expand Down Expand Up @@ -618,6 +677,7 @@ function decorateBlock(block) {
block.classList.add('block');
block.dataset.blockName = shortBlockName;
block.dataset.blockStatus = 'initialized';
wrapTextNodes(block);
const blockWrapper = block.parentElement;
blockWrapper.classList.add(`${shortBlockName}-wrapper`);
const section = block.closest('.section');
Expand Down Expand Up @@ -706,4 +766,5 @@ export {
toClassName,
updateSectionsStatus,
waitForLCP,
wrapTextNodes,
};
4 changes: 2 additions & 2 deletions scripts/services/Link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const adaptToSiteUrlRegex = /^https?:\/\/([^/.]+--adaptto-website--adaptto.hlx.(page|live)|adapt.to|franklin.adaptto.de|localhost:\d+)(\/.+)$/;
const adaptToSiteUrlPathnameGroup = 3;
const adaptToSiteUrlRegex = /^https?:\/\/([^/.]+--adaptto-website--adaptto.(hlx|aem).(page|live)|adapt.to|localhost:\d+)(\/.+)$/;
const adaptToSiteUrlPathnameGroup = 4;
const downloadUrlRegex = /^.+\.(pdf|zip)$/;

/**
Expand Down
9 changes: 8 additions & 1 deletion scripts/utils/datetime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const locale = 'en-GB';
const timeOptions = { hour: '2-digit', minute: '2-digit', timeZone: 'UTC' };
const dateFullOptions = { dateStyle: 'full' };
const datePatternWithoutComma = /^(\w+) (\d+ \w+ \d+)$/;

/**
* Format date in full format.
Expand All @@ -9,7 +10,13 @@ const dateFullOptions = { dateStyle: 'full' };
* @returns {string} Formatted date
*/
export function formatDateFull(date) {
return date.toLocaleDateString(locale, dateFullOptions);
const formattedDate = date.toLocaleDateString(locale, dateFullOptions);
// insert comma after day name if not already present
const match = datePatternWithoutComma.exec(formattedDate);
if (match) {
return `${match[1]}, ${match[2]}`;
}
return formattedDate;
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/scripts/services/LinkHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('services/LinkHandler', () => {
it('rewriteUrl', () => {
expect(rewriteUrl('https://adapt.to/mypath')).to.eq('/mypath');
expect(rewriteUrl('https://experimental-download-links--adaptto-website--adaptto.hlx.page/2021/schedule')).to.eq('/2021/schedule');
expect(rewriteUrl('https://experimental-download-links--adaptto-website--adaptto.aem.page/2021/schedule')).to.eq('/2021/schedule');
expect(rewriteUrl('https://main--adaptto-website--adaptto.hlx.live/2021/schedule#day1')).to.eq('/2021/schedule#day1');
expect(rewriteUrl('https://localhost:2000/2021/schedule#day1')).to.eq('/2021/schedule#day1');
expect(rewriteUrl('https://my.host.com/mypath')).to.eq('https://my.host.com/mypath');
Expand Down

0 comments on commit 964c884

Please sign in to comment.