diff options
Diffstat (limited to 'app.js')
| -rw-r--r-- | app.js | 78 |
1 files changed, 78 insertions, 0 deletions
@@ -0,0 +1,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(); |
