File size: 6,838 Bytes
870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 1c83083 870d198 | 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | const dataUrl = "./data/registry.json";
const searchInput = document.getElementById("search-input");
const sphereFilter = document.getElementById("sphere-filter");
const comboFilter = document.getElementById("combo-filter");
const statusFilter = document.getElementById("status-filter");
const artifactFilter = document.getElementById("artifact-filter");
const registryGrid = document.getElementById("registry-grid");
const stats = document.getElementById("stats");
const resultCount = document.getElementById("result-count");
const cardTemplate = document.getElementById("card-template");
let registryEntries = [];
function titleCase(value) {
return value
.split(/[\s_-]+/)
.filter(Boolean)
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join(" ");
}
function prettyLabel(key, value) {
if (!value) {
return "";
}
if (key === "sphere") {
return titleCase(value);
}
if (key === "artifactType" || key === "validationStage") {
return titleCase(value);
}
return value;
}
function uniqueValues(entries, key) {
return [...new Set(entries.map((entry) => entry[key]).filter(Boolean))].sort();
}
function fillSelect(select, values, key) {
for (const value of values) {
const option = document.createElement("option");
option.value = value;
option.textContent = prettyLabel(key, value);
select.appendChild(option);
}
}
function buildStats(entries) {
const bySphere = ["science", "entrepreneurship", "technology"].map((sphere) => ({
label: prettyLabel("sphere", sphere),
value: entries.filter((entry) => entry.primarySphere === sphere).length,
className: sphere,
}));
const cards = [
{ label: "Total entries", value: entries.length, className: "total" },
...bySphere,
{
label: "Hybrid lanes",
value: entries.filter((entry) => entry.combo.includes("+")).length,
className: "hybrid",
},
];
stats.innerHTML = "";
for (const card of cards) {
const wrapper = document.createElement("article");
wrapper.className = `stat ${card.className}`;
wrapper.innerHTML = `
<div class="stat-value">${card.value}</div>
<div class="stat-label">${card.label}</div>
`;
stats.appendChild(wrapper);
}
}
function setText(target, value) {
target.textContent = value && value.length ? value : "—";
}
function renderCards(entries) {
registryGrid.innerHTML = "";
resultCount.textContent = `${entries.length} result${entries.length === 1 ? "" : "s"}`;
if (!entries.length) {
const empty = document.createElement("div");
empty.className = "empty";
empty.textContent = "No entries match the current filters yet.";
registryGrid.appendChild(empty);
return;
}
for (const entry of entries) {
const fragment = cardTemplate.content.cloneNode(true);
const sphereBadge = fragment.querySelector(".badge.sphere");
const comboBadge = fragment.querySelector(".badge.combo");
const statusBadge = fragment.querySelector(".badge.status");
const title = fragment.querySelector(".title");
const summary = fragment.querySelector(".summary");
const track = fragment.querySelector(".track");
const artifactType = fragment.querySelector(".artifact-type");
const secondarySpheres = fragment.querySelector(".secondary-spheres");
const deliveryLayers = fragment.querySelector(".delivery-layers");
const validationStage = fragment.querySelector(".validation-stage");
const tags = fragment.querySelector(".tags");
const links = fragment.querySelector(".links");
sphereBadge.textContent = prettyLabel("sphere", entry.primarySphere);
sphereBadge.classList.add(entry.primarySphere);
comboBadge.textContent = entry.combo;
comboBadge.classList.add(`combo-${entry.combo.toLowerCase().replace(/\+/g, "-")}`);
statusBadge.textContent = prettyLabel("status", entry.status);
title.textContent = entry.title;
summary.textContent = entry.summary;
setText(track, entry.track);
setText(artifactType, prettyLabel("artifactType", entry.artifactType));
setText(
secondarySpheres,
entry.secondarySpheres.length
? entry.secondarySpheres.map((item) => prettyLabel("sphere", item)).join(", ")
: "",
);
setText(deliveryLayers, entry.deliveryLayers.join(", "));
setText(validationStage, prettyLabel("validationStage", entry.validationStage));
setText(tags, entry.tags.join(", "));
for (const link of entry.links) {
const anchor = document.createElement("a");
anchor.href = link.href;
anchor.textContent = link.label;
anchor.target = "_blank";
anchor.rel = "noreferrer";
links.appendChild(anchor);
}
registryGrid.appendChild(fragment);
}
}
function applyFilters() {
const query = searchInput.value.trim().toLowerCase();
const sphere = sphereFilter.value;
const combo = comboFilter.value;
const status = statusFilter.value;
const artifact = artifactFilter.value;
const filtered = registryEntries.filter((entry) => {
const matchesSphere = sphere === "all" || entry.primarySphere === sphere;
const matchesCombo = combo === "all" || entry.combo === combo;
const matchesStatus = status === "all" || entry.status === status;
const matchesArtifact = artifact === "all" || entry.artifactType === artifact;
const haystack = [
entry.title,
entry.summary,
entry.track,
entry.entryType,
entry.primarySphere,
entry.combo,
entry.artifactType,
entry.validationStage,
...entry.secondarySpheres,
...entry.deliveryLayers,
...entry.tags,
]
.join(" ")
.toLowerCase();
const matchesQuery = !query || haystack.includes(query);
return matchesSphere && matchesCombo && matchesStatus && matchesArtifact && matchesQuery;
});
renderCards(filtered);
}
async function init() {
const response = await fetch(dataUrl);
registryEntries = await response.json();
fillSelect(sphereFilter, uniqueValues(registryEntries, "primarySphere"), "sphere");
fillSelect(comboFilter, uniqueValues(registryEntries, "combo"), "combo");
fillSelect(statusFilter, uniqueValues(registryEntries, "status"), "status");
fillSelect(artifactFilter, uniqueValues(registryEntries, "artifactType"), "artifactType");
buildStats(registryEntries);
renderCards(registryEntries);
searchInput.addEventListener("input", applyFilters);
sphereFilter.addEventListener("change", applyFilters);
comboFilter.addEventListener("change", applyFilters);
statusFilter.addEventListener("change", applyFilters);
artifactFilter.addEventListener("change", applyFilters);
}
init().catch((error) => {
registryGrid.innerHTML = `<div class="empty">Failed to load registry data: ${error.message}</div>`;
resultCount.textContent = "Error";
});
|