Template:Hpccalendar
Jump to navigation
Jump to search
<script> async function fetchAndDisplayCourses() {
const url = 'https://api.veranstaltungen.hpc-in-deutschland.de/events';
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch courses: ${response.status}`);
}
const events = await response.json(); const today = new Date(); const twoMonthsLater = new Date(); twoMonthsLater.setMonth(today.getMonth() + 2);
// Filter upcoming courses within next 2 months
let upcomingCourses = events.filter(event => {
const startDate = new Date(event.startDate || event.date);
return startDate >= today && startDate <= twoMonthsLater;
});
// Sort by start date ascending upcomingCourses.sort((a, b) => new Date(a.startDate || a.date) - new Date(b.startDate || b.date));
let html = '
- ';
upcomingCourses.forEach(event => {
const start = new Date(event.startDate || event.date);
const end = event.endDate ? new Date(event.endDate) : null;
const location = event.location || (event.online ? 'Online' : 'No location info');
html += '
- '; // Date before the name html += `${start.toLocaleDateString()}`; if (end && end > start) { html += ` - ${end.toLocaleDateString()}`; } html += ': '; // Name as a link to URL html += `<a href="${event.url}" target="_blank" rel="noopener noreferrer">${event.title || event.name}</a>`; html += ` | Location: ${location}`; html += ' '; }); html += '
';
document.getElementById('course-list').innerHTML = html;
} catch (error) {
document.getElementById('course-list').innerText = 'Error loading courses: ' + error.message;
}
}
fetchAndDisplayCourses(); </script>