Skip to content

Commit 67fe2ff

Browse files
committed
Pre-build step for images
This sets up the rework the image retrieval for the Modals and pages.
1 parent 2243ab9 commit 67fe2ff

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ yarn-error.log*
4040
*.tsbuildinfo
4141
next-env.d.ts
4242
public/data/index.json
43+
public/data/skyboxManifest.json

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"private": true,
55
"scripts": {
66
"prepare-data": "node scripts/generate-index.js",
7-
"dev": "npm run prepare-data && next dev --turbopack",
8-
"prebuild": "npm run prepare-data",
7+
"prepare-skybox-manifest": "node scripts/generate-skybox-manifest.js",
8+
"dev": "npm run prepare-data && npm run prepare-skybox-manifest && next dev --turbopack",
9+
"prebuild": "npm run prepare-data && npm run prepare-skybox-manifest",
910
"build": "next build",
1011
"start": "next start",
1112
"lint": "next lint"

scripts/generate-skybox-manifest.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const rootDir = path.join(__dirname, '..');
5+
const skyboxDir = path.join(rootDir, 'public', 'skyboxes');
6+
const outFile = path.join(rootDir, 'public', 'data', 'skyboxManifest.json');
7+
8+
if (!fs.existsSync(skyboxDir)) {
9+
console.error('❌ Skybox directory not found:', skyboxDir);
10+
process.exit(1);
11+
}
12+
13+
const slugs = fs.readdirSync(skyboxDir).filter((name) =>
14+
fs.statSync(path.join(skyboxDir, name)).isDirectory()
15+
);
16+
17+
const manifest = slugs.map((slug) => {
18+
const previewsPath = path.join(skyboxDir, slug, 'images', 'previews');
19+
if (!fs.existsSync(previewsPath)) {
20+
console.warn(`⚠️ No preview folder for ${slug}`);
21+
return { slug, previewCount: 0, previews: [] };
22+
}
23+
24+
const files = fs
25+
.readdirSync(previewsPath)
26+
.filter((f) => /\.(png|jpe?g|webp|avif)$/i.test(f))
27+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
28+
29+
return {
30+
slug,
31+
previewCount: files.length,
32+
previews: files,
33+
};
34+
});
35+
36+
fs.writeFileSync(outFile, JSON.stringify(manifest, null, 2));
37+
console.log(`✅ Wrote manifest with ${manifest.length} skyboxes → ${outFile}`);

0 commit comments

Comments
 (0)