Spaces:
Build error
Build error
Xianbao QIAN
commited on
Commit
·
836ccb6
1
Parent(s):
d686f2c
add some basic examples
Browse files- content/data.json +21 -0
- src/app/layout.tsx +1 -1
- src/app/page.tsx +40 -96
content/data.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "test data",
|
| 3 |
+
"description": "test data",
|
| 4 |
+
"data": [
|
| 5 |
+
{
|
| 6 |
+
"title": "test data",
|
| 7 |
+
"description": "test data",
|
| 8 |
+
"data": []
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"title": "test data2",
|
| 12 |
+
"description": "test data2",
|
| 13 |
+
"data": []
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"title": "test data3",
|
| 17 |
+
"description": "test data3",
|
| 18 |
+
"data": []
|
| 19 |
+
}
|
| 20 |
+
]
|
| 21 |
+
}
|
src/app/layout.tsx
CHANGED
|
@@ -24,7 +24,7 @@ export default function RootLayout({
|
|
| 24 |
children: React.ReactNode;
|
| 25 |
}>) {
|
| 26 |
return (
|
| 27 |
-
<html lang="en">
|
| 28 |
<body
|
| 29 |
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
| 30 |
>
|
|
|
|
| 24 |
children: React.ReactNode;
|
| 25 |
}>) {
|
| 26 |
return (
|
| 27 |
+
<html lang="en" className="bg-white dark:bg-gray-900">
|
| 28 |
<body
|
| 29 |
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
| 30 |
>
|
src/app/page.tsx
CHANGED
|
@@ -1,101 +1,45 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
export default function Home() {
|
| 4 |
return (
|
| 5 |
-
<
|
| 6 |
-
<
|
| 7 |
-
|
| 8 |
-
className="dark:invert"
|
| 9 |
-
src="https://nextjs.org/icons/next.svg"
|
| 10 |
-
alt="Next.js logo"
|
| 11 |
-
width={180}
|
| 12 |
-
height={38}
|
| 13 |
-
priority
|
| 14 |
-
/>
|
| 15 |
-
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
|
| 16 |
-
<li className="mb-2">
|
| 17 |
-
Get started by editing{" "}
|
| 18 |
-
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
|
| 19 |
-
src/app/page.tsx
|
| 20 |
-
</code>
|
| 21 |
-
.
|
| 22 |
-
</li>
|
| 23 |
-
<li>Save and see your changes instantly.</li>
|
| 24 |
-
</ol>
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
|
| 44 |
-
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
| 45 |
-
target="_blank"
|
| 46 |
-
rel="noopener noreferrer"
|
| 47 |
-
>
|
| 48 |
-
Read our docs
|
| 49 |
-
</a>
|
| 50 |
-
</div>
|
| 51 |
-
</main>
|
| 52 |
-
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
|
| 53 |
-
<a
|
| 54 |
-
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
| 55 |
-
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
| 56 |
-
target="_blank"
|
| 57 |
-
rel="noopener noreferrer"
|
| 58 |
-
>
|
| 59 |
-
<Image
|
| 60 |
-
aria-hidden
|
| 61 |
-
src="https://nextjs.org/icons/file.svg"
|
| 62 |
-
alt="File icon"
|
| 63 |
-
width={16}
|
| 64 |
-
height={16}
|
| 65 |
-
/>
|
| 66 |
-
Learn
|
| 67 |
-
</a>
|
| 68 |
-
<a
|
| 69 |
-
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
| 70 |
-
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
| 71 |
-
target="_blank"
|
| 72 |
-
rel="noopener noreferrer"
|
| 73 |
-
>
|
| 74 |
-
<Image
|
| 75 |
-
aria-hidden
|
| 76 |
-
src="https://nextjs.org/icons/window.svg"
|
| 77 |
-
alt="Window icon"
|
| 78 |
-
width={16}
|
| 79 |
-
height={16}
|
| 80 |
-
/>
|
| 81 |
-
Examples
|
| 82 |
-
</a>
|
| 83 |
-
<a
|
| 84 |
-
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
|
| 85 |
-
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
| 86 |
-
target="_blank"
|
| 87 |
-
rel="noopener noreferrer"
|
| 88 |
-
>
|
| 89 |
-
<Image
|
| 90 |
-
aria-hidden
|
| 91 |
-
src="https://nextjs.org/icons/globe.svg"
|
| 92 |
-
alt="Globe icon"
|
| 93 |
-
width={16}
|
| 94 |
-
height={16}
|
| 95 |
-
/>
|
| 96 |
-
Go to nextjs.org →
|
| 97 |
-
</a>
|
| 98 |
-
</footer>
|
| 99 |
-
</div>
|
| 100 |
);
|
| 101 |
}
|
|
|
|
| 1 |
+
import fs from 'fs';
|
| 2 |
+
import path from 'path';
|
| 3 |
+
|
| 4 |
+
type DataItem = {
|
| 5 |
+
title: string;
|
| 6 |
+
description: string;
|
| 7 |
+
data: any[];
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
type Data = {
|
| 11 |
+
title: string;
|
| 12 |
+
description: string;
|
| 13 |
+
data: DataItem[];
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
export default async function Home() {
|
| 17 |
+
// Read the JSON file
|
| 18 |
+
const jsonDirectory = path.join(process.cwd(), 'content');
|
| 19 |
+
const fileContents = await fs.readFileSync(jsonDirectory + '/data.json', 'utf8');
|
| 20 |
+
const data: Data = JSON.parse(fileContents);
|
| 21 |
|
|
|
|
| 22 |
return (
|
| 23 |
+
<main className="container mx-auto py-8 text-gray-900 dark:text-white">
|
| 24 |
+
<h1 className="text-4xl font-bold mb-4">{data.title}</h1>
|
| 25 |
+
<p className="text-xl mb-8">{data.description}</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
<table className="table-auto border-collapse w-full">
|
| 28 |
+
<thead>
|
| 29 |
+
<tr>
|
| 30 |
+
<th className="px-4 py-2 bg-gray-100 dark:bg-gray-800 text-left">Title</th>
|
| 31 |
+
<th className="px-4 py-2 bg-gray-100 dark:bg-gray-800 text-left">Description</th>
|
| 32 |
+
</tr>
|
| 33 |
+
</thead>
|
| 34 |
+
<tbody>
|
| 35 |
+
{data.data.map((item: DataItem, index: number) => (
|
| 36 |
+
<tr key={index} className="border-t border-gray-200 dark:border-gray-700">
|
| 37 |
+
<td className="px-4 py-2">{item.title}</td>
|
| 38 |
+
<td className="px-4 py-2">{item.description}</td>
|
| 39 |
+
</tr>
|
| 40 |
+
))}
|
| 41 |
+
</tbody>
|
| 42 |
+
</table>
|
| 43 |
+
</main>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
);
|
| 45 |
}
|