Skip to content

feat: on-site GitHub link with live star count#14

Merged
anurag629 merged 1 commit into
developfrom
feat/github-star-count
Jul 8, 2026
Merged

feat: on-site GitHub link with live star count#14
anurag629 merged 1 commit into
developfrom
feat/github-star-count

Conversation

@anurag629

Copy link
Copy Markdown
Member

What

Adds a "Star on GitHub" control so the open-source repo is one click from every page: a compact pill in the header (GitHub mark + star count) and a labelled version in the footer ("Star on GitHub" + count).

How

components/shared/GitHubStars.tsx — one async server component used in both places:

  • getStarCount() fetches api.github.com/repos/codercops/toolbelt with next: { revalidate: 3600 }, so GitHub is hit at most once an hour regardless of traffic (well under the 60/hr unauthenticated limit), and a AbortSignal.timeout(3000) bounds the one cache-miss request per hour.
  • The count never reaches the browser (server-side fetch, no client CSP/rate-limit exposure).
  • Graceful degradation: any failure (403/5xx, timeout, JSON error, missing field) is caught and returns null, so the button still renders as a plain link. A GitHub outage never breaks a page.
  • Inlined GitHub mark SVG rather than lucide's Github icon (a deprecated brand icon in this lucide version); amber filled Star for the count.

lib/tools.tsGITHUB_REPO / GITHUB_REPO_URL constants (single source).

Verification

  • Rendered HTML on a tool page: exactly two repo links (header + footer), both target="_blank" rel="noopener noreferrer", live count rendered (currently 1).
  • formatStars checked across boundaries (999 → "999", 1000 → "1.0k", 9999 → "10k", 10500 → "11k") — no "10.0k" artifact.
  • Adversarial 4-lens review (RSC/caching/resilience, edge cases, a11y, design). RSC + caching + failure-path handling verified sound. Two minor bugs it confirmed (the 9950–9999 "10.0k" case, and the aria-label announcing the raw count while the pill shows the abbreviated one) are fixed in this PR.
  • npm run build, npm run lint, npm run test (27/27) pass.

Third PR in the SEO plan. Next and last: the README + repo-presentation overhaul (badges, star-history, live tool links, reusing the per-page OG images as visuals).

Add a "Star on GitHub" control to the header (compact) and footer (labelled),
so the open-source repo is one click from every page.

- components/shared/GitHubStars.tsx: an async server component that fetches the
  repo's star count from the GitHub API with revalidate 3600 (hit at most once
  an hour, well under the unauthenticated limit) plus a 3s timeout. Any failure
  degrades to just the link, so a GitHub outage never breaks a page, and the
  count never reaches the browser.
- Inlined GitHub mark SVG (lucide's brand icon is deprecated); amber Star icon.
- lib/tools.ts: GITHUB_REPO / GITHUB_REPO_URL constants.

The aria-label mirrors the visible abbreviated count and pluralizes; formatStars
is consistent across the 1k/10k boundaries.
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
toolbelt Ready Ready Preview, Comment Jul 8, 2026 8:55am

Request Review

@anurag629 anurag629 merged commit f0e952c into develop Jul 8, 2026
3 checks passed
@anurag629 anurag629 deleted the feat/github-star-count branch July 8, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant