|
1 |
| -import fs from 'fs'; |
| 1 | +import { use } from 'react'; |
| 2 | +import fs from 'fs'; |
2 | 3 | import path from 'path';
|
3 | 4 | import SkyboxClient from './skybox-client';
|
4 | 5 |
|
5 |
| -// This function runs at build time to generate all possible paths |
6 | 6 | 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 })); |
12 | 10 | }
|
13 | 11 |
|
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! |
22 | 14 | }: {
|
23 |
| - params: { slug: string }; |
| 15 | + params: Promise<{ slug: string }>; |
24 | 16 | }) {
|
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 | + |
32 | 22 | return <SkyboxClient slug={slug} skyboxData={skyboxData} />;
|
33 | 23 | }
|
0 commit comments