import registryData from '@cli-data/registry.json' import { Calendar, Download, Hash } from 'lucide-react' import Link from 'next/link' import type { WebsiteMetadata } from '@/lib/content-loader' import { getRawClient } from '@/lib/redis' import { getRoute } from '@/lib/routes' // Build lookup: webSlug -> CLI slug (runs once at module load / build time) const webSlugToCliSlug = new Map() for (const entry of registryData as { slug: string; webSlug?: string }[]) { if (entry.webSlug) { webSlugToCliSlug.set(entry.webSlug, entry.slug) } } /** * Format a number with K suffix for thousands (e.g. 1500 → 1.5K) */ function formatCount(count: number): string { if (count >= 1000) { return `${(count / 1000).toFixed(1).replace(/\.0$/, '')}K` } return count.toString() } interface WebsiteDetailSidebarProps { website: WebsiteMetadata } /** * Sidebar for website detail pages showing stats, metadata, and per-agent installs. * Server component — reads install data from Redis at SSR time. */ export async function WebsiteDetailSidebar({ website }: WebsiteDetailSidebarProps) { const cliSlug = webSlugToCliSlug.get(website.slug) let installCount = 0 let agentInstalls: { name: string; count: number }[] = [] if (cliSlug) { try { const redis = getRawClient() if (redis) { const [totalCount, agentData] = await Promise.all([ redis.hget('telemetry:skills:total', cliSlug), redis.hgetall>(`telemetry:skills:agents:${cliSlug}`) ]) installCount = totalCount ?? 0 if (agentData) { agentInstalls = Object.entries(agentData) .map(([name, count]) => ({ name, count: Number(count) })) .sort((a, b) => b.count - a.count) .slice(0, 8) } } } catch { // Redis unavailable — show empty } } return ( ) }