File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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-
2722let starCount = ' ' ;
2823try {
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 {}
You can’t perform that action at this time.
0 commit comments