(function () { "use strict"; function esc(s) { return String(s == null ? "" : s) .replace(/&/g, "&") .replace(//g, ">"); } function subdomain(id) { return id.toLowerCase().replace(/[^a-z0-9-]/g, "-"); } function countExperiments(node) { let n = 0; (node.children || []).forEach((c) => { n += 1 + countExperiments(c); }); return n; } function timeAgo(iso) { if (!iso) return ""; const d = (Date.now() - new Date(iso).getTime()) / 86400000; if (d < 1) return "today"; if (d < 2) return "yesterday"; if (d < 30) return `${Math.floor(d)}d ago`; if (d < 365) return `${Math.floor(d / 30)}mo ago`; return `${Math.floor(d / 365)}y ago`; } function card(space) { const id = space.id; const owner = id.split("/")[0]; const name = id.split("/")[1] || id; const sub = subdomain(id); const title = (space.cardData && space.cardData.title) || name; const a = document.createElement("a"); a.className = "card"; a.href = `https://huggingface.co/spaces/${id}`; a.target = "_blank"; a.rel = "noopener"; a.innerHTML = `
preview…
` + `
` + `
` + `
${esc(title)}
` + `
${esc(owner)}
` + `
` + (space.likes ? `♥ ${space.likes}` : "") + (space.lastModified ? `${esc(timeAgo(space.lastModified))}` : "") + `` + `
`; return a; } async function enrich(space, el) { const sub = subdomain(space.id); const chip = el.querySelector("[data-exp]"); try { const r = await fetch(`https://${sub}.static.hf.space/logbook.json`); if (!r.ok) throw new Error(); const manifest = await r.json(); const n = countExperiments(manifest.root || {}); chip.textContent = n === 1 ? "1 experiment" : `${n} experiments`; if (manifest.title) el.querySelector(".card-title").textContent = manifest.title; } catch (e) { chip.remove(); } } async function main() { const grid = document.getElementById("grid"); let spaces = []; try { const r = await fetch( "https://huggingface.co/api/spaces?filter=trackio-logbook&full=true&limit=300" ); spaces = await r.json(); } catch (e) { grid.innerHTML = '

Could not load logbooks right now.

'; return; } spaces = spaces.filter((s) => !s.sdk || s.sdk === "static"); spaces.sort( (a, b) => new Date(b.lastModified || 0) - new Date(a.lastModified || 0) ); if (!spaces.length) { grid.innerHTML = '

No logbooks published yet. Be the first!

'; document.getElementById("count").textContent = ""; return; } document.getElementById("count").textContent = `${spaces.length} logbook${spaces.length === 1 ? "" : "s"}`; grid.innerHTML = ""; spaces.forEach((s) => { const el = card(s); grid.appendChild(el); enrich(s, el); }); } main(); })();