diff --git a/docs/components/community-stats-header.tsx b/docs/components/community-stats-header.tsx new file mode 100644 index 000000000..b2d9d8d97 --- /dev/null +++ b/docs/components/community-stats-header.tsx @@ -0,0 +1,34 @@ +import { fetchCommunityStats, fmtNum, fmtUsd } from '@/lib/telemetry'; + +/** + * Server component that renders the top-level stats for the community savings page. + * Fetches live data from Supabase at render time. + */ +export async function CommunityStatsHeader() { + const data = await fetchCommunityStats(); + + const stats = [ + { value: fmtNum(data.total_tokens_saved), label: 'Tokens Saved' }, + { value: fmtUsd(data.total_cost_saved), label: 'Cost Saved' }, + { value: fmtNum(data.total_requests), label: 'Requests Optimized' }, + { value: fmtNum(data.unique_instances), label: 'Active Instances' }, + ]; + + return ( +
+ {stats.map((s) => ( +
+ + {s.value} + + + {s.label} + +
+ ))} +
+ ); +} diff --git a/docs/components/live-stats.tsx b/docs/components/live-stats.tsx new file mode 100644 index 000000000..2d8f2790b --- /dev/null +++ b/docs/components/live-stats.tsx @@ -0,0 +1,43 @@ +import Link from 'next/link'; +import { fetchCommunityStats, fmtNum, fmtUsd } from '@/lib/telemetry'; + +/** + * Server component that fetches live stats from Supabase at render time. + * Falls back to hardcoded data if the API is unreachable. + */ +export async function LiveStats() { + const data = await fetchCommunityStats(); + + const stats = [ + { value: fmtNum(data.total_tokens_saved), label: 'Tokens Saved' }, + { value: fmtUsd(data.total_cost_saved), label: 'Cost Saved' }, + { value: fmtNum(data.total_requests), label: 'Requests Optimized' }, + { value: fmtNum(data.unique_instances), label: 'Active Instances' }, + ]; + + return ( +
+
+ {stats.map((s) => ( +
+ + {s.value} + + + {s.label} + +
+ ))} +
+ + View detailed charts and breakdowns → + +
+ ); +} diff --git a/docs/components/mdx.tsx b/docs/components/mdx.tsx index 8538c0904..37e680523 100644 --- a/docs/components/mdx.tsx +++ b/docs/components/mdx.tsx @@ -6,10 +6,11 @@ import { createGenerator } from 'fumadocs-typescript'; import { TypeTable } from 'fumadocs-ui/components/type-table'; import { Tab, Tabs } from 'fumadocs-ui/components/tabs'; import { - LiveStats, KeyFeatures, FrameworkIntegrations, } from './marketing'; +import { LiveStats } from './live-stats'; +import { CommunityStatsHeader } from './community-stats-header'; import { StatsSection } from './stats'; import { CommunityCharts } from './community-charts'; @@ -27,6 +28,7 @@ export function getMDXComponents(components?: MDXComponents) { Tabs, StatsSection, CommunityCharts, + CommunityStatsHeader, LiveStats, KeyFeatures, FrameworkIntegrations, diff --git a/docs/content/docs/community-savings.mdx b/docs/content/docs/community-savings.mdx index 4bdb88b34..0e174dc79 100644 --- a/docs/content/docs/community-savings.mdx +++ b/docs/content/docs/community-savings.mdx @@ -7,7 +7,7 @@ Real-time aggregate metrics from Headroom proxy instances worldwide. All data is ## Overview - + ## Savings Over Time