* Build-time GitHub star count. Fetched once when the site is built (the GitHub * Actions runner has network); falls back to a constant locally / offline so a * build never hangs or fails on the network. The result is memoized for the * lifetime of the build process, so rendering it on every page
(n: number)
| 6 | * call, not one per page. |
| 7 | */ |
| 8 | function format(n: number): string { |
| 9 | if (n >= 1000) { |
| 10 | const k = n / 1000; |
| 11 | const rounded = k >= 10 ? Math.round(k) : Math.round(k * 10) / 10; |
| 12 | return `${String(rounded).replace(/\.0$/, '')}k`; |
| 13 | } |
| 14 | return String(n); |
| 15 | } |
| 16 | |
| 17 | async function fetchStars(fallback: string): Promise<string> { |
| 18 | try { |