fix: bundle mosaics broken since find date-bucketing — index find/<yyyy>/<mm>/<slug> paths, add avif
The generator still resolved heroes at the old flat src/content/find/<slug>/ 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.
This commit is contained in:
@@ -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/<year>/<month>/<slug>/ (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}`);
|
||||
|
||||
Reference in New Issue
Block a user