fix: replace invalid top-level return with isFresh flag in star scripts

Top-level return is a syntax error in ES modules. Replace the early
return pattern with an isFresh boolean guard. Also revert the hero
"Star on GitHub" button change.
This commit is contained in:
Samuel Berthe 2026-04-14 19:59:36 +02:00
parent 1f8bcca779
commit 5366d4b9ae
No known key found for this signature in database
GPG key ID: 64863511FFBD0E3C
2 changed files with 6 additions and 4 deletions

View file

@ -173,15 +173,16 @@ const starsLabel = stars >= 1000 ? `${(stars / 1000).toFixed(1)}k` : String(star
}
const cached = sessionStorage.getItem(CACHE_KEY);
let isFresh = false;
if (cached) {
const { value, ts } = JSON.parse(cached);
if (Date.now() - ts < CACHE_TTL) {
starsEl.textContent = formatStars(value);
return; // cache is fresh, skip API call
isFresh = true;
}
}
fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', {
if (!isFresh) fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', {
headers: { Accept: 'application/vnd.github+json' },
})
.then((r) => r.ok ? r.json() : null)

View file

@ -55,15 +55,16 @@ const starsLabel = stars >= 1000 ? `${(stars / 1000).toFixed(1)}k` : String(star
}
const cached = sessionStorage.getItem(CACHE_KEY);
let isFresh = false;
if (cached) {
const { value, ts } = JSON.parse(cached);
if (Date.now() - ts < CACHE_TTL) {
starsEl.textContent = fmt(value);
return; // cache is fresh, skip API call
isFresh = true;
}
}
fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', {
if (!isFresh) fetch('https://api.github.com/repos/samber/awesome-prometheus-alerts', {
headers: { Accept: 'application/vnd.github+json' },
})
.then((r) => r.ok ? r.json() : null)