feat: 新增站点公告系统与多项体验优化
此提交完成了以下核心功能与优化: 1. 新增站点公告全流程支持:包含公告模型、CRUD接口、管理后台页面、公告详情页与首页展示 2. 实现评论楼层化与回复嵌套:重构评论系统为树状结构,支持回复评论与层级限制 3. 添加用户在线状态追踪:异步更新用户最后活跃时间并做SQL限频 4. 优化用户体验:移动端浮动操作条、统一板块标签样式、用户页签到积分展示、注册即登录优化 5. 其他细节优化:SEO站点地图新增公告页、评论分页与统计、登录/注册表单增强等
This commit is contained in:
99
frontend/app/announcement/[id]/page.tsx
Normal file
99
frontend/app/announcement/[id]/page.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import { ChevronRight, Megaphone } from "lucide-react";
|
||||
import { fetchAnnouncementDetail } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/format";
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{ id: string }>;
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const data = await fetchAnnouncementDetail(id).catch(() => null);
|
||||
if (!data) return { title: "公告不存在" };
|
||||
return {
|
||||
title: data.announcement.title,
|
||||
description: `站点公告 · ${data.announcement.tag}`,
|
||||
openGraph: {
|
||||
title: data.announcement.title,
|
||||
description: `站点公告 · ${data.announcement.tag}`,
|
||||
type: "article",
|
||||
publishedTime: data.announcement.created_at,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function AnnouncementPage({ params }: PageProps) {
|
||||
const { id } = await params;
|
||||
const data = await fetchAnnouncementDetail(id).catch(() => null);
|
||||
if (!data) notFound();
|
||||
|
||||
const a = data.announcement;
|
||||
const jsonLd = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Article",
|
||||
headline: a.title,
|
||||
datePublished: a.created_at,
|
||||
dateModified: a.updated_at,
|
||||
articleSection: "站点公告",
|
||||
keywords: a.tag,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="max-w-3xl mx-auto">
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
||||
/>
|
||||
|
||||
{/* 面包屑 */}
|
||||
<nav className="meta mb-5 flex items-center gap-1.5 text-[13px]">
|
||||
<Link href="/" className="hover:text-[var(--accent)] transition-colors">
|
||||
首页
|
||||
</Link>
|
||||
<ChevronRight size={13} />
|
||||
<span style={{ color: "var(--accent)" }}>站点公告</span>
|
||||
</nav>
|
||||
|
||||
<article className="panel p-6 sm:p-8">
|
||||
<div className="flex items-center justify-between gap-3 flex-wrap">
|
||||
<span className={`j13-anno-tag is-${a.tag_color}`}>{a.tag}</span>
|
||||
<time className="meta text-[12px] tabular-nums" dateTime={a.created_at}>
|
||||
{formatDate(a.created_at)}
|
||||
</time>
|
||||
</div>
|
||||
|
||||
<h1
|
||||
className="mt-3.5 text-[24px] sm:text-[28px] font-extrabold leading-snug tracking-tight"
|
||||
style={{ color: "var(--ink)" }}
|
||||
>
|
||||
{a.title}
|
||||
</h1>
|
||||
|
||||
<div
|
||||
className="mt-5 pt-5"
|
||||
style={{ borderTop: "1px solid var(--line)" }}
|
||||
>
|
||||
<div className="prose-content">
|
||||
<ReactMarkdown>{a.content}</ReactMarkdown>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<div className="mt-5 flex items-center gap-2 text-[12.5px] meta">
|
||||
<Megaphone size={14} style={{ color: "var(--accent)" }} />
|
||||
<span>由站点管理团队发布</span>
|
||||
<Link
|
||||
href="/"
|
||||
className="ml-auto font-semibold transition-colors hover:text-[var(--accent)]"
|
||||
style={{ color: "var(--accent)" }}
|
||||
>
|
||||
返回首页
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user