${cube(pal, 18)} no. ${String(idx + 1).padStart(2, '0')} — ${c.blurb}
/* a small town of posts. every post is a building shaped by what it is. */
const $ = (s, el = document) => el.querySelector(s);
const $$ = (s, el = document) => [...el.querySelectorAll(s)];
const TOWN = {
'writing-with-adhd': { kind: 'prose', build: 'prose', x: 1, y: 1, w: 4, d: 4, n: 7, p: 'peach', blurb: 'the tallest thing here. seven floors of wandering.' },
'ferrotype': { kind: 'code', build: 'code', x: 6.6, y: 1, w: 3, d: 3, n: 7, p: 'peri', blurb: 'rust types, poured into typescript moulds.' },
'building-ui-in-gpui': { kind: 'code', build: 'code', x: 11.2, y: 1.4, w: 2.6, d: 2.6, n: 4, p: 'sky', blurb: 'tips & tricks, floor by floor.' },
'fig-gen-making-generative-art-in-figma': { kind: 'image', build: 'image', x: 1, y: 6.8, w: 4, d: 3.2, n: 3, p: 'mint', blurb: 'a gallery hung with sine waves.' },
'design-workshop': { kind: 'image', build: 'image', x: 6.4, y: 6.6, w: 4, d: 3.2, n: 2, p: 'lilac', blurb: 'voxels, posters, lost worlds.' },
'spool': { kind: 'code', build: 'spool', x: 11.6, y: 6.8, w: 2.4, d: 2.4, p: 'peach', blurb: 'tasks wound into the repo.' },
'css-grid-lanes': { kind: 'code', build: 'lanes', x: 1.6, y: 11.6, w: 3, d: 3, p: 'mint', blurb: 'columns that pack themselves.' },
'the-black-magic-of-canvas-and-text-editing': { kind: 'note', build: 'note', x: 7.2, y: 11.8, w: 2, d: 2, p: 'sky', blurb: 'a kiosk of links.' },
};
let fallbackSlot = 0;
function conf(p) {
if (TOWN[p.slug]) return TOWN[p.slug];
const imgs = (p.html.match(/ 3 ? 'image' : pres > 1 ? 'code' : p.html.length < 2500 ? 'note' : 'prose';
return (TOWN[p.slug] = { kind, build: kind, x: 11 + (fallbackSlot++ % 2) * 2, y: 11.5, w: 2, d: 2, n: 3, p: 'butter', blurb: '' });
}
const KIND_GLYPH = { code: '▲', image: '■', prose: '●', note: '◆' };
let posts = [];
const app = $('#app');
const fmt = d => new Date(d + 'T12:00:00').toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
const words = html => html.replace(/
/g, '').replace(/<[^>]+>/g, ' ').split(/\s+/).filter(Boolean).length; const imgsOf = p => [...p.html.matchAll(/]*src="([^"]+)"/g)].map(m => m[1]); const strip = (html, title) => html.replace(/^\s*
]*>([\s\S]*?)<\/h1>\s*/, (m, i) => i.replace(/<[^>]+>/g, '').trim().toLowerCase() === title.toLowerCase() ? '' : m); const cube = (pal = PAL.peri, s = 22) => ``; function makeBuilding(p, u, opts = {}) { const c = conf(p); const b = Build[c.build](u, { ...c, p: PAL[c.p], img: imgsOf(p), ...opts }); return b; } // --------------------------------------------------------------- // background: drifting translucent triangles & hexes // --------------------------------------------------------------- (function bg() { const root = $('#bgshapes'); const shapes = ['M0 0 L40 23 L0 46Z', 'M20 0 L40 11.5 L40 34.5 L20 46 L0 34.5 L0 11.5Z', 'M0 23 L40 0 L40 46Z']; for (let i = 0; i < 22; i++) { const s = 18 + Math.random() * 60; const el = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); el.setAttribute('viewBox', '0 0 40 46'); el.setAttribute('width', s); el.setAttribute('height', s * 1.15); el.innerHTML = `
`; el.style.cssText = `left:${Math.random() * 100}%;top:${Math.random() * 100}%;animation-duration:${18 + Math.random() * 26}s;animation-delay:${-Math.random() * 30}s`; root.append(el); } })(); // --------------------------------------------------------------- // index: the town // --------------------------------------------------------------- let parallax = null; function renderIndex() { document.body.dataset.view = 'index'; const u = Math.max(22, Math.min(innerWidth * .026, innerHeight * .042)); app.innerHTML = ` `; const world = $('#world'); world.style.setProperty('--u', `${u}px`); const S = 15; world.style.width = `${S * u}px`; world.style.height = `${S * u}px`; // the island: two slabs, a path, a pond world.append(Iso.box(u, { x: -.6, y: -.6, w: S + 1.2, d: S + 1.2, z: -1.6, h: .9, p: PAL.lilac, cls: 'island low' })); world.append(Iso.box(u, { w: S, d: S, z: -.7, h: .7, p: PAL.ground, cls: 'island', top: 'gridtop' })); world.append(Iso.box(u, { x: 0, y: 5.4, w: S, d: .7, z: 0, h: .04, p: PAL.white, cls: 'path' })); world.append(Iso.box(u, { x: 5.6, y: 0, w: .7, d: S, z: 0, h: .04, p: PAL.white, cls: 'path' })); world.append(Iso.box(u, { x: 10.6, y: 10.6, w: 3.4, d: 3.4, z: -.3, h: .32, p: PAL.mint, cls: 'pond', top: 'water' })); // a few loose cubes [[14.2, 4.4, .6], [0.3, 15.5, .5], [9.8, 14.4, .45], [15.6, 9, .7]].forEach(([x, y, s], i) => world.append(Iso.box(u, { x, y, w: s, d: s, h: s, z: i === 3 ? 1.5 : 0, p: [PAL.peri, PAL.mint, PAL.butter, PAL.pink][i], cls: i === 3 ? 'bob' : '' }))); posts.forEach((p, i) => { const c = conf(p); const b = makeBuilding(p, u); const site = Iso.group('site', c.x, c.y, 0, u); site.dataset.slug = p.slug; site.style.setProperty('--i', i); site.append(b.el); const lift = b.top > 7 ? .8 : 1.2 + (i % 3) * .8; site.append(Iso.board(u, b.cx, b.cy, b.top + lift, `${String(i + 1).padStart(2, '0')} ${KIND_GLYPH[c.kind]}${p.title}`, 'tagb')); world.append(site); }); // hover sync between list, labels and buildings const sites = $$('.site', world); const focus = slug => { sites.forEach(s => s.classList.toggle('hot', s.dataset.slug === slug)); world.classList.toggle('focus', !!slug); $$('.t-list a').forEach(a => a.classList.toggle('hot', a.dataset.slug === slug)); }; sites.forEach(s => { s.addEventListener('pointerenter', () => focus(s.dataset.slug)); s.addEventListener('pointerleave', () => focus(null)); s.addEventListener('click', e => { e.preventDefault(); fly(s.dataset.slug); }); }); $$('.t-list a').forEach(a => { a.addEventListener('pointerenter', () => focus(a.dataset.slug)); a.addEventListener('pointerleave', () => focus(null)); a.addEventListener('click', e => { e.preventDefault(); fly(a.dataset.slug); }); }); // the world leans toward the cursor const st = { x: 0, y: 0, tx: 0, ty: 0 }; onpointermove = e => { st.tx = e.clientX / innerWidth - .5; st.ty = e.clientY / innerHeight - .5; }; cancelAnimationFrame(parallax); const loop = () => { st.x += (st.tx - st.x) * .06; st.y += (st.ty - st.y) * .06; world.style.transform = `rotateX(${58 - st.y * 6}deg) rotateZ(${45 + st.x * 10}deg)`; parallax = requestAnimationFrame(loop); }; loop(); const dbg = new URLSearchParams(location.search).get('hover'); if (dbg) focus(posts[+dbg].slug); } // fly toward a building, then open it function fly(slug) { const stage = $('#stage'), site = $(`.site[data-slug="${slug}"] .grp`); if (!stage || !site) { location.hash = slug; return; } const r = site.getBoundingClientRect(), sr = stage.getBoundingClientRect(); const dx = (r.left + r.width / 2) - (sr.left + sr.width / 2), dy = (r.top + r.height / 2) - (sr.top + sr.height / 2); stage.style.transform = `scale(3.2) translate(${-dx}px, ${-dy}px)`; document.body.classList.add('flying'); setTimeout(() => { location.hash = slug; }, 650); } // --------------------------------------------------------------- // post: a diorama that is built as you read // --------------------------------------------------------------- let floorsState = null; function renderPost(p) { cancelAnimationFrame(parallax); onpointermove = null; document.body.classList.remove('flying'); const c = conf(p); const pal = PAL[c.p]; document.body.dataset.view = 'post'; document.documentElement.style.setProperty('--acc-t', pal.t); document.documentElement.style.setProperty('--acc-s', pal.s); document.documentElement.style.setProperty('--acc-e', pal.e); const idx = posts.indexOf(p), next = posts[(idx + 1) % posts.length]; const wc = words(p.html); const html = strip(p.html, p.title); app.innerHTML = ` nate.rip
a small town of ${posts.length} posts
by nate butler — design, type systems, tools
- ▲ code
- ■ image
- ● prose
- ◆ note
${posts.map((p, i) => `
- ${KIND_GLYPH[conf(p).kind]}${p.title}${p.date.slice(0, 4)}
`).join('')}1 floor ≈ 1 section${''.repeat(24)}${Array.from({ length: 6 }, (_, i) => ``).join('')}`; // diorama const dworld = $('#dworld'); const u = Math.max(26, Math.min(innerWidth * .034, innerHeight * .05)); Iso.full = true; const big = makeBuilding(p, u, { n: Math.min(c.n ? c.n + 2 : 6, 9) }); const pad = 2; const W = Math.max(c.w, c.d) + pad * 2; dworld.style.width = dworld.style.height = `${W * u}px`; dworld.append(Iso.box(u, { x: 0, y: 0, w: W, d: W, z: -.8, h: .8, p: PAL.ground, top: 'gridtop', cls: 'island' })); const g = Iso.group('', pad + (W - pad * 2 - c.w) / 2, pad + (W - pad * 2 - c.d) / 2, 0, u); g.append(big.el); dworld.append(g); Iso.full = false; big.floors.forEach((f, i) => { if (i > 0) f.classList.add('pending'); }); floorsState = { floors: big.floors, shown: 1 }; updateFloors(); const body = $('.body', app); $$('a[href^="http"]', body).forEach(a => { a.target = '_blank'; a.rel = 'noopener'; }); $$('img', body).forEach(i => { i.loading = 'lazy'; }); $$('h2', body).forEach(h => h.insertAdjacentHTML('afterbegin', cube(pal, 26))); shape[c.kind]?.(body, p, pal); $$('p', body).forEach(par => { const imgs = $$('img', par); if (imgs.length && !par.textContent.trim()) { const fig = document.createElement('figure'); fig.className = 'frame'; imgs.forEach(i => fig.append(i)); if (imgs[0].alt) fig.insertAdjacentHTML('beforeend', ` ${cube(pal, 18)} no. ${String(idx + 1).padStart(2, '0')} — ${c.blurb}
${p.title}
${html}next building →${next.title}${cube(PAL[conf(next).p], 40)}${imgs[0].alt} `); par.replaceWith(fig); } }); reveal(); } function updateFloors() { if (!floorsState) return; const max = Math.max(1, document.documentElement.scrollHeight - innerHeight); const f = Math.min(1, scrollY / max); const n = floorsState.floors.length; const want = Math.max(Math.ceil(n * .25), Math.ceil(n * (.25 + .75 * f))); floorsState.floors.forEach((el, i) => el.classList.toggle('pending', i >= want)); const b = $('#built'); if (b) b.textContent = f > .985 ? 'complete ✓' : `building… ${Math.round(f * 100)}%`; } addEventListener('scroll', updateFloors, { passive: true }); const shape = { code(body, p, pal) { $$('pre', body).forEach((pre, i) => { const w = document.createElement('div'); w.className = 'chip'; w.innerHTML = `${cube(PAL.ink, 14)} block ${String(i + 1).padStart(2, '0')}`; pre.replaceWith(w); w.append(pre); }); }, image(body, p, pal) { if (!p.slug.startsWith('fig-gen')) return; // the favourite gens become monoliths standing in a row const imgs = $$('img', body).slice(3); if (!imgs.length) return; const holder = document.createElement('div'); holder.className = 'mono-wrap'; const w = document.createElement('div'); w.className = 'world mono'; const u = 42; w.style.width = `${imgs.length * 2.4 * u}px`; w.style.height = `${3 * u}px`; w.append(Iso.box(u, { x: -.6, y: -.4, w: imgs.length * 2.4 + .6, d: 2.6, z: -.4, h: .4, p: PAL.ground, top: 'gridtop' })); imgs.forEach((img, i) => { const m = Iso.box(u, { x: i * 2.4, y: 1, w: 1.8, d: .5, h: 5.4, p: PAL.ink, south: 'gen', cls: 'monolith' }); m.querySelector('.fs').style.backgroundImage = `url("${img.src}")`; m.style.setProperty('--i', i); w.append(m); img.closest('p')?.remove(); }); holder.append(w); const anchor = $$('p', body).find(x => /favorite gens/i.test(x.textContent)) || body.lastElementChild; anchor.after(holder); }, // sections become floors of a staircase prose(body) { const kids = [...body.childNodes]; const sections = []; let cur = document.createElement('section'); cur.className = 'flr'; sections.push(cur); kids.forEach(n => { if (n.nodeType === 1 && n.tagName === 'H2') { cur = document.createElement('section'); cur.className = 'flr'; sections.push(cur); } cur.append(n); }); body.innerHTML = ''; sections.forEach((s, i) => { s.style.setProperty('--step', i); s.dataset.floor = `floor ${String(i + 1).padStart(2, '0')}`; body.append(s); }); body.classList.add('stairs'); const ul = $('ul', body); if (ul) { ul.classList.add('blocks'); $$('li', ul).forEach((li, i) => li.insertAdjacentHTML('afterbegin', `${i + 1}`)); } }, note(body) { // each "**link** - author" paragraph becomes a tile const grid = document.createElement('div'); grid.className = 'tiles'; let pending = null; [...body.children].forEach(el => { const isLink = el.tagName === 'P' && el.firstElementChild?.tagName === 'A' && el.firstElementChild.querySelector('strong'); if (isLink) { pending = document.createElement('div'); pending.className = 'tile'; pending.innerHTML = el.innerHTML; grid.append(pending); el.remove(); } else if (pending && el.tagName === 'P' && !el.querySelector('strong')) { pending.insertAdjacentHTML('beforeend', `${el.innerHTML}
`); el.remove(); pending = null; } else if (/H[23]/.test(el.tagName)) { const h = el.cloneNode(true); h.className = 'tile-h'; grid.append(h); el.remove(); pending = null; } else if (el.tagName === 'UL' && grid.children.length) { const t = document.createElement('div'); t.className = 'tile list'; t.append(el); grid.append(t); } }); const first = body.querySelector('p'); (first || body).after(grid); }, }; function reveal() { const io = new IntersectionObserver(es => es.forEach(e => { if (e.isIntersecting) { e.target.classList.add('in'); io.unobserve(e.target); } }), { rootMargin: '0px 0px -6% 0px' }); $$('.ph > *, .body > *, .next', app).forEach((el, i) => { el.classList.add('rv'); el.style.setProperty('--rd', `${Math.min(i, 6) * 70}ms`); io.observe(el); }); } function route() { const slug = decodeURIComponent(location.hash.slice(1)); const p = posts.find(x => x.slug === slug); floorsState = null; scrollTo(0, 0); if (p) renderPost(p); else renderIndex(); } addEventListener('hashchange', route); addEventListener('resize', () => { if (document.body.dataset.view === 'index') renderIndex(); }); (async () => { posts = await fetch('../content/posts.json').then(r => r.json()); route(); })();