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 ""; + } +}