Skip to content

Commit

Permalink
Update utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
suhjainadobe authored Aug 8, 2024
1 parent f36fea1 commit c58c02c
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,27 +724,10 @@ async function decorateIcons(area, config) {
async function decoratePlaceholders(area, config) {
const el = area.querySelector('main') || area;
const regex = /{{(.*?)}}|%7B%7B(.*?)%7D%7D/g;
const walker = document.createTreeWalker(
el,
NodeFilter.SHOW_TEXT,
{
acceptNode(node) {
return regex.test(node.nodeValue) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
},
},
);
const nodes = [];
let node = walker.nextNode();
while (node !== null) {
nodes.push(node);
node = walker.nextNode();
}
if (!nodes.length) return;
const found = regex.test(el.innerHTML);
if (!found) return;
const { replaceText } = await import('../features/placeholders.js');
const replaceNodes = nodes.map(async (textNode) => {
textNode.nodeValue = await replaceText(textNode.nodeValue, config, regex);
});
await Promise.all(replaceNodes);
el.innerHTML = await replaceText(el.innerHTML, config, regex);
}

async function loadFooter() {
Expand Down

0 comments on commit c58c02c

Please sign in to comment.