Something went wrong. Try again.
A single hub to check all of my ATProto activity
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import { CONTEXT_ANCHOR_PX, verbColor } from "./config";import { esc } from "./format";import { intervalPredicate } from "./model";import type { Interval } from "./types";
const FAR_FUTURE = new Date("2999-12-31");const intervalEnd = (iv: Interval): Date => iv.end || FAR_FUTURE;
// Intervals covering `date`; broadest span first so a containing interval// leads a contained one. Spans are [start, end) so back-to-back jobs don't// both light up on the month they share.export function activeIntervals(intervals: Interval[], date: Date): Interval[] { return intervals .filter((iv) => date >= iv.start && date < intervalEnd(iv)) .sort((a, b) => (a.start.getTime() - b.start.getTime()) || (intervalEnd(b).getTime() - intervalEnd(a).getTime()));}
// A sticky bar that reflects whichever job/degree spans contain the date// currently sitting under it as you scroll.export function setupContextBar(intervals: Interval[], name: string): () => void { const noop = (): void => {}; const bar = document.querySelector<HTMLElement>("#contextbar"); const rows = [...document.querySelectorAll<HTMLElement>(".event[data-date]")]; if (!bar || !rows.length || !intervals.length) { bar?.classList.add("empty"); return noop; } const ac = new AbortController(); const { signal } = ac;
// Cache each *visible* row's absolute top + date, sorted by position. // Collapsed-group items are hidden (offsetParent null) and skipped; toggling // a group re-measures. Absolute top (rect + scrollY) is robust to nesting. let index: { top: number; date: Date }[] = []; const measure = (): void => { index = rows .filter((r) => r.offsetParent !== null) .map((r) => ({ top: r.getBoundingClientRect().top + window.scrollY, date: new Date(r.dataset.date!) })) .sort((a, b) => a.top - b.top); };
// Dates descend as top increases — binary-search the last row above the line. const currentDate = (): Date | null => { const y = window.scrollY + CONTEXT_ANCHOR_PX; let lo = 0, hi = index.length - 1; let ans: Date | null = null; while (lo <= hi) { const mid = (lo + hi) >> 1; if (index[mid].top <= y) { ans = index[mid].date; lo = mid + 1; } else hi = mid - 1; } return ans; };
// "Diego is working at Carto as a Senior Data Scientist" // "Diego was studying BSc Computer Science at UC3M" const phraseHtml = (iv: Interval): string => `${esc(name)} ${iv.end ? "was" : "is"} ${esc(intervalPredicate(iv))}`;
const update = (): void => { const date = currentDate(); const active = date ? activeIntervals(intervals, date) : []; if (!active.length) { bar.classList.add("empty"); return; } bar.classList.remove("empty"); bar.innerHTML = active .map((iv) => `<span class="ctx" style="--verb-color:${verbColor(iv.verb)}">` + `<span class="dot"></span><span>${phraseHtml(iv)}</span>` + `</span></span>`) .join(""); };
let ticking = false; const onScroll = (): void => { if (ticking) return; ticking = true; requestAnimationFrame(() => { update(); ticking = false; }); }; measure(); update(); window.addEventListener("scroll", onScroll, { passive: true, signal }); window.addEventListener("resize", () => { measure(); update(); }, { signal }); // Expanding/collapsing a group changes layout; toggle doesn't bubble → capture. document.addEventListener("toggle", () => { measure(); update(); }, { capture: true, signal }); return () => ac.abort();}