File size: 1,643 Bytes
ae853c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Document Hub — render the route manifest as clickable routing cards.
async function init() {
    let manifest;
    try { manifest = await fetch('/api/routes').then(r => r.json()); }
    catch (_) { document.getElementById('manifest').innerHTML = '<p>manifest unavailable</p>'; return; }

    const host = document.getElementById('manifest');
    host.innerHTML = '';
    manifest.groups.forEach(g => {
        const title = document.createElement('div');
        title.className = 'group-title';
        title.textContent = g.group;
        host.appendChild(title);

        const grid = document.createElement('div');
        grid.className = 'routegrid';
        g.routes.forEach(r => {
            // GET (and pages/external) are clickable; templated/POST render as static cards.
            const clickable = (r.kind === 'get' || r.kind === 'page' || r.kind === 'external');
            const tag = clickable ? 'a' : 'div';
            const card = document.createElement(tag);
            card.className = 'routecard' + (r.method === 'POST' ? ' post' : '') + (r.kind === 'external' ? ' external' : '');
            if (clickable) { card.href = r.path; if (r.kind !== 'page') card.target = '_blank'; }
            const shown = r.kind === 'external' ? r.path.replace(/^https?:\/\//, '') : r.path;
            card.innerHTML = `<span class="m">${r.method}</span>
                <div class="lbl">${r.label}${clickable ? ' ↗' : ''}</div>
                <div class="path">${shown}</div>
                <div class="d">${r.desc}</div>`;
            grid.appendChild(card);
        });
        host.appendChild(grid);
    });
}
init();