Skip to content

Commit f3eecb1

Browse files
committed
feat(blog): enhance blog metadata and internationalization support
- Added keywords, date, and author fields to blog metadata for improved SEO and content management. - Updated multilingual support in the home page to display author and date information. - Enhanced layout to accommodate new metadata fields and improve user experience.
1 parent 5e231be commit f3eecb1

File tree

4 files changed

+209
-127
lines changed

4 files changed

+209
-127
lines changed

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

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,59 @@ import { source } from '@/lib/source';
44
// i18n文本
55
const texts = {
66
en: {
7-
noBlogsMessage: "No blog posts yet"
7+
noBlogsMessage: "No blog posts yet",
8+
by: "By",
9+
on: "on"
810
},
911
'zh-Hans': {
10-
noBlogsMessage: "暂时还没有博客文章"
12+
noBlogsMessage: "暂时还没有博客文章",
13+
by: "作者",
14+
on: "发布于"
1115
},
1216
'zh-Hant': {
13-
noBlogsMessage: "暫時還沒有部落格文章"
17+
noBlogsMessage: "暫時還沒有部落格文章",
18+
by: "作者",
19+
on: "發布於"
1420
},
1521
ja: {
16-
noBlogsMessage: "まだブログ記事がありません"
22+
noBlogsMessage: "まだブログ記事がありません",
23+
by: "著者",
24+
on: "投稿日"
1725
},
1826
fr: {
19-
noBlogsMessage: "Aucun article de blog pour le moment"
27+
noBlogsMessage: "Aucun article de blog pour le moment",
28+
by: "Par",
29+
on: "le"
2030
},
2131
es: {
22-
noBlogsMessage: "Aún no hay publicaciones en el blog"
32+
noBlogsMessage: "Aún no hay publicaciones en el blog",
33+
by: "Por",
34+
on: "el"
2335
},
2436
pt: {
25-
noBlogsMessage: "Ainda não há postagens no blog"
37+
noBlogsMessage: "Ainda não há postagens no blog",
38+
by: "Por",
39+
on: "em"
2640
},
2741
ko: {
28-
noBlogsMessage: "아직 블로그 글이 없습니다"
42+
noBlogsMessage: "아직 블로그 글이 없습니다",
43+
by: "작성자",
44+
on: "작성일"
2945
},
3046
ms: {
31-
noBlogsMessage: "Belum ada catatan blog lagi"
47+
noBlogsMessage: "Belum ada catatan blog lagi",
48+
by: "Oleh",
49+
on: "pada"
3250
},
3351
id: {
34-
noBlogsMessage: "Belum ada postingan blog"
52+
noBlogsMessage: "Belum ada postingan blog",
53+
by: "Oleh",
54+
on: "pada"
3555
},
3656
ru: {
37-
noBlogsMessage: "Пока нет записей в блоге"
57+
noBlogsMessage: "Пока нет записей в блоге",
58+
by: "Автор",
59+
on: "опубликовано"
3860
}
3961
} as const;
4062

@@ -45,7 +67,23 @@ export default async function HomePage({
4567
}) {
4668
const lang = (await params).lang as keyof typeof texts;
4769
// 获取指定语言的页面
48-
const blogs = source.getPages(lang);
70+
const allBlogs = source.getPages(lang);
71+
72+
// 按日期排序,新的在前(降序)
73+
const blogs = allBlogs.sort((a, b) => {
74+
const dateA = a.data.date;
75+
const dateB = b.data.date;
76+
77+
// 如果两个都没有日期,保持原有顺序
78+
if (!dateA && !dateB) return 0;
79+
// 没有日期的放在后面
80+
if (!dateA) return 1;
81+
if (!dateB) return -1;
82+
83+
// 按日期降序排列(新的在前)
84+
return dateB.getTime() - dateA.getTime();
85+
});
86+
4987
const t = texts[lang] || texts.en;
5088

5189
return (
@@ -62,18 +100,53 @@ export default async function HomePage({
62100
<Link
63101
key={blog.url}
64102
href={blog.url}
65-
className="block space-y-3 pb-8"
103+
className="block space-y-3 pb-8 border-b border-fd-border last:border-b-0"
66104
>
67-
<article>
68-
<h2 className="text-2xl font-semibold text-fd-foreground">
105+
<article className="space-y-3">
106+
<h2 className="text-2xl font-semibold text-fd-foreground hover:text-fd-primary transition-colors">
69107
{blog.data.title || (lang === 'zh-Hans' ? '无标题' : 'Untitled')}
70108
</h2>
71109

110+
{/* 作者和日期信息 */}
111+
{(blog.data.author || blog.data.date) && (
112+
<div className="flex items-center gap-4 text-sm text-fd-muted-foreground">
113+
{blog.data.author && (
114+
<span className="flex items-center gap-1">
115+
{t.by} {blog.data.author}
116+
</span>
117+
)}
118+
{blog.data.date && (
119+
<span className="flex items-center gap-1">
120+
{t.on} {blog.data.date.toLocaleDateString()}
121+
</span>
122+
)}
123+
</div>
124+
)}
125+
72126
{blog.data.description && (
73127
<p className="text-fd-muted-foreground leading-relaxed">
74128
{blog.data.description}
75129
</p>
76130
)}
131+
132+
{/* 关键词标签 */}
133+
{blog.data.keywords && (
134+
<div className="flex flex-wrap gap-2 mt-3">
135+
{blog.data.keywords.split(',').slice(0, 5).map((keyword, index) => (
136+
<span
137+
key={index}
138+
className="px-2 py-1 bg-fd-secondary text-fd-secondary-foreground text-xs rounded-md"
139+
>
140+
{keyword.trim()}
141+
</span>
142+
))}
143+
{blog.data.keywords.split(',').length > 5 && (
144+
<span className="px-2 py-1 text-fd-muted-foreground text-xs">
145+
+{blog.data.keywords.split(',').length - 5}
146+
</span>
147+
)}
148+
</div>
149+
)}
77150
</article>
78151
</Link>
79152
))}

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@
99
"postinstall": "fumadocs-mdx"
1010
},
1111
"dependencies": {
12+
"fumadocs-core": "15.5.4",
13+
"fumadocs-mdx": "11.6.9",
14+
"fumadocs-ui": "15.5.4",
1215
"next": "15.3.4",
1316
"react": "^19.1.0",
1417
"react-dom": "^19.1.0",
15-
"fumadocs-ui": "15.5.4",
16-
"fumadocs-core": "15.5.4",
17-
"fumadocs-mdx": "11.6.9"
18+
"zod": "^3.25.67"
1819
},
1920
"devDependencies": {
21+
"@tailwindcss/postcss": "^4.1.10",
22+
"@types/mdx": "^2.0.13",
2023
"@types/node": "24.0.3",
2124
"@types/react": "^19.1.8",
2225
"@types/react-dom": "^19.1.6",
23-
"typescript": "^5.8.3",
24-
"@types/mdx": "^2.0.13",
25-
"@tailwindcss/postcss": "^4.1.10",
26-
"tailwindcss": "^4.1.10",
27-
"postcss": "^8.5.6",
2826
"eslint": "^8",
29-
"eslint-config-next": "15.3.4"
27+
"eslint-config-next": "15.3.4",
28+
"postcss": "^8.5.6",
29+
"tailwindcss": "^4.1.10",
30+
"typescript": "^5.8.3"
3031
}
3132
}

0 commit comments

Comments
 (0)