Files
portfolio/site/portfolio.js
T
nicholas 1e7ab57b0a Render every active public repository in the public code list
The homepage list was pinned to four repository names, so a project published
to publish-bot after the last build never appeared. The list is now rebuilt at
page load from the public API: every non-private, non-empty, non-archived repo
in updated order, with language and last-updated date. The static anchors stay
as the no-JavaScript fallback.
2026-12-03 23:22:10 +00:00

66 lines
3.4 KiB
JavaScript

(() => {
"use strict";
document.querySelectorAll("[data-walkthrough]").forEach(panel => {
const steps = [...panel.querySelectorAll("li")];
const button = panel.querySelector("button");
const status = panel.querySelector("[role=status]");
let current = -1;
button.hidden = false;
button.addEventListener("click", () => {
current = (current + 1) % steps.length;
steps.forEach((step, index) => step.classList.toggle("is-active", index === current));
status.textContent = `Step ${current + 1} of ${steps.length}: ${steps[current].querySelector("h3").textContent}. ${steps[current].querySelector("p").textContent}`;
button.textContent = current === steps.length - 1 ? "Restart walkthrough ↺" : "Next step →";
});
});
const list = document.querySelector("[data-public-source]");
if (!list) return;
// The static links in the homepage are the no-JavaScript fallback. When the public API
// answers, the list is rebuilt from the repository list itself, so a project published to
// publish-bot appears here on the next page load with no rebuild or deploy.
const LABELS = { portfolio: "Portfolio source", "ats-native-fsd": "ATS native simulator controller" };
const PAGE = 50, MAX_PAGES = 4;
const sameOriginUrl = value => {
try { const url = new URL(value, location.origin); return url.origin === location.origin && url.protocol === "https:" ? url.href : null; }
catch { return null; }
};
const stamp = value => {
const date = new Date(value);
return Number.isNaN(date.valueOf()) ? "" : date.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
};
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 8000);
const fetchPage = page => fetch(`/api/v1/users/publish-bot/repos?limit=${PAGE}&page=${page}&sort=updated`, { credentials: "omit", headers: { Accept: "application/json" }, signal: controller.signal })
.then(response => { if (!response.ok) throw new Error("Public listing unavailable"); return response.json(); });
(async () => {
const repos = [];
for (let page = 1; page <= MAX_PAGES; page++) {
const batch = await fetchPage(page);
if (!Array.isArray(batch) || batch.length === 0) break;
repos.push(...batch);
if (batch.length < PAGE) break;
}
const active = repos
.filter(repo => repo.private === false && !repo.empty && !repo.archived)
.sort((a, b) => String(b.updated_at).localeCompare(String(a.updated_at)));
if (!active.length) return;
const rows = document.createDocumentFragment();
for (const repo of active) {
const url = sameOriginUrl(repo.html_url);
if (!url) continue;
const link = document.createElement("a");
link.href = url;
link.dataset.repo = repo.name;
if (repo.description) link.title = repo.description;
link.append(document.createTextNode(LABELS[repo.name] || repo.name));
const meta = document.createElement("span");
const updated = stamp(repo.updated_at);
meta.textContent = [repo.language || "Public repository", updated && `updated ${updated}`].filter(Boolean).join(" · ");
link.append(meta);
rows.append(link);
}
if (rows.childElementCount) list.replaceChildren(rows);
})().catch(() => { /* Existing source links remain useful when the API is unavailable. */ })
.finally(() => clearTimeout(timeout));
})();