Skip to content

Commit 7444fec

Browse files
committed
feat: add root layout and enhance home page with i18n support
- Introduced a new RootLayout component for global layout structure. - Updated HomePage to support internationalization with dynamic text based on language. - Removed obsolete test documentation file.
1 parent 8e5d1be commit 7444fec

File tree

4 files changed

+47
-35
lines changed

4 files changed

+47
-35
lines changed

app/[lang]/(home)/page.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
import Link from 'next/link';
22
import { source } from '@/lib/source';
33

4-
export default function HomePage() {
5-
const blogs = source.getPages();
4+
// i18n文本
5+
const texts = {
6+
en: {
7+
noBlogsMessage: "No blog posts yet"
8+
},
9+
zh: {
10+
noBlogsMessage: "暂时还没有博客文章"
11+
}
12+
} as const;
13+
14+
export default async function HomePage({
15+
params,
16+
}: {
17+
params: Promise<{ lang: string }>;
18+
}) {
19+
const lang = (await params).lang as keyof typeof texts;
20+
// 获取指定语言的页面
21+
const blogs = source.getPages(lang);
22+
const t = texts[lang] || texts.en;
623

724
return (
825
<main className="flex flex-1 flex-col px-6 py-8">
926
<div className="max-w-6xl mx-auto w-full">
1027

1128
{blogs.length === 0 ? (
1229
<p className="text-fd-muted-foreground">
13-
暂时还没有博客文章
30+
{t.noBlogsMessage}
1431
</p>
1532
) : (
1633
<div className="grid md:grid-cols-2 gap-8 md:gap-12">
@@ -22,7 +39,7 @@ export default function HomePage() {
2239
>
2340
<article>
2441
<h2 className="text-2xl font-semibold text-fd-foreground">
25-
{blog.data.title || '无标题'}
42+
{blog.data.title || (lang === 'zh' ? '无标题' : 'Untitled')}
2643
</h2>
2744

2845
{blog.data.description && (

app/[lang]/layout.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const locales = [
1919
},
2020
];
2121

22-
export default async function RootLayout({
22+
export default async function Layout({
2323
params,
2424
children,
2525
}: {
@@ -29,18 +29,14 @@ export default async function RootLayout({
2929
const lang = (await params).lang;
3030

3131
return (
32-
<html lang={lang}>
33-
<body>
34-
<RootProvider
35-
i18n={{
36-
locale: lang,
37-
locales,
38-
translations: { cn }[lang],
39-
}}
40-
>
41-
{children}
42-
</RootProvider>
43-
</body>
44-
</html>
32+
<RootProvider
33+
i18n={{
34+
locale: lang,
35+
locales,
36+
translations: { cn }[lang],
37+
}}
38+
>
39+
{children}
40+
</RootProvider>
4541
);
4642
}

app/layout.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import './global.css';
2+
import type { ReactNode } from 'react';
3+
4+
export default function RootLayout({
5+
children,
6+
}: {
7+
children: ReactNode;
8+
}) {
9+
return (
10+
<html suppressHydrationWarning>
11+
<body>
12+
{children}
13+
</body>
14+
</html>
15+
);
16+
}

content/docs/test.mdx

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)