mirror of
https://github.com/samber/awesome-prometheus-alerts.git
synced 2026-06-21 00:47:18 +08:00
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:
parent
1f8bcca779
commit
5366d4b9ae
2 changed files with 6 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue