blob: 93498245dfde2cc68e646ee4bfd5db2f7d005c84 (
plain)
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
|
async function loadAtomFeed() {
const container = document.getElementById('feed-container');
try {
const response = await fetch('feed.xml');
if (!response.ok) throw new Error('Failed to load feed');
const xmlText = await response.text();
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText, 'text/xml');
const entries = Array.from(xmlDoc.querySelectorAll('entry'));
container.innerHTML = '';
if (entries.length === 0) {
container.innerHTML = '<p>No assignments found.</p>';
return;
}
// Group entries by class category
const groupedByClass = {};
entries.forEach(entry => {
const title = entry.querySelector('title')?.textContent || 'Untitled';
const updated = entry.querySelector('updated')?.textContent || '';
const linkEl = entry.querySelector('link');
const link = linkEl ? linkEl.getAttribute('href') : '#';
// Grab category term or fallback to "General"
const categoryEl = entry.querySelector('category');
const className = categoryEl ? categoryEl.getAttribute('term') : 'General';
const itemData = {
title,
link,
updated: updated ? new Date(updated).toLocaleDateString() : ''
};
if (!groupedByClass[className]) {
groupedByClass[className] = [];
}
groupedByClass[className].push(itemData);
});
// Render grouped entries
Object.keys(groupedByClass).sort().forEach(className => {
const groupSection = document.createElement('section');
groupSection.className = 'class-group';
const classHeader = document.createElement('h2');
classHeader.className = 'class-title';
classHeader.textContent = className;
groupSection.appendChild(classHeader);
const ul = document.createElement('ul');
ul.className = 'feed-list';
groupedByClass[className].forEach(item => {
const li = document.createElement('li');
li.className = 'feed-item';
li.innerHTML = `
<h3><a href="${item.link}">${item.title}</a></h3>
${item.updated ? `<div class="meta">Updated: ${item.updated}</div>` : ''}
`;
ul.appendChild(li);
});
groupSection.appendChild(ul);
container.appendChild(groupSection);
});
} catch (error) {
container.innerHTML = `<p>Error loading entries: ${error.message}</p>`;
}
}
loadAtomFeed();
|