From fa043a496f7579680c78b22d0a5015f48dc99a4d Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Thu, 9 Apr 2026 02:07:32 -0500 Subject: [PATCH] fetch GitHub star count dynamically in docs header (#1202) * fetch GitHub star count dynamically in docs header Replace the hardcoded "27k" star count with a live fetch from the GitHub API, revalidated every 24 hours via Next.js fetch caching. Gracefully hides the count if the API is unreachable. * remove GITHUB_TOKEN usage from star count fetch --- docs/src/components/header.tsx | 8 ++++---- docs/src/lib/github.ts | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 docs/src/lib/github.ts diff --git a/docs/src/components/header.tsx b/docs/src/components/header.tsx index 7c9240e..5a5d949 100644 --- a/docs/src/components/header.tsx +++ b/docs/src/components/header.tsx @@ -1,10 +1,10 @@ -"use client"; - import Link from "next/link"; import { ThemeToggle } from "./theme-toggle"; import { Search } from "./search"; +import { getStarCount } from "@/lib/github"; -export function Header() { +export async function Header() { + const stars = await getStarCount(); return (
@@ -68,7 +68,7 @@ export function Header() { > - 27k + {stars && {stars}} { + try { + const res = await fetch(`https://api.github.com/repos/${REPO}`, { + headers: { Accept: "application/vnd.github.v3+json" }, + next: { revalidate: REVALIDATE }, + }); + if (!res.ok) return ""; + const data = await res.json(); + const count = data.stargazers_count; + if (typeof count !== "number") return ""; + if (count >= 1000) + return `${(count / 1000).toFixed(count >= 10000 ? 0 : 1)}k`; + return String(count); + } catch { + return ""; + } +}