saturn
- 187 commits
- 2 branches
- 0 tags
- updated
- CI 2/2
feat: bring back posts
Verifiedsigned by Daniel Daum with SSH key SHA256:drhIqfmUzuijEg5lpF1wfHhbG2Z4ebL9Lf+nLCJWAfg
Showing 9 changed files with 866 additions and 40 deletions.
_routes.json
+1 −1
@@ -1,5 +1,5 @@11{22 "version": 1,3 "include": ["/about/*", "/now/*", "/blog/*", "/projects", "/projects/*", "/api/*"],3 "include": ["/", "/about/*", "/now/*", "/blog/*", "/posts/*", "/projects", "/projects/*", "/api/*"],44 "exclude": []55}
blog/index.html
+17 −2
@@ -103,11 +103,26 @@103103 <header class="page-header">104104 <h1><span aria-hidden="true">/</span>blog</h1>105105 <p class="meta">106 Things I've written — long-form writing and notes on107 what I've played, watched and read.106 Things I've written — short posts, long-form writing,107 and notes on what I've played, watched and read.108108 </p>109109 </header>110110111 <!-- POSTS: my newest bluesky post as a card, filled at the edge112 by social/posts.js. what's inside [data-posts] is the fallback -->113 <section aria-labelledby="blog-posts">114 <h2 class="section-label" id="blog-posts">posts</h2>115 <div data-posts="highlight">116 <p class="meta">117 posts are on118 <a href="https://bsky.app/profile/daum.dev">bluesky</a>.119 </p>120 </div>121 <p class="post-feed-more caps">122 <a href="/posts/">all posts →</a>123 </p>124 </section>125111126 <section aria-labelledby="blog-writing">112127 <h2 class="section-label" id="blog-writing">writing</h2>113128 <ol class="archive">
global.css
+264 −1
@@ -1428,6 +1428,264 @@ nav p {14281428 }14291429}143014301431/*============================*/1432/* components - posts feed */1433/*============================*/14341435/* my bluesky posts on / and /posts/, written in by social/posts.js.1436 a quiet log: dashed rules between posts, grey meta row, lime only on1437 links */1438.post-item {1439 display: flex;1440 flex-direction: column;1441 gap: 0.75rem;1442 padding: 1.5rem 0;1443 scroll-margin-top: 1rem;1444}14451446.post-item + .post-item {1447 border-top: 1px dashed var(--borders);1448}14491450/* arriving from a permalink: the post sits in the panel colour */1451.post-item:target {1452 margin-inline: -1rem;1453 padding-inline: 1rem;1454 background-color: var(--surface);1455 box-shadow: inset 2px 0 0 var(--accent);1456}14571458/* time left, reply right; both grey until hovered, like the footer */1459.post-item-meta {1460 display: flex;1461 flex-wrap: wrap;1462 justify-content: space-between;1463 align-items: baseline;1464 gap: 0.25rem 1rem;1465 margin: 0;1466 font-size: 0.75rem;1467 letter-spacing: 0.08em;1468}14691470.post-item-time,1471.post-item-reply {1472 color: var(--text-secondary);1473 border-bottom: 1px solid transparent;1474 transition:1475 color 150ms ease,1476 border-bottom-color 150ms ease;1477}14781479.post-item-time:hover,1480.post-item-reply:hover {1481 color: var(--accent);1482 border-bottom-color: var(--accent);1483}14841485.post-item-body {1486 margin: 0;1487}14881489/* one image keeps its shape, and so do video thumbnails */1490.post-item-media img,1491.post-item-video img {1492 width: auto;1493 height: auto;1494 max-height: 26rem;1495 border: 1px solid var(--borders);1496 border-radius: 2px;1497}14981499/* two or more: a cropped grid, two across */1500.post-item-media--grid {1501 display: grid;1502 grid-template-columns: 1fr 1fr;1503 gap: 0.4rem;1504}15051506.post-item-media--grid img {1507 width: 100%;1508 height: 100%;1509 aspect-ratio: 1;1510 object-fit: cover;1511}15121513/* a video: its thumbnail with a play mark, linking to bluesky to play */1514.post-item-video {1515 position: relative;1516 align-self: flex-start;1517}15181519.post-item-video::after {1520 content: "\25B6";1521 position: absolute;1522 inset: 50% auto auto 50%;1523 translate: -50% -50%;1524 display: grid;1525 place-items: center;1526 width: 3rem;1527 height: 3rem;1528 padding-left: 0.2rem;1529 border: 1px solid var(--borders);1530 background-color: color-mix(in srgb, var(--background-dark) 80%, transparent);1531 color: var(--text-headings);1532 font-size: 1rem;1533 transition:1534 color 150ms ease,1535 border-color 150ms ease;1536}15371538.post-item-video:hover::after {1539 color: var(--accent);1540 border-color: var(--accent);1541}15421543/* link cards and quoted posts */1544.post-item-card {1545 display: flex;1546 flex-direction: column;1547 gap: 0.3rem;1548 padding: 0.875rem 1rem;1549 border: 1px solid var(--borders);1550 background-color: var(--surface);1551 transition: border-color 150ms ease;1552}15531554.post-item-card:hover {1555 border-color: var(--accent);1556}15571558.post-item-card-title {1559 color: var(--text-headings);1560 font-size: 0.9375rem;1561}15621563.post-item-card-desc,1564.post-item-quote-text {1565 color: var(--text-body);1566 font-size: 0.85rem;1567 line-height: 1.55;1568 display: -webkit-box;1569 -webkit-box-orient: vertical;1570 -webkit-line-clamp: 2;1571 overflow: hidden;1572}15731574.post-item-quote-text {1575 -webkit-line-clamp: 4;1576}15771578.post-item-card-meta {1579 color: var(--text-secondary);1580 font-size: 0.75rem;1581 letter-spacing: 0.04em;1582}15831584.post-item-quote .post-item-card-meta {1585 color: var(--text-headings);1586}15871588.post-item-quote .post-item-card-meta span {1589 color: var(--text-secondary);1590}15911592.post-item-note {1593 margin: 0;1594 font-size: 0.85rem;1595}15961597/* a repost: small label before the time, the original post in a panel */1598.post-item-label {1599 margin-right: 0.5rem;1600 color: var(--text-secondary);1601}16021603.post-item-label::before {1604 content: "\21BB\00A0";1605}16061607.post-item-repost {1608 display: flex;1609 flex-direction: column;1610 gap: 0.75rem;1611 padding: 1rem;1612 border: 1px solid var(--borders);1613 background-color: var(--surface);1614}16151616.post-item-repost > .post-item-card-meta {1617 margin: 0;1618 color: var(--text-headings);1619}16201621.post-item-repost > .post-item-card-meta span {1622 color: var(--text-secondary);1623}16241625/* cards inside the panel step back down to the page colour */1626.post-item-repost .post-item-card {1627 background-color: var(--background-dark);1628}16291630/* the first post sits right under the label */1631.post-feed > .post-item:first-child:not(:target) {1632 padding-top: 0.25rem;1633}16341635.post-feed > .meta {1636 margin: 0;1637}16381639.post-feed > .post-item:last-child:not(:target) {1640 padding-bottom: 0.25rem;1641}16421643/* the newest post on /blog/: a small panel, set apart from the list1644 under it */1645.post-card {1646 display: flex;1647 flex-direction: column;1648 gap: 0.5rem;1649 padding: 1rem 1.25rem;1650 border: 1px solid var(--borders);1651 background-color: var(--surface);1652 transition: border-color 150ms ease;1653}16541655.post-card:hover {1656 border-color: var(--accent);1657}16581659.post-card-meta {1660 display: flex;1661 flex-wrap: wrap;1662 justify-content: space-between;1663 gap: 0.25rem 1rem;1664}16651666.post-card-meta,1667.post-card-extra {1668 font-size: 0.72rem;1669 letter-spacing: 0.08em;1670 color: var(--text-secondary);1671}16721673.post-card-text {1674 color: var(--text-headings);1675 font-size: 0.9375rem;1676 line-height: 1.6;1677 display: -webkit-box;1678 -webkit-box-orient: vertical;1679 -webkit-line-clamp: 4;1680 overflow: hidden;1681}16821683/* "all posts ->" under the posts on / and /blog/ */1684.post-feed-more {1685 margin: 1rem 0 0;1686 font-size: 0.85rem;1687}168814311689/*============================*/14321690/* components - id list */14331691/*============================*/@@ -2604,7 +2862,12 @@ footer nav a,26042862.comment-author,26052863.comment-time,26062864.comment-link,2607.id-row dt {2865.id-row dt,2866.post-item-time,2867.post-item-reply,2868.post-item-label,2869.post-card-meta,2870.post-card-extra {26082871 text-transform: uppercase;26092872}26102873
index.html
+17 −34
@@ -9,7 +9,7 @@99 />1010 <meta1111 http-equiv="Content-Security-Policy"12 content="default-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' https://assets.danieldaum.net; media-src 'self' https://assets.danieldaum.net;"12 content="default-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' https://assets.danieldaum.net https://cdn.bsky.app https://video.bsky.app; media-src 'self' https://assets.danieldaum.net;"1313 />1414 <meta name="referrer" content="strict-origin-when-cross-origin" />1515 <link@@ -111,6 +111,22 @@111111 </p>112112 </header>113113114 <!-- POSTS: my newest bluesky posts, filled at the edge by115 social/posts.js. what's inside [data-posts] is the fallback,116 shown when the pds can't be reached -->117 <section aria-labelledby="home-posts">118 <h2 class="section-label" id="home-posts">posts</h2>119 <div class="post-feed" data-posts="3">120 <p class="meta">121 posts are on122 <a href="https://bsky.app/profile/daum.dev">bluesky</a>.123 </p>124 </div>125 <p class="post-feed-more caps">126 <a href="/posts/">all posts →</a>127 </p>128 </section>129114130 <!-- WRITING, newest first: the latest five of /blog/'s rows. past115131 five, add an "all writing" link to /blog/ under the list -->116132 <section aria-labelledby="home-writing">@@ -149,39 +165,6 @@149165 </li>150166 </ol>151167 </section>152153 <!-- PROJECTS -->154 <section aria-label="projects">155 <h2 class="section-label">projects</h2>156157 <div class="card-grid">158 <!-- hidden: llm-generated project page159 <a class="card" href="/projects/holonet/">160 <p class="card-type">Sep '26 · game backend</p>161 <p class="card-title">Holonet</p>162 <p class="card-desc">163 A multiplayer video game backend in Go164 </p>165 <div class="pills">166 <span class="pill">#new</span>167 <span class="pill pill--dev">#in-development</span>168 </div>169 </a>170 -->171 <!-- hidden: old project page, /projects/ is showcase now172 <a class="card" href="/projects/saturn/">173 <p class="card-type">Jan '26 · re-design</p>174 <p class="card-title">Saturn</p>175 <p class="card-desc">176 A cozy yet minimalist personal website177 </p>178 </a>179 -->180 <a class="card card--more" href="/projects/">181 <p class="card-title">all projects →</p>182 </a>183 </div>184 </section>185168 </main>186169187170 <!-- ===== FOOTER ===== -->
posts/index.htmladded
+141 −0
@@ -0,0 +1,141 @@1<!doctype html>2<html lang="en">3 <head>4 <meta charset="UTF-8" />5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />6 <meta7 name="description"8 content="Short posts, written on Bluesky"9 />10 <meta11 http-equiv="Content-Security-Policy"12 content="default-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' https://assets.danieldaum.net https://cdn.bsky.app https://video.bsky.app; media-src 'self' https://assets.danieldaum.net;"13 />14 <meta name="referrer" content="strict-origin-when-cross-origin" />15 <link16 rel="preload"17 href="/assets/fonts/geistpixel/GeistPixel-Square.woff2"18 as="font"19 type="font/woff2"20 crossorigin21 />22 <link rel="preconnect" href="https://assets.danieldaum.net" />23 <link rel="stylesheet" href="/global.css" />24 <script src="/theme.js"></script>25 <link26 rel="icon"27 type="image/png"28 sizes="32x32"29 href="/assets/favicon/favicon-32x32.png"30 />31 <link32 rel="icon"33 type="image/png"34 sizes="16x16"35 href="/assets/favicon/favicon-16x16.png"36 />37 <link38 rel="apple-touch-icon"39 sizes="180x180"40 href="/assets/favicon/apple-touch-icon.png"41 />42 <link rel="manifest" href="/assets/favicon/site.webmanifest" />43 <link44 rel="alternate"45 type="application/atom+xml"46 title="daniel daum"47 href="https://danieldaum.net/feed.xml"48 />49 <title>daniel daum - posts</title>5051 <meta property="og:type" content="website" />52 <meta property="og:site_name" content="daniel daum" />53 <meta property="og:title" content="daniel daum - posts" />54 <meta55 property="og:description"56 content="Short posts, written on Bluesky"57 />58 <meta property="og:url" content="https://danieldaum.net/posts/" />59 <meta60 property="og:image"61 content="https://assets.danieldaum.net/img/misc/og.jpg"62 />63 <meta property="og:image:type" content="image/jpeg" />64 <meta property="og:image:width" content="1200" />65 <meta property="og:image:height" content="630" />66 <meta67 property="og:image:alt"68 content="daniel daum - software engineer, avid reader, aspiring game dev - danieldaum.net"69 />7071 <meta name="twitter:card" content="summary_large_image" />72 <meta name="twitter:title" content="daniel daum - posts" />73 <meta74 name="twitter:description"75 content="Short posts, written on Bluesky"76 />77 <meta78 name="twitter:image"79 content="https://assets.danieldaum.net/img/misc/og.jpg"80 />81 <meta82 name="twitter:image:alt"83 content="daniel daum - software engineer, avid reader, aspiring game dev - danieldaum.net"84 />85 </head>8687 <body>88 <a class="skip-link" href="#main">skip to content</a>8990 <!-- ===== HEADER ===== -->91 <header class="site-header">92 <a class="site-name" href="/">Daniel Daum</a>93 <nav aria-label="main navigation">94 <a href="/about/">about</a>95 <a href="/blog/" aria-current="page">blog</a>96 <a href="/projects/">projects</a>97 <a href="/garden/">garden</a>98 </nav>99 </header>100101 <!-- ===== MAIN ===== -->102 <main id="main">103 <nav class="breadcrumb" aria-label="breadcrumb">104 <a href="/blog/">blog</a> <span aria-hidden="true">-></span>105 <a href="/posts/">posts</a>106 </nav>107108 <header class="page-header">109 <h1><span aria-hidden="true">/</span>posts</h1>110 <p class="meta">111 Short posts. Written on112 <a href="https://bsky.app/profile/daum.dev">bluesky</a>113 and shown here.114 </p>115 </header>116117 <!-- every post, newest first, filled at the edge by118 social/posts.js. what's inside [data-posts] is the fallback -->119 <section class="post-feed" aria-label="posts" data-posts="all">120 <p class="meta">121 posts couldn't load right now. they're all on122 <a href="https://bsky.app/profile/daum.dev">bluesky</a>.123 </p>124 </section>125 </main>126127 <!-- ===== FOOTER ===== -->128 <footer>129 <nav aria-label="site links">130 <p aria-hidden="true">//</p>131 <a href="mailto:daniel@danieldaum.net"> email </a>132 <a href="/projects/saturn/">source</a>133 <a href="/id/">ID</a>134 <a href="/changelog/">changelog</a>135 <a href="/privacy/">privacy</a>136 <a href="/feed.xml">feed</a>137 <button type="button" class="theme-button">theme</button>138 </nav>139 </footer>140 </body>141</html>
privacy/index.html
+10 −1
@@ -107,7 +107,7 @@107107 </p>108108 <h1>Privacy Policy</h1>109109 <p class="meta caps">110 <time datetime="2026-10-15">15 October 2026</time>110 <time datetime="2026-11-24">24 November 2026</time>111111 </p>112112 </header>113113@@ -153,6 +153,15 @@153153 me if you want your comment taken down.154154 </p>155155156 <h2 class="caps">Posts</h2>157 <p>158 The posts on the home page are from my Bluesky account.159 This site fetches them, so Bluesky never sees you open160 the page. Pictures in a post load from Bluesky's image161 servers, so if a post has one, Bluesky sees your IP162 when it loads. Links go to Bluesky.163 </p>164156165 <h2 class="caps">Email</h2>157166 <p>If you email me, I have your email. That's it.</p>158167
social/README.md
+27 −0
@@ -11,6 +11,7 @@ likes and comments. everything for them lives in this folder, and none of it is1111| `functions/api/like.js` | the like button posts here |1212| `functions/api/moderate.js` | the approve/delete page linked from new-comment emails |1313| `functions/projects/` | not social: `/projects/` is showcase at code.danieldaum.net, redirected or proxied |14| `posts.js` | not social: my bluesky posts on `/`, `/blog/` and `/posts/`, called from `_middleware.js`. see [posts](#posts) |1415| `email.js` | email worker: turns mail sent to `reply@replies.danieldaum.net` into comments |1516| `schema.sql` | the d1 tables: `Likes`, `LikeVoters`, `Comments` |1617| `wrangler.toml` | pages config (d1 binding) |@@ -56,6 +57,32 @@ this works on `/about/`, `/now/<slug>/` and `/blog/<slug>/`. `/projects/` is sho56573. add the section to the pages57584. `mise run social-email`: the worker uses `isLikeable()` too, so it rejects comments for the new pages until it's redeployed585960## posts6162my bluesky posts and reposts, newest first, replies left out:6364| page | `data-posts` | shows |65| --- | --- | --- |66| `/` | `3` | the newest 3 |67| `/blog/` | `highlight` | the newest one as a card |68| `/posts/` | `all` | every post, each with an id so `/posts/#<rkey>` links to it |6970`posts.js` reads which posts exist from my pds (`home.daum.dev`) and asks bluesky's appview for the rest: reposted and quoted text, and image thumbnails, which load from `cdn.bsky.app`. `_middleware.js` hands it the pages in `POST_PAGES`, and it writes each `[data-posts]`. whatever is inside the element in the html is the fallback.7172**it never slows the site down:**7374- it runs on those three pages only. every other page and file is served straight from pages, no function (`/_routes.json`)75- the post data comes from cloudflare's cache, shared by all three pages. once it's 5 minutes old, visitors still get the cached copy and a refresh runs after the response is sent76- only an empty cache (first visit after a deploy, or a new colo) waits, at most 800 ms. past that the page goes out with its fallback and the refresh finishes in the background77- if the pds is down, the cached posts are kept for a day before the fallback shows78- no js in the browser. images are lazy, sized thumbnails7980the micro posts version that came before had no `_routes.json`, so a function ran on every request on the site, and it waited on the pds with no limit.8182**changing it:** `FRESH`, `WAIT` and `CACHE_KEY` are at the top of `posts.js`; bump `CACHE_KEY` when the shape of the cached data changes. a new page needs its path in `POST_PAGES` and `/_routes.json`. pages with images need `https://cdn.bsky.app` (and `https://video.bsky.app` for video thumbnails) in their `img-src`.8384**locally:** `mise run serve` doesn't run functions, so it shows the fallback. `mise run social-dev` shows real posts on `localhost:8788`.855986## deploying60876188- **functions:** automatic. on every push, ci (`.gitea/workflows/deploy.yaml`) runs wrangler from this folder
social/functions/_middleware.js
+4 −1
@@ -1,11 +1,14 @@11// fills [data-social] with likes and comments from d1. if anything fails the2// page keeps its fallback text. runs on the paths in /_routes.json2// page keeps its fallback text. runs on the paths in /_routes.json.3// /, /blog/ and /posts/ get my bluesky posts instead (../posts.js)3445import { isLikeable, voterId, renderSocial } from "../lib.js";6import { POST_PAGES, withPosts } from "../posts.js";5768export async function onRequest(context) {79 const { request, env } = context;810 const { pathname } = new URL(request.url);11 if (POST_PAGES.has(pathname) && (request.method === "GET" || request.method === "HEAD")) return withPosts(context);912 if (!isLikeable(pathname)) return context.next();10131114 // the file never changes, so a 304 would show stale counts
social/posts.jsadded
+385 −0
@@ -0,0 +1,385 @@1// my bluesky posts on the site: the newest 3 on /, the newest one as a card2// on /blog/, all of them on /posts/. my posts and reposts, newest first,3// replies dropped. which posts exist comes from my pds; bluesky's appview4// fills in what the pds doesn't hold (reposted and quoted text, image5// thumbnails on bluesky's cdn). nothing here runs in the browser.6//7// the pages never wait on my pds. the posts come from cloudflare's cache;8// once they're FRESH seconds old the next visitor still gets the cached copy9// and a refresh runs after the response is sent. only an empty cache waits,10// and never more than WAIT ms: past that the page goes out with its fallback11// text and the refresh carries on in the background for the next visitor.12// see README "posts"1314const PDS = "https://home.daum.dev";15const DID = "did:plc:e3z5gj5iyuwgqao562bo4bdf";16const HANDLE = "daum.dev";17const APPVIEW = "https://public.api.bsky.app";18const TZ = "America/Los_Angeles";1920const FRESH = 300; // seconds21const WAIT = 800; // ms, empty cache only22const FETCH_TIMEOUT = 8000; // ms, the background refresh23const CACHE_KEY = "/__posts/v2"; // bump when the cached data's shape changes2425// the pages that show posts, and the only ones that ever cause a pds fetch.26// each also needs its path in /_routes.json27export const POST_PAGES = new Set(["/", "/blog/", "/posts/"]);2829// fills each [data-posts] on the page: "highlight" (the newest, as a card),30// "all", or a number. what's inside it is the fallback, kept if the pds31// can't be read32export async function withPosts(context) {33 const { request } = context;3435 // the file never changes, so a 304 would show stale posts36 const fresh = new Request(request);37 fresh.headers.delete("If-None-Match");38 fresh.headers.delete("If-Modified-Since");39 const response = await context.next(fresh);40 if (!(response.headers.get("content-type") || "").includes("text/html")) return response;4142 let items = null;43 try {44 items = await cachedItems(context);45 } catch {}46 if (items === null) return response;4748 const page = new HTMLRewriter()49 .on("[data-posts]", {50 element(el) {51 el.setInnerContent(render(items, el.getAttribute("data-posts")), { html: true });52 },53 })54 .transform(response);5556 const out = new Response(page.body, page);57 out.headers.set("Cache-Control", "public, max-age=0, must-revalidate");58 out.headers.delete("ETag");59 return out;60}6162function render(items, mode) {63 if (items.length === 0) return `<p class="meta">nothing posted yet.</p>`;64 if (mode === "highlight") return renderHighlight(items[0]);65 const shown = mode === "all" ? items : items.slice(0, Number(mode) || 3);66 return shown.map(renderItem).join("\n");67}6869// ---------------------------------------------------------------------------70// cache7172// every post, or null for the fallback73async function cachedItems(context) {74 const cache = caches.default;75 const key = new Request(new URL(CACHE_KEY, context.request.url));76 const hit = await cache.match(key);77 const age = hit ? (Date.now() - Number(hit.headers.get("X-Fetched-At"))) / 1000 : Infinity;78 if (hit && age < FRESH) return hit.json();7980 const refresh = loadItems(AbortSignal.timeout(FETCH_TIMEOUT)).then(async (items) => {81 // kept a day so a pds outage serves old posts, not the fallback82 const stored = new Response(JSON.stringify(items), {83 headers: {84 "Content-Type": "application/json",85 "Cache-Control": "public, max-age=86400",86 "X-Fetched-At": String(Date.now()),87 },88 });89 await cache.put(key, stored);90 return items;91 });92 context.waitUntil(refresh.catch(() => {}));9394 if (hit) return hit.json();95 const timeout = new Promise((resolve) => setTimeout(() => resolve(null), WAIT));96 return Promise.race([refresh.catch(() => null), timeout]);97}9899// ---------------------------------------------------------------------------100// data101102// every post and repost, newest first, each with the appview's copy of the103// post (`view`, missing if the appview failed). throws if the pds can't be read104async function loadItems(signal) {105 const [posts, reposts] = await Promise.all([106 listRecords("app.bsky.feed.post", signal),107 listRecords("app.bsky.feed.repost", signal),108 ]);109110 const items = [111 ...posts112 .filter((r) => typeof r.value?.text === "string" && !r.value.reply)113 .map((r) => ({ rkey: rkeyOf(r.uri), uri: r.uri, createdAt: r.value.createdAt, record: r.value })),114 ...reposts115 .filter((r) => typeof r.value?.subject?.uri === "string")116 .map((r) => ({ rkey: rkeyOf(r.uri), uri: r.value.subject.uri, createdAt: r.value.createdAt, repost: true })),117 ].sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));118119 const views = await getPosts(items.map((i) => i.uri), signal);120 for (const item of items) item.view = views.get(item.uri);121 return items;122}123124async function listRecords(collection, signal) {125 const records = [];126 let cursor;127 do {128 const url = new URL("/xrpc/com.atproto.repo.listRecords", PDS);129 url.searchParams.set("repo", DID);130 url.searchParams.set("collection", collection);131 url.searchParams.set("limit", "100");132 if (cursor) url.searchParams.set("cursor", cursor);133 const res = await fetch(url, { signal });134 if (!res.ok) throw new Error(`listRecords ${collection}: ${res.status}`);135 const page = await res.json();136 records.push(...(page.records ?? []));137 cursor = page.records?.length ? page.cursor : undefined;138 } while (cursor);139 return records;140}141142// the appview's hydrated copy of each post, by uri, 25 per call. whatever143// it returned before failing144async function getPosts(uris, signal) {145 const views = new Map();146 try {147 for (let i = 0; i < uris.length; i += 25) {148 const url = new URL("/xrpc/app.bsky.feed.getPosts", APPVIEW);149 for (const uri of uris.slice(i, i + 25)) url.searchParams.append("uris", uri);150 const res = await fetch(url, { signal });151 if (!res.ok) break;152 for (const view of (await res.json()).posts ?? []) views.set(view.uri, view);153 }154 } catch {}155 return views;156}157158function rkeyOf(uri) {159 return uri.split("/").pop();160}161162// ---------------------------------------------------------------------------163// rendering164165// one post on / or /posts/. the time is its permalink on /posts/; replying166// happens on bluesky. a repost shows the original in a panel167function renderItem(item) {168 const { view } = item;169 const href = postHref(item.uri);170 const lines = [171 `<article class="post-item${item.repost ? " post-item--repost" : ""}" id="${esc(item.rkey)}">`,172 ` <p class="post-item-meta">`,173 ` <span>${item.repost ? `<span class="post-item-label">reposted</span> ` : ""}<a class="post-item-time" href="/posts/#${esc(item.rkey)}"><time datetime="${esc(item.createdAt)}">${formatDate(item.createdAt)}</time></a></span>`,174 ` <a class="post-item-reply" href="${href}">reply on bluesky</a>`,175 ` </p>`,176 ];177178 if (!item.repost) {179 lines.push(...body(item.record, view, href));180 } else if (typeof view?.record?.text !== "string") {181 lines.push(` <p class="post-item-note"><a href="${href}">reposted post → view on bluesky</a></p>`);182 } else {183 lines.push(184 ` <div class="post-item-repost">`,185 ` <p class="post-item-card-meta">${author(view.author)}</p>`,186 ...body(view.record, view, href).map((l) => ` ${l}`),187 ` </div>`,188 );189 }190191 lines.push(`</article>`);192 return lines.join("\n");193}194195// the newest post on /blog/: a small card, text only, linking to it on /posts/196function renderHighlight(item) {197 const record = item.repost ? item.view?.record : item.record;198 const who = item.repost ? `${item.view?.author?.displayName || item.view?.author?.handle || ""}: ` : "";199 const extras = attachments(item.view?.embed);200 const text = record?.text?.trim() || extras.join(", ") || "view post";201 return [202 `<a class="post-card" href="/posts/#${esc(item.rkey)}">`,203 ` <span class="post-card-meta">`,204 ` <span>${item.repost ? "↻ reposted" : "@" + HANDLE}</span>`,205 ` <time datetime="${esc(item.createdAt)}">${formatDate(item.createdAt)}</time>`,206 ` </span>`,207 ` <span class="post-card-text">${escText(who + text)}</span>`,208 extras.length ? ` <span class="post-card-extra">${escText(extras.join(" · "))}</span>` : null,209 `</a>`,210 ].filter((l) => l !== null).join("\n");211}212213// "2 images", "video", "link", "quote"214function attachments(embed) {215 switch (embed?.$type) {216 case "app.bsky.embed.images#view": {217 const n = embed.images?.length || 0;218 return n ? [n === 1 ? "1 image" : `${n} images`] : [];219 }220 case "app.bsky.embed.video#view":221 return ["video"];222 case "app.bsky.embed.external#view":223 return ["link"];224 case "app.bsky.embed.record#view":225 return ["quote"];226 case "app.bsky.embed.recordWithMedia#view":227 return [...attachments(embed.media), "quote"];228 default:229 return [];230 }231}232233// text, then whatever is attached. with no appview copy, attachments are a link234function body(record, view, href) {235 const lines = [];236 if (record.text.trim()) {237 lines.push(` <p class="post-item-body">${renderText(record.text, record.facets)}</p>`);238 }239 if (view?.embed) {240 lines.push(...renderEmbed(view.embed, href).map((l) => ` ${l}`));241 } else if (record.embed) {242 lines.push(` <p class="post-item-note"><a href="${href}">attachment → view on bluesky</a></p>`);243 }244 return lines;245}246247// facets index the text by utf-8 byte offset, not by js string index248function renderText(text, facets = []) {249 const bytes = new TextEncoder().encode(text);250 const decode = (from, to) => new TextDecoder().decode(bytes.slice(from, to));251 const sorted = facets252 .filter((f) => f.index && f.features?.length)253 .sort((a, b) => a.index.byteStart - b.index.byteStart);254255 let out = "";256 let pos = 0;257 for (const facet of sorted) {258 const { byteStart, byteEnd } = facet.index;259 if (byteStart < pos) continue;260 out += escText(decode(pos, byteStart));261 const label = escText(decode(byteStart, byteEnd));262 const link = facetHref(facet.features[0]);263 out += link ? `<a href="${esc(link)}">${label}</a>` : label;264 pos = byteEnd;265 }266 return out + escText(decode(pos));267}268269function facetHref(feature) {270 switch (feature.$type) {271 case "app.bsky.richtext.facet#link":272 return /^https?:\/\//.test(feature.uri) ? feature.uri : null;273 case "app.bsky.richtext.facet#mention":274 return `https://bsky.app/profile/${feature.did}`;275 case "app.bsky.richtext.facet#tag":276 return `https://bsky.app/hashtag/${encodeURIComponent(feature.tag)}`;277 default:278 return null;279 }280}281282// the appview's embed views. images are its thumbnails, never full size283function renderEmbed(embed, href) {284 switch (embed.$type) {285 case "app.bsky.embed.images#view":286 return renderImages(embed.images);287 case "app.bsky.embed.video#view":288 return renderVideo(embed, href);289 case "app.bsky.embed.external#view":290 return renderCard(embed.external);291 case "app.bsky.embed.record#view":292 return renderQuote(embed.record);293 case "app.bsky.embed.recordWithMedia#view":294 return [...renderEmbed(embed.media, href), ...renderQuote(embed.record?.record)];295 default:296 return [];297 }298}299300// one image keeps its shape; two or more go in a cropped grid301function renderImages(images = []) {302 const imgs = images303 .filter((img) => isHttps(img.thumb))304 .map((img) => `<img src="${esc(img.thumb)}" alt="${esc(img.alt || "")}"${sizeAttrs(img.aspectRatio)} loading="lazy" decoding="async" />`);305 if (imgs.length === 0) return [];306 const cls = imgs.length === 1 ? "post-item-media" : "post-item-media post-item-media--grid";307 return [`<div class="${cls}">`, ...imgs.map((i) => ` ${i}`), `</div>`];308}309310// the thumbnail with a play mark; it plays on bluesky311function renderVideo(embed, href) {312 if (!isHttps(embed.thumbnail)) {313 return [`<p class="post-item-note"><a href="${href}">video → watch on bluesky</a></p>`];314 }315 const alt = embed.alt ? `${embed.alt} (video, plays on bluesky)` : "video, plays on bluesky";316 return [317 `<a class="post-item-video" href="${href}">`,318 ` <img src="${esc(embed.thumbnail)}" alt="${esc(alt)}"${sizeAttrs(embed.aspectRatio)} loading="lazy" decoding="async" />`,319 `</a>`,320 ];321}322323function renderCard(external) {324 if (!isHttps(external?.uri, true)) return [];325 const domain = new URL(external.uri).hostname.replace(/^www\./, "");326 return [327 `<a class="post-item-card" href="${esc(external.uri)}">`,328 ` <span class="post-item-card-title">${escText(external.title || domain)}</span>`,329 external.description ? ` <span class="post-item-card-desc">${escText(external.description)}</span>` : null,330 ` <span class="post-item-card-meta">${escText(domain)}</span>`,331 `</a>`,332 ].filter((l) => l !== null);333}334335function renderQuote(record) {336 const href = postHref(record?.uri);337 if (!href) return [];338 if (record.$type !== "app.bsky.embed.record#viewRecord" || typeof record.value?.text !== "string") {339 return [`<p class="post-item-note"><a href="${href}">quoting →</a></p>`];340 }341 return [342 `<a class="post-item-card post-item-quote" href="${href}">`,343 ` <span class="post-item-card-meta">${author(record.author)}</span>`,344 ` <span class="post-item-quote-text">${escText(record.value.text)}</span>`,345 `</a>`,346 ];347}348349function author(a = {}) {350 const name = a.displayName || a.handle || "";351 return `${escText(name)} <span>@${escText(a.handle || "")}</span>`;352}353354// at://did/app.bsky.feed.post/rkey -> https://bsky.app/profile/<handle or did>/post/rkey355function postHref(uri) {356 const match = /^at:\/\/([^/]+)\/app\.bsky\.feed\.post\/([^/]+)$/.exec(uri || "");357 if (!match) return null;358 const who = match[1] === DID ? HANDLE : match[1];359 return `https://bsky.app/profile/${who}/post/${match[2]}`;360}361362function isHttps(url, orHttp = false) {363 return typeof url === "string" && (orHttp ? /^https?:\/\// : /^https:\/\//).test(url);364}365366function sizeAttrs(ratio) {367 return ratio?.width && ratio?.height ? ` width="${ratio.width}" height="${ratio.height}"` : "";368}369370// 8 Oct 2026, 1:42 pm371function formatDate(iso) {372 const d = new Date(iso);373 if (Number.isNaN(d.getTime())) return "";374 const day = d.toLocaleDateString("en-GB", { timeZone: TZ, day: "numeric", month: "short", year: "numeric" });375 const time = d.toLocaleTimeString("en-US", { timeZone: TZ, hour: "numeric", minute: "2-digit" }).toLowerCase();376 return `${day}, ${time}`;377}378379function escText(s) {380 return esc(s).replace(/\n/g, "<br />");381}382383function esc(s) {384 return String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);385}