Skip to content

Commit 5597d55

Browse files
committed
Add live GitHub contributions counter to replace static project count
1 parent dcb7aed commit 5597d55

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

index.html

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ <h2 class="hero-subtitle" id="typewriter" data-text="{{ site.data.profile.headli
4646
<div class="stat-label">Years Experience</div>
4747
</div>
4848
<div class="stat-card">
49-
<div class="stat-number" data-count="50">50+</div>
50-
<div class="stat-label">Projects Delivered</div>
49+
<div class="stat-number" id="github-contributions" data-count="0">Loading...</div>
50+
<div class="stat-label">Contributions Last Year</div>
5151
</div>
5252
<div class="stat-card">
5353
<div class="stat-number" data-count="{{ site.github.public_repositories.size }}">{{ site.github.public_repositories.size }}+</div>
@@ -92,3 +92,73 @@ <h3>Connect</h3>
9292
</div>
9393
</div>
9494
</section>
95+
96+
<script>
97+
// Fetch live GitHub contributions count
98+
async function fetchGitHubContributions() {
99+
const contributionsElement = document.getElementById('github-contributions');
100+
101+
try {
102+
// Fetch the GitHub profile page
103+
const response = await fetch('https://github.com/NotAwar');
104+
const html = await response.text();
105+
106+
// Parse the HTML to find the contribution count
107+
const parser = new DOMParser();
108+
const doc = parser.parseFromString(html, 'text/html');
109+
110+
// Find the contributions heading
111+
const contributionHeading = doc.querySelector('h2.f4.text-normal.mb-2');
112+
113+
if (contributionHeading) {
114+
// Extract just the number from the text
115+
const text = contributionHeading.textContent.trim();
116+
const match = text.match(/^([\d,]+)/);
117+
118+
if (match) {
119+
const count = match[1].replace(/,/g, '');
120+
const displayCount = parseInt(count).toLocaleString();
121+
122+
// Animate the counter
123+
animateCounter(contributionsElement, parseInt(count), displayCount);
124+
} else {
125+
contributionsElement.textContent = '620+';
126+
}
127+
} else {
128+
contributionsElement.textContent = '620+';
129+
}
130+
} catch (error) {
131+
console.error('Error fetching GitHub contributions:', error);
132+
// Fallback to a default value
133+
contributionsElement.textContent = '620+';
134+
}
135+
}
136+
137+
// Animate counter from 0 to target
138+
function animateCounter(element, targetNum, displayCount) {
139+
const duration = 2000; // 2 seconds
140+
const steps = 60;
141+
const increment = targetNum / steps;
142+
let current = 0;
143+
let step = 0;
144+
145+
const timer = setInterval(() => {
146+
step++;
147+
current += increment;
148+
149+
if (step >= steps) {
150+
element.textContent = displayCount;
151+
clearInterval(timer);
152+
} else {
153+
element.textContent = Math.floor(current).toLocaleString();
154+
}
155+
}, duration / steps);
156+
}
157+
158+
// Run on page load
159+
if (document.readyState === 'loading') {
160+
document.addEventListener('DOMContentLoaded', fetchGitHubContributions);
161+
} else {
162+
fetchGitHubContributions();
163+
}
164+
</script>

0 commit comments

Comments
 (0)