mirror of
https://github.com/vercel-labs/json-render.git
synced 2026-09-14 13:41:32 +08:00
6e5ea186de
* feat(web): fetch GitHub star count dynamically Replace the hardcoded "12k" star count in the header with a live value from the GitHub API, revalidated every 24 hours. Gracefully hides the count if the fetch fails. * fix: add GITHUB_TOKEN to turbo.json globalEnv * fix: remove GITHUB_TOKEN usage from star count fetch
21 lines
609 B
TypeScript
21 lines
609 B
TypeScript
const REPO = "vercel-labs/json-render";
|
|
const REVALIDATE = 86400;
|
|
|
|
export async function getStarCount(): Promise<string> {
|
|
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 "";
|
|
}
|
|
}
|