|
1 | 1 | --- |
2 | | -import { Icon } from 'astro-icon/components'; |
3 | | -import { Octokit } from 'octokit'; |
4 | | -import { siteMetadata, URLs } from '~/constants'; |
5 | | -import type { RepoStats } from '~/types'; |
| 2 | + import { Icon } from 'astro-icon/components'; |
| 3 | + import { Octokit } from 'octokit'; |
| 4 | + import { siteMetadata, URLs } from '~/constants'; |
| 5 | + import type { RepoStats } from '~/types'; |
6 | 6 |
|
7 | | -const octokit = new Octokit(); |
| 7 | + const octokit = new Octokit(); |
8 | 8 |
|
9 | | -const formatCount = (count: number) => { |
10 | | - return new Intl.NumberFormat('en', { |
11 | | - notation: 'compact', |
12 | | - maximumFractionDigits: 1, |
13 | | - }).format(count); |
14 | | -}; |
| 9 | + const formatCount = (count: number) => { |
| 10 | + return new Intl.NumberFormat('en', { |
| 11 | + notation: 'compact', |
| 12 | + maximumFractionDigits: 1, |
| 13 | + }).format(count); |
| 14 | + }; |
15 | 15 |
|
16 | | -const loadRepoStats = async (): Promise<RepoStats> => { |
17 | | - try { |
18 | | - const repository = await octokit.rest.repos.get({ |
19 | | - owner: siteMetadata.repo.owner, |
20 | | - repo: siteMetadata.repo.name, |
21 | | - }); |
| 16 | + const loadRepoStats = async (): Promise<RepoStats> => { |
| 17 | + try { |
| 18 | + const repository = await octokit.rest.repos.get({ |
| 19 | + owner: siteMetadata.repo.owner, |
| 20 | + repo: siteMetadata.repo.name, |
| 21 | + }); |
22 | 22 |
|
23 | | - const latestRelease = await octokit.rest.repos.getLatestRelease({ |
24 | | - owner: siteMetadata.repo.owner, |
25 | | - repo: siteMetadata.repo.name, |
26 | | - }); |
| 23 | + const latestRelease = await octokit.rest.repos.getLatestRelease({ |
| 24 | + owner: siteMetadata.repo.owner, |
| 25 | + repo: siteMetadata.repo.name, |
| 26 | + }); |
27 | 27 |
|
28 | | - return { |
29 | | - forks: formatCount(repository.data.forks_count), |
30 | | - stars: formatCount(repository.data.stargazers_count), |
31 | | - latestReleaseName: latestRelease.data.name?.replace('v', '') ?? '', |
32 | | - }; |
33 | | - } catch (error) { |
34 | | - console.error('Failed to load repo stats', error); |
35 | | - return { |
36 | | - forks: '', |
37 | | - stars: '', |
38 | | - latestReleaseName: '', |
39 | | - }; |
40 | | - } |
41 | | -}; |
| 28 | + return { |
| 29 | + forks: formatCount(repository.data.forks_count), |
| 30 | + stars: formatCount(repository.data.stargazers_count), |
| 31 | + latestReleaseName: latestRelease.data.name?.replace('v', '') ?? '', |
| 32 | + }; |
| 33 | + } catch (error) { |
| 34 | + console.error('Failed to load repo stats', error); |
| 35 | + return { |
| 36 | + forks: '', |
| 37 | + stars: '', |
| 38 | + latestReleaseName: '', |
| 39 | + }; |
| 40 | + } |
| 41 | + }; |
42 | 42 |
|
43 | | -const { forks, stars, latestReleaseName } = await loadRepoStats(); |
| 43 | + const { forks, stars, latestReleaseName } = await loadRepoStats(); |
44 | 44 | --- |
45 | 45 | <a |
46 | 46 | href={URLs.GITHUB.REPO} |
|
0 commit comments