import type { ReactNode } from "react"; import { Clock } from "lucide-react"; import { formatDate } from "@/lib/format"; function formatDateTime(dateStr: string) { return new Date(dateStr).toLocaleString("zh-CN", { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", }); } /** 公文头:kicker / 标签 / 大标题 / 导语 / 元信息 */ export default function SiteDocMasthead({ kicker, title, excerpt, createdAt, updatedAt, readingMinutes, badges, showTimeOfDay = false, }: { kicker: string; title: string; excerpt?: string; createdAt: string; updatedAt?: string; readingMinutes?: number; badges?: ReactNode; /** 详情页用完整日期时间;列表头图可用短日期 */ showTimeOfDay?: boolean; }) { const edited = updatedAt && new Date(updatedAt).getTime() - new Date(createdAt).getTime() > 60_000; const publishedLabel = showTimeOfDay ? formatDateTime(createdAt) : formatDate(createdAt); const updatedLabel = edited && updatedAt ? showTimeOfDay ? formatDateTime(updatedAt) : formatDate(updatedAt) : null; return (
{kicker} {badges}

{title}

{excerpt ? (

{excerpt}

) : null}

发布于 {publishedLabel} {updatedLabel ? <> · 更新于 {updatedLabel} : null}

{readingMinutes != null ? ( 约 {readingMinutes} 分钟读完 ) : null}
); }