Skip to content

Commit 104473f

Browse files
committed
Add live GitHub repos counter fetched from GitHub API
1 parent 21068d9 commit 104473f

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

index.html

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h2 class="hero-subtitle" id="typewriter" data-text="{{ site.data.profile.headli
5050
<div class="stat-label">Contributions Last Year</div>
5151
</div>
5252
<div class="stat-card">
53-
<div class="stat-number" data-count="{{ site.github.public_repositories.size }}">{{ site.github.public_repositories.size }}+</div>
53+
<div class="stat-number" id="github-repos" data-count="0">Loading...</div>
5454
<div class="stat-label">Open Source Repos</div>
5555
</div>
5656
</div>
@@ -134,6 +134,28 @@ <h3>Connect</h3>
134134
}
135135
}
136136

137+
// Fetch live GitHub repos count
138+
async function fetchGitHubRepos() {
139+
const reposElement = document.getElementById('github-repos');
140+
141+
try {
142+
// Use GitHub API to get user info
143+
const response = await fetch('https://api.github.com/users/NotAwar');
144+
const data = await response.json();
145+
146+
if (data.public_repos) {
147+
// Animate the counter
148+
animateCounter(reposElement, data.public_repos, data.public_repos.toString());
149+
} else {
150+
reposElement.textContent = '45+';
151+
}
152+
} catch (error) {
153+
console.error('Error fetching GitHub repos:', error);
154+
// Fallback to a default value
155+
reposElement.textContent = '45+';
156+
}
157+
}
158+
137159
// Animate counter from 0 to target
138160
function animateCounter(element, targetNum, displayCount) {
139161
const duration = 2000; // 2 seconds
@@ -157,8 +179,12 @@ <h3>Connect</h3>
157179

158180
// Run on page load
159181
if (document.readyState === 'loading') {
160-
document.addEventListener('DOMContentLoaded', fetchGitHubContributions);
182+
document.addEventListener('DOMContentLoaded', () => {
183+
fetchGitHubContributions();
184+
fetchGitHubRepos();
185+
});
161186
} else {
162187
fetchGitHubContributions();
188+
fetchGitHubRepos();
163189
}
164190
</script>

0 commit comments

Comments
 (0)