diff --git a/site/src/components/Header.astro b/site/src/components/Header.astro index 97bb6b9..0c657d9 100644 --- a/site/src/components/Header.astro +++ b/site/src/components/Header.astro @@ -177,6 +177,7 @@ const starsLabel = stars >= 1000 ? `${(stars / 1000).toFixed(1)}k` : String(star const { value, ts } = JSON.parse(cached); if (Date.now() - ts < CACHE_TTL) { starsEl.textContent = formatStars(value); + return; // cache is fresh, skip API call } } diff --git a/site/src/components/StatsBar.astro b/site/src/components/StatsBar.astro index 748d245..eef3c02 100644 --- a/site/src/components/StatsBar.astro +++ b/site/src/components/StatsBar.astro @@ -1,9 +1,23 @@ --- import { getTotalRuleCount, getTotalExporterCount, data } from '../data/rules'; +import { GITHUB_API_REPO_URL } from '../data/site'; const totalRules = getTotalRuleCount(); const totalExporters = getTotalExporterCount(); const totalGroups = data.groups.length; + +let stars = 0; +try { + const res = await fetch(GITHUB_API_REPO_URL, { + headers: { 'Accept': 'application/vnd.github+json' } + }); + if (res.ok) { + const json = await res.json(); + stars = json.stargazers_count ?? 0; + } +} catch {} + +const starsLabel = stars >= 1000 ? `${(stars / 1000).toFixed(1)}k` : String(stars); ---