-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (57 loc) · 3.1 KB
/
script.js
File metadata and controls
66 lines (57 loc) · 3.1 KB
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
document.addEventListener('DOMContentLoaded', () => {
const username = 'RSKCS2';
const projectsContainer = document.getElementById('projects-container');
const grid = document.createElement('div');
grid.className = 'projects-grid';
projectsContainer.appendChild(grid);
async function fetchAndDisplayRepos() {
try {
const response = await fetch(`https://api.github.com/users/${username}/repos?sort=updated&direction=desc`);
const repos = await response.json();
repos.forEach(repo => {
const card = document.createElement('article');
card.className = 'project-card';
// GitHub's Open Graph image URL
const thumbnailUrl = `https://opengraph.githubassets.com/1/${repo.owner.login}/${repo.name}`;
// Last updated date
const updatedDate = new Date(repo.updated_at).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
card.innerHTML = `
<img src="${thumbnailUrl}"
class="project-thumbnail"
alt="${repo.name} preview"
onerror="this.style.display='none'">
<div class="project-content">
<h2 class="project-title">${repo.name}</h2>
<p class="project-description">${repo.description || 'No description available'}</p>
<div class="project-meta">
<div class="project-stats">
<span><i class="fas fa-code"></i> ${repo.language || 'N/A'}</span>
<span><i class="fas fa-star"></i> ${repo.stargazers_count}</span>
<span><i class="fas fa-code-branch"></i> ${repo.forks_count}</span>
</div>
<small>Updated: ${updatedDate}</small>
</div>
<div class="project-links">
<a href="${repo.html_url}" class="project-link" target="_blank" rel="noopener">
<i class="fab fa-github"></i> Repository
</a>
${repo.homepage ? `
<a href="${repo.homepage}" class="project-link" target="_blank" rel="noopener">
<i class="fas fa-external-link-alt"></i> Live Demo
</a>` : ''}
</div>
</div>
`;
grid.appendChild(card);
});
} catch (error) {
console.error('Error loading repositories:', error);
grid.innerHTML = `<p class="error">Failed to load projects. Please try refreshing the page.</p>`;
}
}
fetchAndDisplayRepos();
});