export function formatCount(value: number): string { const n = Number(value ?? 0); if (n >= 100_000) return `${Math.round(n / 10_000)}万`; if (n >= 10_000) return `${(n / 10_000).toFixed(1).replace(/\.0$/, '')}万`; if (n >= 1_000) return `${(n / 1_000).toFixed(1).replace(/\.0$/, '')}k`; return String(n); } export function formatRelativeTime(iso: string): string { const date = new Date(iso); if (Number.isNaN(date.getTime())) return ''; const diffMs = Date.now() - date.getTime(); const minutes = Math.floor(diffMs / 60_000); if (minutes < 1) return '刚刚'; if (minutes < 60) return `${minutes} 分钟前`; const hours = Math.floor(minutes / 60); if (hours < 24) return `${hours} 小时前`; const days = Math.floor(hours / 24); if (days < 30) return `${days} 天前`; return date.toLocaleDateString('zh-CN'); } export function categoryAccent(slug: string): string { const palette = [ 'from-emerald-700 to-teal-500', 'from-amber-700 to-orange-500', 'from-violet-700 to-purple-500', 'from-sky-700 to-cyan-500', 'from-rose-700 to-pink-500', 'from-lime-700 to-green-500', ]; let hash = 0; for (let i = 0; i < slug.length; i += 1) hash = (hash + slug.charCodeAt(i) * (i + 1)) % palette.length; return palette[hash] ?? palette[0]; }