Something went wrong. Try again.
A single hub to check all of my ATProto activity
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306import { ABOUT_HTML, GROUP_MIN, HANDLE, SERIES_GROUP_MIN, UNGROUPED_VERB, verbColor } from "./config";import { blobCid, cdnUrl } from "./atproto";import { dayKey, esc, fmtDay, fmtDayFull, sameDay, truncate } from "./format";import type { ActorProfile, TimelineEvent } from "./types";
// Shimmering placeholder rows shown while the records download. Mirrors the// event grid (pill · body · thumb) so the switch to real content is seamless.const SKELETON_ROWS = 7;export function renderLoading(): void { const host = document.querySelector<HTMLElement>("#timeline"); if (!host) return; const line = (w: string): string => `<span class="sk skel-line" style="width:${w}"></span>`; const row = ` <div class="skel-row"> <span class="sk skel-pill"></span> <div class="skel-body">${line("55%")}${line("92%")}${line("38%")}</div> <span class="sk skel-thumb"></span> </div>`; host.innerHTML = `<div class="skeleton" aria-hidden="true">${row.repeat(SKELETON_ROWS)}</div>`;}
export function renderProfile(p: ActorProfile | undefined): void { if (!p) return; const host = document.querySelector<HTMLElement>("#profile"); if (!host) return; const avatar = p.avatar ? `<img class="avatar" src="${esc(cdnUrl(blobCid(p.avatar), "avatar"))}" alt="">` : ""; // The avatar is centred against the name + bio only; the page description // sits below, outside that row. host.innerHTML = `<div class="profile-main">${avatar}` + `<div class="profile-id">` + `<h1>${esc(p.displayName || "diego.codes")} <span class="handle">@${esc(HANDLE)}</span></h1>` + (p.description ? `<blockquote>${esc(p.description)}</blockquote>` : "") + `</div></div>` + `<p class="about">${ABOUT_HTML}</p>`;}
// The rating + metadata line (stars · genres/place…), shared by rows and the// collapsed group summary.const metaLine = (e: TimelineEvent): string => e.stars || e.meta ? `<p class="muted small">${e.stars}${e.stars && e.meta ? " · " : ""}${esc(e.meta)}</p>` : "";
function buildEventRow(e: TimelineEvent): HTMLElement { const row = document.createElement("article"); row.className = "event"; row.dataset.date = e.date.toISOString(); // read by the sticky context bar row.style.setProperty("--verb-color", verbColor(e.colorVerb));
// e.photos holds blob cids; the hero pulls the fullsize render and each mini a // small thumbnail (data-full carries the fullsize for click-to-swap). Serving // resized CDN images keeps the timeline light. Single-image entries (posters, // roll covers) keep the small right-hand thumb. const featured = e.photos.length ? `<img class="gallery-featured" loading="lazy" decoding="async" src="${esc(cdnUrl(e.photos[0], "feed_fullsize"))}" alt="">` : ""; const minis = e.photos.length ? `<div class="gallery-minis">${e.photos .map((cid, i) => `<img class="mini${i === 0 ? " active" : ""}" loading="lazy" decoding="async"` + ` src="${esc(cdnUrl(cid, "feed_thumbnail"))}" data-full="${esc(cdnUrl(cid, "feed_fullsize"))}" alt="">`) .join("")}</div>` : ""; const rightCol = e.image ? `<img class="thumb" loading="lazy" decoding="async" src="${esc(e.image)}" alt="">` : minis; const permalink = e.url ? `<a class="permalink" href="${esc(e.url)}" target="_blank" rel="noopener">↗</a>` : "";
// Titled rows (reviews, places…) link the title and show text plainly. // Title-less rows (Bluesky posts) show the text itself as the body, with a // trailing permalink instead of a bold title. const h3 = e.title ? `<h3>${e.url ? `<a href="${esc(e.url)}" target="_blank" rel="noopener">${esc(e.title)}</a>` : esc(e.title)}</h3>` : ""; // A self-thread renders each post as a dot on a connecting line, with that // post's own photos beneath it (the trailing permalink hangs off the last // one); a single post is a plain paragraph. const threadPhotos = (photos: string[]): string => photos.length ? `<div class="tphotos ${photos.length === 1 ? "solo" : "multi"}">${photos .map((cid) => `<img class="tphoto" loading="lazy" decoding="async" src="${esc(cdnUrl(cid, "feed_thumbnail"))}" alt="">`) .join("")}</div>` : ""; const body = e.thread.length > 1 ? `<div class="thread">${e.thread .map((p) => { const link = p.url ? ` <a class="permalink" href="${esc(p.url)}" target="_blank" rel="noopener">↗</a>` : ""; const text = p.text || link ? `<p>${esc(p.text)}${link}</p>` : ""; return `<div class="tpost"><span class="tdot"></span><div class="tbody">${text}${threadPhotos(p.photos)}</div></div>`; }) .join("")}</div>` : e.note ? `<p class="note">${esc(e.note)}${e.title ? "" : ` ${permalink}`}</p>` : (!e.title && permalink ? `<p class="note">${permalink}</p>` : "");
row.innerHTML = ` <div class="when"> <span class="verb">${esc(e.verb)}</span> </div> <div class="what"> ${h3} ${metaLine(e)} ${body} ${featured} </div> ${rightCol}`; return row;}
// A collapsed run: a <details> whose <summary> is "verb · rep title and N// others", expanding to the same rows the ungrouped view would show.function buildGroup(run: TimelineEvent[]): HTMLElement { const rep = run[0]; // most recent in the run const others = run.length - 1; const details = document.createElement("details"); details.className = "group";
const summary = document.createElement("summary"); summary.className = "event group-summary"; summary.dataset.date = rep.date.toISOString(); summary.style.setProperty("--verb-color", verbColor(rep.colorVerb)); summary.innerHTML = ` <div class="when"> <span class="verb">${esc(rep.verb)}</span> </div> <div class="what"> <h3>${esc(truncate(rep.title || rep.note, 80))} <span class="others">and ${others} other${others === 1 ? "" : "s"}</span> </h3> ${metaLine(rep)} </div>`; details.appendChild(summary);
const box = document.createElement("div"); box.className = "group-items"; run.forEach((e) => box.appendChild(buildEventRow(e))); details.appendChild(box); return details;}
// Drop the series prefix from an episode title: "Fallout - S2E6 - The Other// Player" → "S2E6 · The Other Player" (the series name lives in the summary).const episodeLabel = (e: TimelineEvent): string => { const name = e.seriesName || ""; const rest = name && e.title.startsWith(name) ? e.title.slice(name.length).replace(/^[\s–-]+/, "").trim() : e.title; return rest.replace(/ - /g, " · ") || e.title;};
// One episode as a node on the series thread: dot + label + rating + review.const episodeNodeHtml = (e: TimelineEvent): string => { const label = esc(episodeLabel(e)); const title = e.url ? `<a href="${esc(e.url)}" target="_blank" rel="noopener">${label}</a>` : label; return `<div class="tpost"> <span class="tdot"></span> <div class="tbody"> <p class="ep-title">${title}${e.stars ? ` <span class="ep-stars">${e.stars}</span>` : ""}</p> ${e.note ? `<p class="note">${esc(e.note)}</p>` : ""} </div> </div>`;};
// A run of adjacent same-series episodes: one event row whose episodes drop// down inside its own content column (tucked under the title), threaded like a// Bluesky self-thread. Toggled by a button so the poster stays put on the right.function buildSeriesGroup(run: TimelineEvent[]): HTMLElement { const rep = run[0]; // most recent episode const row = document.createElement("article"); row.className = "event series-group"; row.dataset.date = rep.date.toISOString(); row.style.setProperty("--verb-color", verbColor(rep.colorVerb)); const thumb = rep.image ? `<img class="thumb" loading="lazy" decoding="async" src="${esc(rep.image)}" alt="">` : ""; row.innerHTML = ` <div class="when"> <span class="verb">${esc(rep.verb)}</span> </div> <div class="what"> <button class="series-toggle" type="button" aria-expanded="false"> <span class="series-name">${esc(rep.seriesName || rep.title)}</span> <span class="others">${run.length} episodes</span> </button> <div class="series-episodes">${run.map(episodeNodeHtml).join("")}</div> </div> ${thumb}`; const btn = row.querySelector<HTMLButtonElement>(".series-toggle")!; btn.addEventListener("click", () => { const open = row.classList.toggle("open"); btn.setAttribute("aria-expanded", String(open)); row.dispatchEvent(new Event("toggle")); // let the rail/context bar re-measure }); return row;}
function yearSeparator(year: number): HTMLElement { const sep = document.createElement("div"); sep.className = "year-sep"; sep.dataset.year = String(year); // rail anchor sep.innerHTML = `<span>${year}</span>`; return sep;}
function monthSeparator(date: Date): HTMLElement { const sep = document.createElement("div"); sep.className = "month-sep"; sep.dataset.month = `${date.getFullYear()}-${date.getMonth()}`; // rail anchor sep.textContent = date.toLocaleDateString("en-GB", { month: "long" }); return sep;}
// A day heading: labelled thin rule, mirroring the year separator's form. Marks// the start of each day (the per-entry date lives here now, not on every row).// The compact label morphs into the full date on hover (CSS crossfade).function daySeparator(date: Date): HTMLElement { const sep = document.createElement("div"); sep.className = "day-sep"; sep.innerHTML = `<span class="day-label">` + `<span class="dl-short">${esc(fmtDay(date))}</span>` + `<span class="dl-full">${esc(fmtDayFull(date))}</span>` + `</span>`; return sep;}
export function renderTimeline(events: TimelineEvent[]): void { const host = document.querySelector<HTMLElement>("#timeline"); if (!host) return; host.innerHTML = ""; let lastYear: number | null = null; let lastMonth: string | null = null;
let lastDay: string | null = null; let i = 0; while (i < events.length) { const e = events[i]; const year = e.date.getFullYear(); const monthKey = `${year}-${e.date.getMonth()}`; const day = dayKey(e.date); if (year !== lastYear) { host.appendChild(yearSeparator(year)); lastYear = year; lastMonth = null; lastDay = null; } if (monthKey !== lastMonth) { host.appendChild(monthSeparator(e.date)); lastMonth = monthKey; lastDay = null; } if (day !== lastDay) { host.appendChild(daySeparator(e.date)); lastDay = day; }
// A run of adjacent same-series episodes (same day) threads together; a // lone episode renders as an ordinary row. Episodes never fall into the // generic verb group below. if (e.seriesId) { let k = i; while (k + 1 < events.length && events[k + 1].seriesId === e.seriesId && sameDay(events[k + 1].date, e.date)) k++; const run = events.slice(i, k + 1); if (run.length >= SERIES_GROUP_MIN) host.appendChild(buildSeriesGroup(run)); else host.appendChild(buildEventRow(e)); i = k + 1; continue; }
// Generic run: same verb + topic, same calendar day (episodes excluded). let j = i; if (e.verb !== UNGROUPED_VERB) { while (j + 1 < events.length && !events[j + 1].seriesId && events[j + 1].verb === e.verb && events[j + 1].colorVerb === e.colorVerb && sameDay(events[j + 1].date, e.date)) j++; } const run = events.slice(i, j + 1); if (run.length >= GROUP_MIN) host.appendChild(buildGroup(run)); else run.forEach((ev) => host.appendChild(buildEventRow(ev))); i = j + 1; }
// Clicking a thumbnail swaps it into the featured slot for that entry. // Delegated on the persistent host and bound once, so re-renders (filtering) // don't stack duplicate listeners. if (!host.dataset.swapBound) { host.dataset.swapBound = "1"; host.addEventListener("click", (e) => { const mini = (e.target as HTMLElement).closest<HTMLImageElement>(".mini"); if (!mini) return; const row = mini.closest<HTMLElement>(".event"); const featured = row?.querySelector<HTMLImageElement>(".gallery-featured"); if (featured) featured.src = mini.dataset.full || mini.src; // swap in the fullsize render row?.querySelectorAll(".mini").forEach((m) => m.classList.toggle("active", m === mini)); }); }}