File size: 6,607 Bytes
81c9a7c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | // Main application script
// GitHub API configuration
const GITHUB_USERNAME = 'JoelA510';
const GITHUB_API_URL = `https://api.github.com/users/${GITHUB_USERNAME}/repos`;
const PROJECTS_TO_SHOW = 4;
// DOM Elements
const projectsContainer = document.getElementById('projects-container');
// Fetch and display GitHub projects
async function loadGitHubProjects() {
try {
// Show loading state
projectsContainer.innerHTML = `
<div class="col-span-2 flex justify-center items-center py-12">
<div class="loading-spinner"></div>
<span class="ml-3 text-gray-600">Loading projects...</span>
</div>
`;
const response = await fetch(GITHUB_API_URL);
if (!response.ok) {
throw new Error(`GitHub API error: ${response.status}`);
}
const repos = await response.json();
// Sort by last updated and take the most recent ones
const recentRepos = repos
.sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at))
.slice(0, PROJECTS_TO_SHOW);
// Clear loading state
projectsContainer.innerHTML = '';
// Create project cards
recentRepos.forEach((repo, index) => {
const projectCard = document.createElement('project-card');
projectCard.setAttribute('title', repo.name);
projectCard.setAttribute('description', repo.description || 'No description available');
projectCard.setAttribute('language', repo.language || 'Various');
projectCard.setAttribute('stars', repo.stargazers_count);
projectCard.setAttribute('forks', repo.forks_count);
projectCard.setAttribute('url', repo.html_url);
projectCard.setAttribute('updated', new Date(repo.updated_at).toLocaleDateString());
projectCard.setAttribute('delay', index * 100);
// Add progress visualization (simulated based on repo metrics)
const progress = calculateProgress(repo);
projectCard.setAttribute('progress', progress);
projectsContainer.appendChild(projectCard);
});
} catch (error) {
console.error('Error loading GitHub projects:', error);
projectsContainer.innerHTML = `
<div class="col-span-2 text-center py-12">
<i data-feather="alert-circle" class="w-16 h-16 text-red-500 mx-auto mb-4"></i>
<h3 class="text-xl font-semibold text-gray-700 mb-2">Unable to load projects</h3>
<p class="text-gray-600">Please check your connection or try again later.</p>
<button onclick="loadGitHubProjects()" class="mt-4 px-6 py-2 bg-primary-500 text-white rounded-lg hover:bg-primary-600 transition-colors">
<i data-feather="refresh-cw" class="w-4 h-4 inline mr-2"></i>
Retry
</button>
</div>
`;
feather.replace();
}
}
// Calculate progress based on repository metrics
function calculateProgress(repo) {
// Simulate progress based on various factors
let progress = 50; // Base progress
// Adjust based on repository activity
if (repo.has_pages) progress += 10;
if (repo.has_issues) progress += 5;
if (repo.has_projects) progress += 5;
if (repo.has_wiki) progress += 5;
// Adjust based on size (more files = more complete)
if (repo.size > 1000) progress += 10;
// Adjust based on age (newer = less complete)
const daysSinceUpdate = (new Date() - new Date(repo.updated_at)) / (1000 * 60 * 60 * 24);
if (daysSinceUpdate > 30) progress += 15; // Older projects might be more complete
if (daysSinceUpdate > 90) progress += 10;
// Cap at 100
return Math.min(progress, 100);
}
// Smooth scroll for anchor links
document.addEventListener('DOMContentLoaded', function() {
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 100,
behavior: 'smooth'
});
}
});
});
// Add animation classes on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fadeInUp');
}
});
}, observerOptions);
// Observe elements to animate
document.querySelectorAll('section > div').forEach(section => {
observer.observe(section);
});
// Initialize tooltips
document.querySelectorAll('[data-tooltip]').forEach(element => {
element.addEventListener('mouseenter', function() {
const tooltip = document.createElement('div');
tooltip.className = 'absolute z-50 px-3 py-2 text-sm text-white bg-gray-900 rounded-lg shadow-lg';
tooltip.textContent = this.getAttribute('data-tooltip');
tooltip.style.top = `${this.offsetTop - 40}px`;
tooltip.style.left = `${this.offsetLeft + this.offsetWidth / 2 - tooltip.offsetWidth / 2}px`;
document.body.appendChild(tooltip);
this.dataset.tooltipElement = tooltip;
});
element.addEventListener('mouseleave', function() {
if (this.dataset.tooltipElement) {
document.body.removeChild(this.dataset.tooltipElement);
delete this.dataset.tooltipElement;
}
});
});
// Initialize theme (light mode by default)
document.documentElement.classList.remove('dark');
document.documentElement.classList.add('light');
// Load GitHub projects
loadGitHubProjects();
});
// Utility function to format numbers
function formatNumber(num) {
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + 'M';
}
if (num >= 1000) {
return (num / 1000).toFixed(1) + 'K';
}
return num.toString();
}
// Export functions for use in components
window.PortfolioUtils = {
formatNumber,
loadGitHubProjects
}; |