Skip to content

Commit ff75388

Browse files
committed
perf: read stamps from disk instead of import.meta.glob
1 parent 31bcb03 commit ff75388

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/pages/index.astro

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
---
2+
import { readdir } from 'node:fs/promises';
3+
import path from 'node:path';
24
import BaseLayout from '../layouts/BaseLayout.astro';
35
4-
// Auto-discovers every file in public/stamps/ at build time.
5-
const stampModules = import.meta.glob('/public/stamps/*');
6-
const stamps = Object.keys(stampModules).map(path => path.replace('/public', ''));
6+
// Auto-discovers every stamp in public/stamps/ at build time.
7+
// Plain readdir instead of import.meta.glob: globbing public/ makes Vite
8+
// emit a second hashed copy of every stamp into dist/_astro/ that nothing uses.
9+
const stampDir = path.join(process.cwd(), 'public/stamps');
10+
const stampFiles = (await readdir(stampDir))
11+
.filter(f => /\.(png|gif|jpe?g|webp|avif)$/i.test(f))
12+
.sort();
13+
const stamps = stampFiles.map(f => `/stamps/${f}`);
714
815
// The seamless loop works by animating translateX(-50%) across a set rendered twice.
916
// That only works if one set is wider than the visible bar (~1300px).
1017
// So we pad the array up to at least 30 entries before doubling it.
1118
const MIN_STAMPS = 30;
12-
const copies = Math.ceil(MIN_STAMPS / stamps.length);
19+
const copies = stamps.length ? Math.ceil(MIN_STAMPS / stamps.length) : 0;
1320
const paddedStamps = Array(copies).fill(stamps).flat();
1421
---
1522

0 commit comments

Comments
 (0)