feat: 重构导航和博客系统,支持多级菜单和API数据源

- 重构导航菜单支持多级子菜单结构
- 博客系统改为从API获取数据,移除本地文件存储
- 删除旧的关于页面,准备重构
- 修复博客详情页slug匹配问题
- 默认首页重定向到中文版本
This commit is contained in:
砂糖
2025-11-21 17:49:17 +08:00
parent 0a420f2dbb
commit 216076ff2a
13 changed files with 178 additions and 222 deletions

View File

@@ -1,5 +0,0 @@
export default function Page() {
return (
<div className="container mx-auto px-4 py-12"></div>
);
}

View File

@@ -1,5 +0,0 @@
export default function Page() {
return (
<div className="container mx-auto px-4 py-12"></div>
);
}

View File

@@ -1,5 +0,0 @@
export default function Page() {
return (
<div className="container mx-auto px-4 py-12"></div>
);
}

View File

@@ -1,5 +0,0 @@
export default function Page() {
return (
<div className="container mx-auto px-4 py-12">绿</div>
);
}

View File

@@ -1,5 +0,0 @@
export default function Page() {
return (
<div className="container mx-auto px-4 py-12"></div>
);
}

View File

@@ -1,5 +0,0 @@
export default function Page() {
return (
<div className="container mx-auto px-4 py-12"></div>
);
}

View File

@@ -22,8 +22,9 @@ export async function generateMetadata({
}: MetadataProps): Promise<Metadata> {
const { locale, slug } = await params;
let { posts }: { posts: BlogPost[] } = await getPosts(locale);
const post = posts.find((post) => post.slug === "/" + slug);
const post = posts.find((post) => post.slug === slug);
console.log(post, posts);
if (!post) {
return constructMetadata({
title: "404",
@@ -50,7 +51,7 @@ export default async function BlogPage({ params }: { params: Params }) {
const { locale, slug } = await params;
let { posts }: { posts: BlogPost[] } = await getPosts(locale);
const post = posts.find((item) => item.slug === "/" + slug);
const post = posts.find((item) => item.slug === slug);
if (!post) {
return notFound();

View File

@@ -9,7 +9,7 @@ import { getTranslations } from "next-intl/server";
type Params = Promise<{ locale: string }>;
type SearchParams = { page?: string; type?: string };
type SearchParams = { page?: string; category?: string };
type MetadataProps = {
params: Params;
@@ -36,34 +36,18 @@ export default async function Page({
searchParams,
}: {
params: Params;
searchParams?: SearchParams;
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
const { locale } = await params;
let { posts } = await getPosts(locale);
const resolvedSearchParams = await searchParams;
const category = resolvedSearchParams.category as string || "";
let { posts } = await getPosts(locale, category);
const t = await getTranslations("Blog");
// 分类筛选(公司新闻/专家访谈/行业动态/公告)
const type = (searchParams?.type || "").toLowerCase();
const typeLabelMap: Record<string, string> = {
company: "公司新闻",
experts: "专家访谈",
industry: "行业动态",
notice: "公告",
};
const typeLabel = typeLabelMap[type];
if (type) {
posts = posts.filter((p) => {
const metaType = String((p.metadata as any)?.type || "").toLowerCase();
const tags: string[] = (p.tags as any) || [];
const hitMeta = metaType === type;
const hitTag = Array.isArray(tags) && tags.some((t) => String(t).toLowerCase() === type);
return hitMeta || hitTag;
});
}
const pageRaw = searchParams?.page;
const page = Math.max(1, parseInt(pageRaw || "1", 10));
const pageRaw = resolvedSearchParams.page as string || "1";
const page = Math.max(1, parseInt(pageRaw, 10));
const pageSize = 10;
const totalPages = Math.max(1, Math.ceil(posts.length / pageSize));
const start = (page - 1) * pageSize;
@@ -77,14 +61,14 @@ export default async function Page({
{/* 顶部操作区:标签 + 面包屑 */}
<div className="container mx-auto px-4">
<div className="flex flex-col md:flex-row md:items-center md:justify-between gap-4 mt-4">
<div className="flex gap-3">
{/* <div className="flex gap-3">
<button className="px-4 py-2 rounded-md border bg-white text-gray-700 shadow-sm hover:bg-gray-50">
投资者保护
</button>
<button className="px-4 py-2 rounded-md border bg-white text-gray-700 shadow-sm hover:bg-gray-50">
公司公告
</button>
</div>
</div> */}
<div className="flex items-center gap-2 text-sm text-gray-500">
<I18nLink href="/" prefetch={false} className="hover:underline">
@@ -93,12 +77,12 @@ export default async function Page({
<I18nLink href="/blog" prefetch={false} className="hover:underline">
</I18nLink>
{typeLabel && (
{/* {typeLabel && (
<>
<span>/</span>
<span className="text-gray-700">{typeLabel}</span>
</>
)}
)} */}
</div>
</div>
@@ -111,7 +95,7 @@ export default async function Page({
return (
<I18nLink
key={post.slug}
href={`/blog${post.slug}`}
href={`/blog/${post.slug}`}
prefetch={false}
className="block rounded-md mb-4 bg-gray-100 px-6 py-5 transition-all duration-200 shadow hover:bg-gray-200 hover:translate-y-[1px] hover:shadow-inner active:translate-y-[2px] active:shadow-inner focus:outline-none focus:ring-1 focus:ring-gray-300"
>
@@ -139,9 +123,8 @@ export default async function Page({
<I18nLink
href={`/blog?page=${Math.max(1, page - 1)}`}
prefetch={false}
className={`px-2.5 py-1 border rounded-sm text-sm ${
page === 1 ? "bg-gray-100 text-gray-400" : "bg-white hover:bg-gray-50"
}`}
className={`px-2.5 py-1 border rounded-sm text-sm ${page === 1 ? "bg-gray-100 text-gray-400" : "bg-white hover:bg-gray-50"
}`}
>
{"<"}
</I18nLink>
@@ -167,11 +150,10 @@ export default async function Page({
key={it}
href={`/blog?page=${it}`}
prefetch={false}
className={`px-2.5 py-1 border rounded-sm text-sm ${
isActive
? "bg-red-600 text-white border-red-600"
: "bg-white hover:bg-gray-50"
}`}
className={`px-2.5 py-1 border rounded-sm text-sm ${isActive
? "bg-red-600 text-white border-red-600"
: "bg-white hover:bg-gray-50"
}`}
>
{it}
</I18nLink>
@@ -181,9 +163,8 @@ export default async function Page({
<I18nLink
href={`/blog?page=${Math.min(totalPages, page + 1)}`}
prefetch={false}
className={`px-2.5 py-1 border rounded-sm text-sm ${
page === totalPages ? "bg-gray-100 text-gray-400" : "bg-white hover:bg-gray-50"
}`}
className={`px-2.5 py-1 border rounded-sm text-sm ${page === totalPages ? "bg-gray-100 text-gray-400" : "bg-white hover:bg-gray-50"
}`}
>
{">"}
</I18nLink>

6
app/page.tsx Normal file
View File

@@ -0,0 +1,6 @@
// 默认跳转到中文版本
import { redirect } from 'next/navigation';
export default function HomePage() {
redirect('/zh');
}