import Link from "next/link"; import { PenSquare, LogIn, UserPlus, MessagesSquare, Users, MessageCircle, Sparkles } from "lucide-react"; import type { OverviewStats } from "@/lib/api"; type HeroUser = { username: string; nickname: string } | null; function greetingOf(h: number): string { if (h >= 5 && h < 11) return "早上好"; if (h >= 11 && h < 14) return "中午好"; if (h >= 14 && h < 18) return "下午好"; if (h >= 18 && h < 23) return "晚上好"; return "夜深了"; } // 首页欢迎横幅:时段问候 + 站点主张 + 发帖引导 + 内联社区数据。纯服务端组件。 export default function HomeHero({ user, stats }: { user: HeroUser; stats: OverviewStats | null }) { const name = user ? user.nickname || user.username : null; const hello = greetingOf(new Date().getHours()); const today = stats?.today_posts ?? 0; const statItems = stats ? [ { icon: MessagesSquare, label: "讨论", value: stats.posts, hot: false }, { icon: Users, label: "成员", value: stats.users, hot: false }, { icon: MessageCircle, label: "评论", value: stats.comments, hot: false }, { icon: Sparkles, label: today > 0 ? "今日新帖" : "今日", value: today, hot: today > 0 }, ] : []; return (

{name ? `${hello},${name}` : `${hello},欢迎来到姜十三`}

分享技术、讨论问题、交流心得

{user ? ( 发起讨论 ) : ( <> 登录后参与讨论 注册 )}
{statItems.length > 0 && (
{statItems.map(({ icon: Icon, label, value, hot }) => (
{value}
{hot && } {label}
))}
)}
); }