import Link from "next/link"; import { ArrowLeft } from "lucide-react"; import type { PostListItem } from "@/lib/api"; import LikeButton from "./LikeButton"; import Avatar from "./Avatar"; import { IconComment, IconEye } from "./Icons"; /** 发帖/回复时间统一为相对时间:刚刚 / N分钟前 / N小时前 / N天前 / N个月前 / N年前 */ function formatRelative(dateStr: string) { const t = new Date(dateStr).getTime(); const diff = Date.now() - t; const min = 60_000, hour = 60 * min, day = 24 * hour; if (diff < min) return "刚刚"; if (diff < hour) return `${Math.floor(diff / min)}分钟前`; if (diff < day) return `${Math.floor(diff / hour)}小时前`; if (diff < 30 * day) return `${Math.floor(diff / day)}天前`; if (diff < 365 * day) return `${Math.floor(diff / (30 * day))}个月前`; return `${Math.floor(diff / (365 * day))}年前`; } /** * 帖子列表行(参考社区信息流样式): * 大头像 + 加粗标题(徽章内联)+ 第二行「板块 · 作者 · 发布时间 ← 最后回复」+ * 右侧评论数等统计垂直居中。用于首页/板块页/搜索结果。 */ export default function PostRow({ post, boardHref, index = 0, compact = false, showViews = true, showLike = true, }: { post: PostListItem; index?: number; boardHref?: boolean; compact?: boolean; showViews?: boolean; showLike?: boolean; }) { const lastReply = post.last_reply; const replied = lastReply && new Date(lastReply.created_at).getTime() > new Date(post.created_at).getTime() + 60_000; return (
{post.pinned > 0 && 置顶} {post.recommended && 推荐}

{post.title}

{boardHref && ( {post.board.name} )} {post.user.nickname} · {formatRelative(post.created_at)} {replied && ( {lastReply!.user.nickname || lastReply!.user.username} {formatRelative(lastReply!.created_at)} )}
{post.comment_count} {showViews && ( {post.view_count} )} {showLike && ( )}
); }