Add GitHub star count to site header (#673)
* Add GitHub star count to site header Fetches star count from GitHub API via /api/github-stars with 5-minute server-side caching (ISR + stale-while-revalidate). Shows formatted count (e.g. "2.2k") next to the GitHub link in both desktop nav and mobile drawer. * Move star count to separate badge left of download button GitHub icon + formatted count as its own clickable element in the right header section, separate from the nav links. Desktop only. * Center GitHub stars badge vertically in header * Add right padding to GitHub stars badge
This commit is contained in:
parent
7143359c04
commit
2e2e190bf4
3 changed files with 89 additions and 2 deletions
33
web/app/api/github-stars/route.ts
Normal file
33
web/app/api/github-stars/route.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { NextResponse } from "next/server";
|
||||
|
||||
export const revalidate = 300; // ISR: regenerate every 5 minutes
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const res = await fetch(
|
||||
"https://api.github.com/repos/manaflow-ai/cmux",
|
||||
{
|
||||
headers: { Accept: "application/vnd.github.v3+json" },
|
||||
next: { revalidate: 300 },
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
return NextResponse.json({ stars: null }, { status: 502 });
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
const stars: number = data.stargazers_count;
|
||||
|
||||
return NextResponse.json(
|
||||
{ stars },
|
||||
{
|
||||
headers: {
|
||||
"Cache-Control": "public, s-maxage=300, stale-while-revalidate=600",
|
||||
},
|
||||
}
|
||||
);
|
||||
} catch {
|
||||
return NextResponse.json({ stars: null }, { status: 502 });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue