@a83/orbiter-admin 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * sidebar.js — dynamically populates collection links + pod footer in every page.
3
+ * Supports parent/child hierarchy (matching SidebarCollections.astro in the original).
4
+ */
5
+ (function () {
6
+ document.addEventListener('DOMContentLoaded', function () {
7
+ var params = new URLSearchParams(location.search);
8
+ var activeCol = params.get('col') || params.get('collection');
9
+ var page = location.pathname.split('/').pop().replace('.html', '');
10
+
11
+ fetch('/api/info', { credentials: 'include' })
12
+ .then(function (r) { return r.ok ? r.json() : null; })
13
+ .then(function (info) {
14
+ if (!info) return;
15
+
16
+ var sidebar = document.querySelector('.sidebar');
17
+ if (!sidebar) return;
18
+
19
+ // Find "Assets" nav-section to insert before it
20
+ var sections = sidebar.querySelectorAll('.nav-section');
21
+ var assetsSection = null;
22
+ for (var i = 0; i < sections.length; i++) {
23
+ if (sections[i].textContent.trim() === 'Assets') {
24
+ assetsSection = sections[i];
25
+ break;
26
+ }
27
+ }
28
+ if (!assetsSection) return;
29
+
30
+ var collections = info.collections || [];
31
+
32
+ // Build parent→children map
33
+ var topLevel = collections.filter(function (c) { return !c.parent; });
34
+ var childMap = {};
35
+ collections.filter(function (c) { return c.parent; }).forEach(function (c) {
36
+ if (!childMap[c.parent]) childMap[c.parent] = [];
37
+ childMap[c.parent].push(c);
38
+ });
39
+
40
+ var frag = document.createDocumentFragment();
41
+
42
+ topLevel.forEach(function (col) {
43
+ var isActive = (page === 'entries') && activeCol === col.id;
44
+ var a = document.createElement('a');
45
+ a.className = 'nav-item' + (isActive ? ' active' : '');
46
+ a.href = '/entries.html?col=' + encodeURIComponent(col.id) + '&label=' + encodeURIComponent(col.label);
47
+ a.innerHTML =
48
+ '<span class="nav-icon">▤</span>' +
49
+ '<span class="nav-label">' + col.label + '</span>' +
50
+ '<span class="nav-badge">' + col.total + '</span>';
51
+ frag.appendChild(a);
52
+
53
+ // Children
54
+ var kids = childMap[col.id] || [];
55
+ if (kids.length > 0) {
56
+ var children = document.createElement('div');
57
+ children.className = 'nav-children';
58
+ kids.forEach(function (kid) {
59
+ var isKidActive = (page === 'entries') && activeCol === kid.id;
60
+ var ka = document.createElement('a');
61
+ ka.className = 'nav-item nav-child' + (isKidActive ? ' active' : '');
62
+ ka.href = '/entries.html?col=' + encodeURIComponent(kid.id) + '&label=' + encodeURIComponent(kid.label);
63
+ ka.innerHTML =
64
+ '<span class="nav-icon">◦</span>' +
65
+ '<span class="nav-label">' + kid.label + '</span>' +
66
+ '<span class="nav-badge">' + kid.total + '</span>';
67
+ children.appendChild(ka);
68
+ });
69
+ frag.appendChild(children);
70
+ }
71
+ });
72
+
73
+ assetsSection.parentNode.insertBefore(frag, assetsSection);
74
+
75
+ // Update sidebar footer: pod filename
76
+ var podNameEl = sidebar.querySelector('#pod-name');
77
+ if (podNameEl && info.podPath) {
78
+ podNameEl.textContent = info.podPath.split('/').pop();
79
+ }
80
+
81
+ // pod-info line
82
+ var podInfoEl = sidebar.querySelector('#pod-info');
83
+ if (podInfoEl) {
84
+ var total = collections.reduce(function (s, c) { return s + c.total; }, 0);
85
+ podInfoEl.textContent = collections.length + ' collections · ' + total + ' entries';
86
+ }
87
+ })
88
+ .catch(function () {});
89
+ });
90
+ })();