-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
394 lines (342 loc) · 14.5 KB
/
Copy pathapp.js
File metadata and controls
394 lines (342 loc) · 14.5 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
document.addEventListener('DOMContentLoaded', () => {
loadMarkdown('data/overview.md', 'overview-content');
loadTracks();
loadMarkdown('data/rfps.md', 'rfps-content');
loadMarkdown('data/applications.md', 'applications-content');
loadMarkdown('data/contact.md', 'contact-content');
loadGithubActivity();
loadGrants();
loadMedia();
setupMobileMenu();
setupScrollSpy();
});
async function loadMarkdown(url, elementId) {
try {
const response = await fetch(url);
const text = await response.text();
const container = document.getElementById(elementId);
if (container) {
container.innerHTML = marked.parse(text);
}
} catch (error) {
console.error(`Error loading markdown from ${url}:`, error);
}
}
async function loadTracks() {
try {
const response = await fetch('data/tracks.json');
const data = await response.json();
const container = document.getElementById('tracks-container');
if (!container) return;
data.forEach(track => {
const trackSection = document.createElement('div');
trackSection.className = 'card track-card';
trackSection.innerHTML = `
<h3>${track.title}</h3>
<p>${track.description}</p>
`;
container.appendChild(trackSection);
});
} catch (error) {
console.error('Error loading tracks:', error);
const container = document.getElementById('tracks-container');
if (container) {
container.innerHTML = '<div class="alert-box">Failed to load tracks data. Please try again later.</div>';
}
}
}
async function loadGrants() {
try {
const response = await fetch('data/grants.json');
const data = await response.json();
const container = document.getElementById('grants-container');
if (!container) return;
data.forEach(track => {
const trackSection = document.createElement('div');
trackSection.className = 'track-section';
const trackTitle = document.createElement('h3');
trackTitle.textContent = track.track;
trackSection.appendChild(trackTitle);
const list = document.createElement('ul');
list.className = 'grant-list';
track.items.forEach(item => {
const li = document.createElement('li');
li.className = 'grant-item';
const periodHtml = item.period ? `<p class="grant-period"><strong>Period:</strong> ${item.period}</p>` : '';
li.innerHTML = `
<h4>${item.title}</h4>
<p>${item.description}</p>
<div class="grant-meta">
<p class="awarded-to"><strong>Awarded to:</strong> ${item.awardedTo}</p>
${periodHtml}
</div>
`;
list.appendChild(li);
});
trackSection.appendChild(list);
// Add divider if not the last item
if (data.indexOf(track) < data.length - 1) {
const divider = document.createElement('div');
divider.className = 'subsection-divider';
trackSection.appendChild(divider);
}
container.appendChild(trackSection);
});
} catch (error) {
console.error('Error loading grants:', error);
const container = document.getElementById('grants-container');
if (container) {
container.innerHTML = '<div class="alert-box">Failed to load grants data.</div>';
}
}
}
async function loadMedia() {
try {
const response = await fetch('data/media.json');
const data = await response.json();
const container = document.getElementById('media-container');
if (!container) return;
data.forEach(category => {
const categorySection = document.createElement('div');
const categoryTitle = document.createElement('h3');
categoryTitle.textContent = category.category;
categorySection.appendChild(categoryTitle);
// Special handling for Video Updates
if (category.category.includes('Video')) {
const grid = document.createElement('div');
grid.className = 'video-grid';
category.items.forEach(item => {
const videoId = getYouTubeVideoId(item.url);
const thumbnailUrl = videoId ?
`https://img.youtube.com/vi/${videoId}/mqdefault.jpg` :
'eth-diamond-multi.png'; // Fallback
const card = document.createElement('a');
card.href = item.url;
card.target = '_blank';
card.className = 'video-card';
card.innerHTML = `
<div class="video-thumbnail">
<img src="${thumbnailUrl}" alt="${item.title}" loading="lazy">
<div class="play-icon">▶</div>
</div>
<div class="video-info">
<h4>${item.title}</h4>
</div>
`;
grid.appendChild(card);
});
categorySection.appendChild(grid);
} else {
// Standard list for other categories
const list = document.createElement('ul');
list.className = 'media-list';
// Add disclaimer for Papers category
if (category.category === 'Papers') {
const disclaimer = document.createElement('p');
disclaimer.className = 'disclaimer';
disclaimer.innerHTML = '<em>Note: Papers may be co-funded with other organizations and not all authors are necessarily funded by this project.</em>';
categorySection.appendChild(disclaimer);
}
category.items.forEach(item => {
const li = document.createElement('li');
li.innerHTML = `<a href="${item.url}" target="_blank">${item.title}</a>`;
list.appendChild(li);
});
categorySection.appendChild(list);
}
container.appendChild(categorySection);
});
} catch (error) {
console.error('Error loading media:', error);
const container = document.getElementById('media-container');
if (container) {
container.innerHTML = '<p>Failed to load media resources.</p>';
}
}
}
function getYouTubeVideoId(url) {
try {
const urlObj = new URL(url);
if (urlObj.hostname.includes('youtube.com')) {
return urlObj.searchParams.get('v');
} else if (urlObj.hostname.includes('youtu.be')) {
return urlObj.pathname.slice(1);
}
} catch (e) {
console.warn('Invalid YouTube URL:', url);
}
return null;
}
function setupMobileMenu() {
const menuToggle = document.getElementById('menu-toggle');
const sidebar = document.querySelector('.sidebar');
if (menuToggle && sidebar) {
menuToggle.addEventListener('click', () => {
sidebar.classList.toggle('active');
menuToggle.classList.toggle('active');
});
// Close menu when clicking a link
sidebar.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
sidebar.classList.remove('active');
menuToggle.classList.remove('active');
});
});
}
}
function setupScrollSpy() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.3 // Trigger when 30% of the section is visible
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.getAttribute('id');
// Remove active class from all links
navLinks.forEach(link => link.classList.remove('active'));
// Add active class to corresponding link
const activeLink = document.querySelector(`.nav-link[href="#${id}"]`);
if (activeLink) {
activeLink.classList.add('active');
}
}
});
}, observerOptions);
sections.forEach(section => {
observer.observe(section);
});
}
async function loadGithubActivity() {
const container = document.getElementById('activity-container');
if (!container) return;
const CACHE_KEY = 'github_activity_cache';
const CACHE_DURATION = 15 * 60 * 1000; // 15 minutes
// Check cache
const cached = localStorage.getItem(CACHE_KEY);
if (cached) {
const { timestamp, data } = JSON.parse(cached);
if (Date.now() - timestamp < CACHE_DURATION) {
renderActivity(data, container);
return;
}
}
try {
const response = await fetch('data/repos.json');
const repos = await response.json();
// Fetch events for each repo in parallel
const fetchPromises = repos.map(async repo => {
try {
const eventsResponse = await fetch(`https://api.github.com/repos/${repo}/events?per_page=30`);
if (eventsResponse.ok) {
return await eventsResponse.json();
}
return [];
} catch (e) {
console.warn(`Failed to fetch events for ${repo}`, e);
return [];
}
});
const results = await Promise.all(fetchPromises);
const allEvents = results.flat();
const meaningfulEvents = allEvents.filter(event => {
switch (event.type) {
case 'PushEvent':
return event.payload.ref === 'refs/heads/main' || event.payload.ref === 'refs/heads/master';
case 'PullRequestEvent':
return event.payload.action === 'opened' || event.payload.action === 'merged' || (event.payload.action === 'closed' && event.payload.pull_request.merged);
case 'ReleaseEvent':
return event.payload.action === 'published';
case 'GollumEvent':
return true;
case 'IssuesEvent':
return event.payload.action === 'opened' || event.payload.action === 'closed';
case 'DiscussionEvent':
return event.payload.action === 'created';
case 'PullRequestReviewEvent':
return event.payload.action === 'created';
default:
return false;
}
});
// Sort by date (newest first)
meaningfulEvents.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
// Keep top 10
const topEvents = meaningfulEvents.slice(0, 10);
// Cache result
localStorage.setItem(CACHE_KEY, JSON.stringify({
timestamp: Date.now(),
data: topEvents
}));
renderActivity(topEvents, container);
} catch (error) {
console.error('Error loading GitHub activity:', error);
container.innerHTML = '<p>Unable to load activity feed. Please check back later.</p>';
}
}
function renderActivity(events, container) {
if (events.length === 0) {
container.innerHTML = '<p>No recent activity found.</p>';
return;
}
const list = document.createElement('ul');
list.className = 'activity-list';
events.forEach(event => {
const li = document.createElement('li');
li.className = 'activity-item';
let action = '';
let details = '';
const repoName = event.repo.name;
const date = new Date(event.created_at).toLocaleDateString();
switch (event.type) {
case 'PushEvent':
action = 'pushed to';
details = `branch <code>${event.payload.ref.replace('refs/heads/', '')}</code>`;
break;
case 'PullRequestEvent':
const prAction = (event.payload.action === 'merged' || (event.payload.action === 'closed' && event.payload.pull_request.merged)) ? 'merged' : 'opened';
action = `${prAction} PR #${event.payload.number}`;
details = `<a href="${event.payload.pull_request.html_url}" target="_blank">${event.payload.pull_request.title}</a>`;
break;
case 'IssuesEvent':
action = `${event.payload.action} issue #${event.payload.issue.number}`;
details = `<a href="${event.payload.issue.html_url}" target="_blank">${event.payload.issue.title}</a>`;
break;
case 'ReleaseEvent':
action = `published release`;
details = `<a href="${event.payload.release.html_url}" target="_blank">${event.payload.release.name || event.payload.release.tag_name}</a>`;
break;
case 'DiscussionEvent':
action = `${event.payload.action} discussion`;
details = `<a href="${event.payload.discussion.html_url}" target="_blank">${event.payload.discussion.title}</a>`;
break;
case 'GollumEvent':
const page = event.payload.pages[0];
action = `${page.action} wiki page`;
details = `<a href="${page.html_url}" target="_blank">${page.title}</a>`;
break;
case 'PullRequestReviewEvent':
action = `reviewed PR #${event.payload.pull_request.number}`;
details = `<a href="${event.payload.review.html_url}" target="_blank">${event.payload.pull_request.title}</a>`;
break;
default:
action = 'acted on';
details = event.type;
}
li.innerHTML = `
<div class="activity-header">
<span class="activity-repo">${repoName}</span>
<span class="activity-date">${date}</span>
</div>
<div class="activity-body">
<strong>${event.actor.login}</strong> ${action} ${details}
</div>
`;
list.appendChild(li);
});
container.innerHTML = '';
container.appendChild(list);
}