diff --git a/src/components/buttons/GithubButton.astro b/src/components/buttons/GithubButton.astro index 18861a20..aa410a81 100644 --- a/src/components/buttons/GithubButton.astro +++ b/src/components/buttons/GithubButton.astro @@ -5,88 +5,65 @@ interface Props { } const { type, target } = Astro.props; ---- - - - { - type == "star" && ( -
- <> - - -   - Star - - {/* - 0 - */} - -
- ) - } +const url = new URL("https://api.github.com/repos/" + target + "/stargazers"); +var headers = new Headers(); +headers.append("Accept", "application/vnd.github+json"); +headers.append("X-GitHub-Api-Version", "2022-11-28"); - { - type == "fork" && ( -
- <> - - -   - Fork - - {/* - 9 - */} - -
- ) - } +const response = await fetch(url, { headers: headers }); +const data = await response.json(); +const starsCount = data.length ? data.length : "?"; +--- - { - type == "follow" && ( -
+{ + type == "star" && ( + + ) +} +{ + type == "fork" && ( + - ) - } - - - + +
+ ) +} +{ + type == "follow" && ( + + ) +} - diff --git a/src/pages/index.astro b/src/pages/index.astro index 63440fc3..f20ab3a7 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -102,10 +102,7 @@ import Rating from "../components/Rating.astro"; >

- +