Skip to content

Commit

Permalink
wp
Browse files Browse the repository at this point in the history
  • Loading branch information
mokimo committed Sep 16, 2024
1 parent cb05c67 commit c71e3a0
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,38 +1221,39 @@ export function partition(arr, fn) {
);
}

async function processSection(section, config, isDoc) {
const decorateInlineFragments = async (section) => {
const inlineFrags = [...section.el.querySelectorAll('a[href*="#_inline"]')];
if (inlineFrags.length) {
const { default: loadInlineFrags } = await import('../blocks/fragment/fragment.js');
const fragPromises = inlineFrags.map((link) => loadInlineFrags(link));
await Promise.all(fragPromises);
const newlyDecoratedSection = decorateSection(section.el, section.idx);
section.blocks = newlyDecoratedSection.blocks;
section.preloadLinks = newlyDecoratedSection.preloadLinks;
}
await decoratePlaceholders(section.el, config);
if (!inlineFrags.length) return;
const { default: loadInlineFrags } = await import('../blocks/fragment/fragment.js');
const fragPromises = inlineFrags.map((link) => loadInlineFrags(link));
await Promise.all(fragPromises);
const newlyDecoratedSection = decorateSection(section.el, section.idx);
section.blocks = newlyDecoratedSection.blocks;
section.preloadLinks = newlyDecoratedSection.preloadLinks;
};

async function processSection(section, config, isDoc) {
await decorateInlineFragments(section);
const tasks = [
decoratePlaceholders(section.el, config),
decorateIcons(section.el, config),
];
if (section.classList.contains('marquee') || section.classList.contains('hero-marquee')) {
loadLink('./utils/decorate.js', { rel: 'preload', as: 'script', crossorigin: 'anonymous' });
}
if (section.preloadLinks.length) {
const [modals, nonModals] = partition(section.preloadLinks, (block) => block.classList.contains('modal'));
const preloads = nonModals.map((block) => loadBlock(block));
await Promise.all(preloads);
nonModals.forEach((block) => tasks.push(loadBlock(block)));
modals.forEach((block) => loadBlock(block));
}
section.blocks.forEach((block) => tasks.push(loadBlock(block)));

const loaded = section.blocks.map((block) => loadBlock(block));

await decorateIcons(section.el, config);

// Only move on to the next section when all blocks are loaded.
await Promise.all(loaded);
await Promise.all(tasks);

// Show the section when all blocks inside are done.
delete section.el.dataset.status;

if (isDoc && section.el.dataset.idx === '0') {
await loadPostLCP(config);
}
if (isDoc && section.el.dataset.idx === '0') await loadPostLCP(config);

delete section.el.dataset.idx;

Expand Down

0 comments on commit c71e3a0

Please sign in to comment.