Skip to content

Commit 60aec28

Browse files
feat(marketing): fetch GitHub stars at build time (#29555)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a9ac1e8 commit 60aec28

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎apps/marketing/src/lib/site.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,25 @@ export const IOS_APP_STORE_URL =
66
export const ANDROID_PLAY_STORE_URL =
77
"https://play.google.com/store/apps/details?id=com.t3tools.t3code";
88

9+
// Runs at build time, so each deploy picks up the current count.
10+
async function fetchGithubStars(): Promise<string> {
11+
const token = process.env.GITHUB_TOKEN;
12+
try {
13+
const response = await fetch("https://api.github.com/repos/pingdotgg/t3code", {
14+
headers: token ? { Authorization: `Bearer ${token}` } : {},
15+
});
16+
if (!response.ok) throw new Error(`GitHub API responded ${response.status}`);
17+
const { stargazers_count: stars } = (await response.json()) as { stargazers_count: number };
18+
return stars < 1000 ? String(stars) : `${Math.floor(stars / 1000)}k+`;
19+
} catch (error) {
20+
// A deploy must not ship a made-up count; offline dev should still render.
21+
if (import.meta.env.PROD) throw new Error("Could not fetch GitHub stars", { cause: error });
22+
console.warn("Could not fetch GitHub stars", error);
23+
return "?";
24+
}
25+
}
26+
927
export const MARKETING_STATS = {
10-
githubStars: "40k+",
28+
githubStars: await fetchGithubStars(),
1129
users: "500,000",
1230
} as const;

0 commit comments

Comments
 (0)