import ParallaxHero from "@/app/[locale]/blog/ParallaxHero"; import TablerEyeFilled from "@/components/icons/eye"; import { Link as I18nLink, Locale, LOCALES } from "@/i18n/routing"; import { getPosts } from "@/lib/getBlogs"; import { constructMetadata } from "@/lib/metadata"; import dayjs from "dayjs"; import { Metadata } from "next"; import { getTranslations } from "next-intl/server"; type Params = Promise<{ locale: string }>; type MetadataProps = { params: Params; }; export async function generateMetadata({ params, }: MetadataProps): Promise { const { locale } = await params; const t = await getTranslations({ locale, namespace: "Blog" }); return constructMetadata({ page: "Blog", title: t("title"), description: t("description"), locale: locale as Locale, path: `/blog`, canonicalUrl: `/blog`, }); } export default async function Page({ params, // searchParams, }: { params: Params; }) { const { locale } = await params; // const resolvedSearchParams = await searchParams; // const category = resolvedSearchParams.category as string || ""; let { posts } = await getPosts(locale); const t = await getTranslations("Blog"); // const pageRaw = resolvedSearchParams.page as string || "1"; // const page = Math.max(1, parseInt(10, 10)); const page = 1; const pageSize = 10; const totalPages = Math.max(1, Math.ceil(posts.length / pageSize)); const start = (page - 1) * pageSize; const end = start + pageSize; const pagePosts = posts.slice(start, end); return (
{/* 顶部操作区:标签 + 面包屑 */}
{/*
*/}
首页 / 新闻中心
{/* 列表 */}
{pagePosts.map((post) => { const year = dayjs(post.date).format("YYYY"); const monthDay = dayjs(post.date).format("MM-DD"); const views = (post.metadata?.views as number) || 0; return (
{post.title}
访问量:{views}
{year}
{monthDay}
); })}
{"<"} {(() => { const items: (number | string)[] = []; const showTotal = totalPages; const maxNumbers = 4; const startNum = 1; const endNum = Math.min(showTotal, maxNumbers); for (let n = startNum; n <= endNum; n++) items.push(n); if (showTotal > maxNumbers + 1) items.push("..."); if (showTotal > maxNumbers) items.push(showTotal); return items.map((it, idx) => { if (typeof it === "string") return ( {it} ); const isActive = it === page; return ( {it} ); }); })()} {">"} 跳往
); } export async function generateStaticParams() { return LOCALES.map((locale) => ({ locale })); }