Skip to content

Commit

Permalink
Revert "feat: update aem lib (#19)"
Browse files Browse the repository at this point in the history
This reverts commit c94c34b.
  • Loading branch information
buuhuu authored Apr 23, 2024
1 parent c94c34b commit fc73928
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 58 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/cleanup-on-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ on:
create:
branches:
- main
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
# only run if commit message is "Initial commit" on main branch
if: ${{ github.event_name == 'workflow_dispatch' || ( github.ref == 'refs/heads/main' && !(contains(github.event, 'head_commit') || github.event.head_commit.message == 'Initial commit' )) }}
if: ${{ github.ref == 'refs/heads/main' && github.event.head_commit.message == 'Initial commit' }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -43,7 +42,7 @@ jobs:
- name: Commit changes
run: |
git config --local user.email "helix@adobe.com"
git config --local user.name "AEM Bot"
git config --local user.name "Helix Bot"
git add .
git commit -m "chore: cleanup repository template"
git push
4 changes: 4 additions & 0 deletions blocks/cards/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
margin: 16px;
}

.cards .cards-card-image p {
margin: 0;
}

.cards .cards-card-image {
line-height: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/cards/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function decorate(block) {
});
ul.append(li);
});
ul.querySelectorAll('picture > img').forEach((img) => {
ul.querySelectorAll('img').forEach((img) => {
const optimizedPic = createOptimizedPicture(img.src, img.alt, false, [{ width: '750' }]);
moveInstrumentation(img, optimizedPic.querySelector('img'));
img.closest('picture').replaceWith(optimizedPic);
Expand Down
75 changes: 21 additions & 54 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,58 +377,6 @@ 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.attributes]
// move the instrumentation from the cell to the new paragraph, also keep the class
// in case the content is a buttton and the cell the button-container
.filter(({ nodeName }) => nodeName === 'class'
|| nodeName.startsWith('data-aue')
|| nodeName.startsWith('data-richtext'))
.forEach(({ nodeName, nodeValue }) => {
wrapper.setAttribute(nodeName, nodeValue);
el.removeAttribute(nodeName);
});
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 @@ -692,11 +640,31 @@ 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');
if (section) section.classList.add(`${shortBlockName}-container`);
// wrap plain text and non-block elements in a <p> or <pre>
block.querySelectorAll(':scope > div > div').forEach((cell) => {
const firstChild = cell.firstElementChild;
const cellText = cell.textContent.trim();
if ((!firstChild && cellText)
|| (firstChild && !firstChild.tagName.match(/^(P(RE)?|H[1-6]|(U|O)L|TABLE)$/))) {
const paragraph = document.createElement('p');
[...cell.attributes]
// move the instrumentation from the cell to the new paragraph, also keep the class
// in case the content is a buttton and the cell the button-container
.filter(({ nodeName }) => nodeName === 'class'
|| nodeName.startsWith('data-aue')
|| nodeName.startsWith('data-richtext'))
.forEach(({ nodeName, nodeValue }) => {
paragraph.setAttribute(nodeName, nodeValue);
cell.removeAttribute(nodeName);
});
paragraph.append(...cell.childNodes);
cell.replaceChildren(paragraph);
}
});
// eslint-disable-next-line no-use-before-define
decorateButtons(block);
}
Expand Down Expand Up @@ -783,5 +751,4 @@ export {
toClassName,
updateSectionsStatus,
waitForLCP,
wrapTextNodes,
};

0 comments on commit fc73928

Please sign in to comment.