From 623f565307f7e972e11adff7c321c6deb119a0e1 Mon Sep 17 00:00:00 2001 From: rzen Date: Fri, 3 Jul 2026 15:44:15 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20bundle=20mosaics=20broken=20since=20find?= =?UTF-8?q?=20date-bucketing=20=E2=80=94=20index=20find///?= =?UTF-8?q?=20paths,=20add=20avif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generator still resolved heroes at the old flat src/content/find// path, so every mosaic was skipped as 'no heroes' and src/generated/ bundle-mosaics sat empty. Home-page bundle tiles have been mosaic-less since the May migration. --- scripts/build-bundle-mosaics.mjs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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}`);