document.addEventListener('DOMContentLoaded', function() { const widgets = document.querySelectorAll('.gitea-widget'); widgets.forEach(widget => { const repo = widget.dataset.repo; // Auto-generate data file path from repo name const dataFile = `/assets/repo-data/${repo.replace('/', '-')}.json`; const showDescription = widget.dataset.showDescription !== 'false'; const showLanguage = widget.dataset.showLanguage !== 'false'; const showLastUpdate = widget.dataset.showLastUpdate !== 'false'; // Show loading state widget.innerHTML = `
Loading ${repo}...
`; // Fetch repository data fetch(dataFile) .then(response => { if (!response.ok) { throw new Error(`Could not load data for ${repo}`); } return response.json(); }) .then(data => { renderWidget(widget, data, { showDescription, showLanguage, showLastUpdate }); }) .catch(error => { renderError(widget, repo, error.message); }); }); }); function renderWidget(widget, data, options) { const lastUpdate = new Date(data.updated_at).toLocaleDateString(); const language = data.language || 'Not specified'; widget.innerHTML = `
${data.stars_count.toLocaleString()} ${data.forks_count.toLocaleString()} ${data.open_issues_count.toLocaleString()}
${options.showDescription && data.description ? `
${data.description}
` : ''}
`; } function renderError(widget, repo, error) { widget.innerHTML = `
Failed to load ${repo} ${error}
`; } function getLanguageColor(language) { const colors = { 'JavaScript': '#f1e05a', 'TypeScript': '#2b7489', 'Python': '#3572A5', 'Java': '#b07219', 'C++': '#f34b7d', 'C': '#555555', 'C#': '#239120', 'PHP': '#4F5D95', 'Ruby': '#701516', 'Go': '#00ADD8', 'Rust': '#dea584', 'Swift': '#ffac45', 'Kotlin': '#F18E33', 'Scala': '#c22d40', 'Shell': '#89e051', 'HTML': '#e34c26', 'CSS': '#563d7c', 'Vue': '#2c3e50', 'React': '#61dafb', 'Dockerfile': '#384d54', 'Markdown': '#083fa1' }; return colors[language] || '#586069'; }