feat: 重构导航和博客系统,支持多级菜单和API数据源
- 重构导航菜单支持多级子菜单结构 - 博客系统改为从API获取数据,移除本地文件存储 - 删除旧的关于页面,准备重构 - 修复博客详情页slug匹配问题 - 默认首页重定向到中文版本
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user