diff --git a/scripts/build-bundle-mosaics.mjs b/scripts/build-bundle-mosaics.mjs index de26690..d4d516c 100644 --- a/scripts/build-bundle-mosaics.mjs +++ b/scripts/build-bundle-mosaics.mjs @@ -23,7 +23,7 @@ const TILE = 598; const GAP = 4; const FULL = TILE * 2 + GAP; // 1200 const BG = { r: 224, g: 219, b: 210, alpha: 1 }; // matches light --rule -const HERO_EXTS = ['jpg', 'jpeg', 'png', 'webp', 'gif']; +const HERO_EXTS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'avif']; function parseItems(frontmatter) { const lines = frontmatter.split('\n'); @@ -46,9 +46,28 @@ async function readFrontmatter(path) { return m ? m[1] : ''; } +// Finds live at find//// (slugs globally unique). +// Index them once so hero lookup stays O(1) per slug. +let findDirIndex = null; +async function buildFindDirIndex() { + const index = new Map(); + const years = (await readdir(FIND_DIR, { withFileTypes: true })).filter((d) => d.isDirectory()); + for (const year of years) { + const yearDir = join(FIND_DIR, year.name); + const months = (await readdir(yearDir, { withFileTypes: true })).filter((d) => d.isDirectory()); + for (const month of months) { + const monthDir = join(yearDir, month.name); + const slugs = (await readdir(monthDir, { withFileTypes: true })).filter((d) => d.isDirectory()); + for (const slug of slugs) index.set(slug.name, join(monthDir, slug.name)); + } + } + return index; +} + async function findHeroPath(slug) { - const dir = join(FIND_DIR, slug); - if (!existsSync(dir)) return null; + if (!findDirIndex) findDirIndex = await buildFindDirIndex(); + const dir = findDirIndex.get(slug); + if (!dir) return null; const entries = await readdir(dir); for (const ext of HERO_EXTS) { const file = entries.find((e) => e.toLowerCase() === `hero.${ext}`);