Skip to content

Commit b47a2cc

Browse files
committed
Fix star count
1 parent fd0d99a commit b47a2cc

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

src/components/CustomHeader.astro

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,15 @@ type Link = {
1919
};
2020
2121
// Note that these links are duplicated in SiteTitle.astro and CustomHeader.astro
22-
function formatStarCount(n: number): string {
23-
if (n >= 1000) return (n / 1000).toFixed(1).replace(/\.0$/, '') + 'k';
24-
return String(n);
25-
}
26-
2722
let starCount = '';
2823
try {
29-
const headers: Record<string, string> = { 'Accept': 'application/vnd.github.v3+json' };
30-
const token = import.meta.env.GITHUB_TOKEN ?? process.env.GITHUB_TOKEN;
31-
if (token) headers['Authorization'] = `Bearer ${token}`;
32-
const res = await fetch('https://api.github.com/repos/skiptools/skip', { headers });
24+
const res = await fetch('https://github.com/skiptools/skip');
3325
if (res.ok) {
34-
const data = await res.json();
35-
if (data?.stargazers_count) {
36-
starCount = formatStarCount(data.stargazers_count);
26+
const html = await res.text();
27+
// Match the stargazers link, e.g. id="repo-stars-counter-star" ... >2.8k<
28+
const match = html.match(/id="repo-stars-counter-star"[^>]*>([^<]+)</);
29+
if (match) {
30+
starCount = match[1].trim();
3731
}
3832
}
3933
} catch {}

0 commit comments

Comments
 (0)