| 53 | } |
| 54 | |
| 55 | async function fetchGithubStats() { |
| 56 | try { |
| 57 | const githubLink = config.social.find( |
| 58 | (c) => c.title.toLowerCase() === "github" |
| 59 | ).link; |
| 60 | const githubUsername = |
| 61 | githubLink.split("/")[githubLink.split("/").length - 1]; |
| 62 | const responseRaw = await fetch( |
| 63 | `https://api.github.com/users/${githubUsername}` |
| 64 | ); |
| 65 | const response = await responseRaw.json(); |
| 66 | githubStats = { ...response, username: githubUsername }; |
| 67 | } catch (error) { |
| 68 | console.log(error); |
| 69 | // handling the error |
| 70 | githubStats = { |
| 71 | username: githubUsername, |
| 72 | bio: "_failed_to_fetch_", |
| 73 | public_repos: "_failed_to_fetch_", |
| 74 | public_gists: "_failed_to_fetch_", |
| 75 | followers: "_failed_to_fetch_", |
| 76 | following: "_failed_to_fetch_", |
| 77 | }; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | export { |
| 82 | //functions exported |