Skip to content

Commit df1a0a4

Browse files
committed
Fix static site generation for each skybox
1 parent ba02830 commit df1a0a4

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

app/skybox/[slug]/page.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
1-
import fs from 'fs';
1+
import { use } from 'react';
2+
import fs from 'fs';
23
import path from 'path';
34
import SkyboxClient from './skybox-client';
45

5-
// This function runs at build time to generate all possible paths
66
export async function generateStaticParams() {
7-
const allPath = path.join(process.cwd(), 'public', 'data', 'index.json');
8-
const allData = JSON.parse(fs.readFileSync(allPath, 'utf8'));
9-
return Object.keys(allData).map((slug) => ({
10-
slug: slug.toString()
11-
}));
7+
const listPath = path.join(process.cwd(), 'public', 'data', 'index.json');
8+
const list = JSON.parse(fs.readFileSync(listPath, 'utf8')) as Record<string, any>;
9+
return Object.keys(list).map((slug) => ({ slug }));
1210
}
1311

14-
async function getSkyboxData(slug: string) {
15-
const dataPath = path.join(process.cwd(), 'public', 'data', `${slug}.json`);
16-
const fileContents = await fs.promises.readFile(dataPath, 'utf8');
17-
return JSON.parse(fileContents);
18-
}
19-
20-
export default async function Page({
21-
params,
12+
export default function Page({
13+
params, // 👈 promise!
2214
}: {
23-
params: { slug: string };
15+
params: Promise<{ slug: string }>;
2416
}) {
25-
const { slug } = params;
26-
const skyboxData = await getSkyboxData(slug);
27-
28-
if (!skyboxData) {
29-
return <div>Skybox not found</div>;
30-
}
31-
17+
const { slug } = use(params); // unwrap
18+
19+
const dataPath = path.join(process.cwd(), 'public', 'data', `${slug}.json`);
20+
const skyboxData = JSON.parse(fs.readFileSync(dataPath, 'utf8'));
21+
3222
return <SkyboxClient slug={slug} skyboxData={skyboxData} />;
3323
}

0 commit comments

Comments
 (0)