The old WordPress version of this blog had comments, and for a few years they were lovely. Then they turned into a spam fest, and when I rebuilt the site I made one rule: no comment system, not hosted by me, not hosted by anyone.
People do reply to my posts, but on X, LinkedIn and increasingly Bluesky, so the conversation happens somewhere the post cannot see. I wanted the replies to come home.
This is part 2 of Building this blog. The lead-in explained how the blog is written in Obsidian and served from Cloudflare Pages. Here I tell you how the Discussion block works, why I built it three times, and why it now runs no code in your browser and needs no help from me, with the real code, data shapes and numbers.
The rule that shaped everything
Self-hosted comments were out, and so was any embeddable service that loads a script and sets cookies. That left the public platforms. X is where most people are, LinkedIn is where many of my clients live, and Bluesky is small but warm, with the friendliest API of the three. So the design became letting the conversation stay where it is, and showing a copy on the page. Every reply links back to its original, and you answer there, as yourself, with that platform’s spam controls doing the work WordPress never did for me.
Version 1: the browser reads the thread
The lead-in describes version 1. When a page with a Bluesky or Mastodon link scrolled into view, a small script fetched the public thread from the network’s own API and drew the replies.
For Bluesky that is one unauthenticated call:
For Bluesky that is one unauthenticated call to the public AppView:
text ShowHide 2 lines
GET https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread
?uri=at://<did>/app.bsky.feed.post/<rkey>&depth=6&parentHeight=0A handle in the link needs a resolveHandle call first. Mastodon is one call to /api/v1/statuses/<id>/context. I cached each answer in sessionStorage for ten minutes. The hard part was text.
Facets and byte offsets
A Bluesky post is plain text plus a list of facets, and each facet says “bytes 31 to 52 of this text are a link”. Mentions and hashtags work the same way. The offsets are UTF-8 byte offsets, while JavaScript strings are UTF-16, so one emoji earlier in the text and every character index is wrong. The fix is to work in bytes. Encode the text, slice the bytes, decode each slice:
The fix is to stop thinking in characters. Encode the text to bytes, slice the bytes, and decode each slice:
js ShowHide 15 lines
const bytes = new TextEncoder().encode(record.text || '');
const decoder = new TextDecoder();
let end = 0;
const facets = (record.facets || []).filter(f => f?.index)
.sort((a, b) => a.index.byteStart - b.index.byteStart);
for (const facet of facets) {
const { byteStart: start, byteEnd: stop } = facet.index;
// refuse overlaps, reversed ranges, out-of-bounds, and cuts inside a multi-byte character
if (start < end || stop <= start || stop > bytes.length ||
(bytes[start] & 0xc0) === 0x80 ||
(stop < bytes.length && (bytes[stop] & 0xc0) === 0x80)) continue;
parent.append(document.createTextNode(decoder.decode(bytes.slice(end, start))));
// ... then the facet's own slice, as a link only if the URI is http(s)
end = stop;
}That 0xc0 test matters. In UTF-8 every continuation byte looks like 10xxxxxx, so a facet that begins or ends on one is cutting a character in half, and I ignore it.
Mastodon replies arrive as HTML, which I will not insert into a page, so I parsed it into an inert document, kept text and safe links and rebuilt it with createTextNode. It worked.
Version 1: what it gave me, what it cost me
What it gave me:
- No build step and no job. Replies appear the moment someone replies, because the browser asks on page view.
- No service of mine in the path. I used the networks’ own public APIs, so there was nothing to host, key or pay for.
- A clean data model. Nothing was stored, so nothing could go stale.
What it cost me:
- Every reader’s browser called Bluesky and a Mastodon instance, and the cost of rate limits fell on each reader. The ten-minute
sessionStoragecache was my only defence. - It could only ever show networks with a public thread API. X and LinkedIn need credentials, so they got a bare “Discuss on X” button.
- The text handling was a risk surface I owned: facets, an inert HTML parse, a URL allow-list, an avatar host allow-list.
- The block set a minimum height while loading to limit layout shift, and without JavaScript there was only a link.
Why I moved. Most of my audience is on X, and version 1 could never show it, so the block told readers the conversation was happening elsewhere. I also do not have a Mastodon account, so that half of the code never got a seed and never showed a reply. My design notes record the other trigger as a decision: readers’ browsers should make no third-party calls. I cannot source more of the feeling than that. Version 1 went live on 22 November, and the replacement was merged the next day.
Version 2: sync the replies, render them at build time
I already use Zernio, a social scheduling service, to post the announcement for each piece to X, LinkedIn and Bluesky. Its inbox API also reads the comments on those posts. A scheduled job can ask Zernio for the replies and commit them as JSON, and Hugo turns the JSON into plain HTML at build time.

The lower row of that figure is version 2. A GitHub Action runs scripts/sync-comments.mjs (Node 20, no dependencies) every fifteen minutes and writes data/comments/<section>-<slug>.json. If anything a reader would see has changed, it commits and dispatches the production deploy. The upper row came later.
The seed was a note with URLs in it
In version 2 a page only got a Discussion block if its note in the vault said where the conversation was:
yaml ShowHide 4 lines
comments:
bluesky: https://bsky.app/profile/<handle>/post/3k1abcdexample
x: https://x.com/<handle>/status/1900000000000000001
linkedin: https://www.linkedin.com/feed/update/urn:li:share:7000000000000000001/I announced the post, Zernio returned the URLs of the three native posts, and I pasted them into the note. The publisher refuses to ship a note whose links are wrong, using an offline validator with one full-string pattern per platform:
python ShowHide 2 lines
'bluesky': PREFIX + r'bsky\.app/profile/[^/?#@]+/post/[A-Za-z0-9]{10,20}' + QUERY,
'x': PREFIX + r'(?:x\.com|twitter\.com)/' + NAME + r'/status/[0-9]+' + QUERY,PREFIX demands https:// and no whitespace or control characters. The validator also rejects unknown keys, URLs over 300 characters and duplicate comments keys, and each failure has a name such as comments-url-invalid.
How the sync finds the right thread
The sync turns three differently shaped URLs into one key per post with postKey: the numeric id after /status/ for X, the record key for Bluesky, and the number in urn:li:share:<n> for LinkedIn, giving keys such as x:1900000000000000001.
Each Zernio inbox item is keyed the same way from its permalink or id. LinkedIn is the sharp edge. A post has a share URN and a different activity URN, and Zernio reports the share one, so a link copied in the activity form matches nothing.
The sync finds pages with links without cloning the content repository. It compares the garden’s main sha with the one in _state.json, and only when that changes does it list the tree and read the unseen blobs in batched GraphQL queries of forty. Since the garden went private it does this with a read token.
A run that has nothing to do
Most runs have nothing to do, so the cheap path matters more than the clever one. The sequence is:
- One call for the garden
mainref. Same sha, nothing to rescan. - One call to Zernio’s
GET /inbox/comments?limit=100&view=summary, which lists posts with acommentCount. - Compare with the counts in state. Equal everywhere means no thread reads.
Two API calls, no commit, a few seconds. When a count changes, the script reads that thread (up to five pages of 100) and rewrites one JSON file. Once a day, after 03:00 UTC, it re-reads every thread with replies, because a count cannot show an edited reply or one I hid on the platform.
Never creating a black hole
I feared a sync that wedges quietly: a rate limit trips on X, every run fails, and the page shows month-old data while the Action stays green. The tests enforce each rule below.

Polling follows the age of the post, because a reply on a day-old post is far likelier than on a two-year-old one. The throttle comes from the clock, so a quiet run needs no state write:
js ShowHide 8 lines
export function isDue(prev, now) {
if (!prev) return true;
if (prev.nextAttempt && now < new Date(prev.nextAttempt)) return false;
const age = prev.created ? now - new Date(prev.created) : 0;
if (age < 48 * HOUR) return true;
if (age < 14 * 24 * HOUR) return now.getUTCMinutes() < 15;
return now.getUTCHours() === 3 && now.getUTCMinutes() < 15;
}Under 48 hours a post is checked every run, up to fourteen days in the first run of each hour, after that daily.
Platforms are isolated. A 429 on X sets a backoff for the X threads, honouring Retry-After, and LinkedIn and Bluesky are still read and committed. The backoff starts at fifteen minutes, doubles and caps at six hours, held in _state.json. A run reads at most twenty threads, and stops if X-RateLimit-Remaining falls to five. Zernio’s limit is 600 calls per window, so a normal day sits nowhere near it.
A failed platform leaves its stored JSON untouched, and an empty thread for a post that had replies is treated as a failure. After six consecutive failed runs the script writes a ::warning:: annotation and after twenty-four an ::error::, about an hour and a half and six hours. The run still exits 0 so the schedule goes on. Only a 401 fails it, because waiting does not fix a rejected key.
Two traps in the sync workflow
A commit pushed with the default GITHUB_TOKEN does not trigger other workflows. So the workflow asks for the deploy itself:
yaml ShowHide 10 lines
permissions:
contents: write
actions: write
concurrency:
group: sync-comments
cancel-in-progress: false
# ...
if [ "$DEPLOY" = "true" ]; then
gh workflow run deploy-production.yaml --ref main
fiDEPLOY is true only when a reader-visible file changed. A commit that only touches _state.json (a new backoff time, say) is pushed so the next run has its memory, but it is not deployed.
The second trap is a settings switch. Zernio’s X inbox capability is off by default, so I turned it on through the API (xCapabilities.inbox set to true). Otherwise the sync finds nothing, which looks exactly like a quiet post.
Version 2: what it gave me, what it cost me
What it gave me:
- X and LinkedIn replies as well as Bluesky, once the X inbox switch was on.
- Static HTML. Readers’ browsers call nobody, there is no script, and the replies are in the page, so they read without JavaScript.
- Moderation I control: a hide list, plus anything hidden on the platform.
- Failure handling I could test. Twenty offline tests cover matching, backoff, budgets and stale data.
What it cost me:
- Up to fifteen minutes before the sync sees a reply, plus a build. It is a mirror, not a live view.
- A dependency on Zernio, on the X inbox switch, and on X reads that are metered.
- The machinery in this post: age polling, backoff, state, annotations. It was more code than all of version 1.
- Replies, names and handles copied into a public repository.
- A manual seed. I still pasted three URLs into a note after every announcement.
Why I moved. The manual seed was the step left. My design notes list a seeding tool as a follow-up, and they say the seed is “announce the post and put the URLs in the note”, so every post needed a vault edit and a publisher run before it could show a thread. Beyond that I will keep the claim modest: it was the only manual step in the chain.
Version 3: the seed becomes automatic
Announcing a post meant copying three URLs out of Zernio into a vault note.
Zernio can call a webhook when a post is published. I registered one for post.platform.published, once per network, and post.published as a safety net. It points at a Cloudflare Pages Function, functions/hooks/zernio.js, which does as little as possible:
- Accept only POST and bodies under 256 KiB.
- Compute HMAC-SHA256 over the raw bytes with a Pages secret, compare in constant time with
X-Zernio-Signature, and answer 401 on a mismatch before parsing anything. - Ignore any other event and any test event.
- Dispatch the
Social Linksworkflow with three validated inputs and answer 202.
js ShowHide 6 lines
res = await fetch(`https://api.github.com/repos/${REPO}/actions/workflows/${WORKFLOW}/dispatches`, {
method: 'POST',
headers: { authorization: `Bearer ${env.GITHUB_DISPATCH_TOKEN}`, /* ... */ },
body: JSON.stringify({ ref: 'main', inputs: { post_id: postId, event_id: eventId, event } }),
});
return res.status === 204 ? reply(202, 'Accepted') : reply(502, 'Dispatch failed');The workflow re-reads the post from Zernio, so a forged or replayed event cannot write anything Zernio does not itself say. The dispatch token is fine-grained, limited to the one site repository, with Actions read and write and nothing else.
Finding the page a post announces
The workflow runs scripts/social-links.mjs. A Zernio post record does not say which page it announces, so the script looks for a link where I put one: the first https://damianflynn.com/posts/<slug>/ or /talks/<slug>/ URL in the content, the LinkedIn firstComment, or the second item of an X thread (threadItems). A post with no such link is ignored on purpose.
Then it normalises the platform’s own post URL. X reports twitter.com/i/web/status/<id>, with no username, so the script rewrites it to x.com/<account username>/status/<id> and checks it against a canonical pattern narrower than the vault validator. LinkedIn’s share URN is what Zernio reports, so the version 2 mismatch cannot bite.
The result lands in data/social/<kind>-<slug>.json:
json ShowHide 9 lines
{
"links": {
"bluesky": "https://bsky.app/profile/<handle>/post/3k2abcdexample",
"linkedin": "https://www.linkedin.com/feed/update/urn:li:share:7000000000000000002/",
"x": "https://x.com/<handle>/status/1900000000000000002"
},
"page": "/posts/markdown-notion-obsidian-building-this-blog/",
"updatedAt": "2026-11-24T11:39:39.031Z"
}The earliest announcement of a page on a network wins, and the file is rewritten only when a link is added. The workflow then commits and dispatches the deploy and a comment sync. The theme and the sync script take the union of the note’s comments: front matter and data/social, with front matter winning on a clash. A nightly run at 03:17 UTC backfills 30 days, because webhooks get lost.
A private garden, and two honest mistakes
Two mistakes are worth owning. My first token file held clipboard text and not a token, so the first attempt to use it failed. And repository secret names cannot start with GITHUB_, which I had to work around.
Then I proved it. A signed test event returned 202, the workflow ran in about twenty seconds, and a one-time backfill recorded the lead-in post and the Dublin talk. I did not edit a note.
Version 3: what it gave me, what it cost me
What it gave me:
- No manual step. Announce the post and the thread appears. The verified test run took about twenty seconds, and the next sync picks the replies up.
- No vault edit and no publisher run, and a nightly backfill behind the webhook catches anything dropped.
- A small attack surface for what it does: nothing unsigned does any work, and the token can only run workflows on one repository.
What it cost me:
- More moving parts: a Function, a workflow, a signing secret, a dispatch token and the Zernio webhook registration.
- Two Pages secrets and a token to renew. The token expires after about a year.
- A dependency on how I announce. If the post carries no link to the page in the right place, nothing is recorded.
- The garden went private on the same day, so the sync reads page front matter through the GitHub API with a read token. That is not a v3 cost, but it is one more credential in the chain.
Why I built it. The manual seed was the last human step, and this closes it. I cannot claim the garden going private caused it. It changed how the sync lists pages, and nothing else.


What lands in the repository
Each page gets one JSON file. This is the real shape, with an invented reply (the timestamp and ids are from the first run):
json ShowHide 21 lines
{
"fetchedAt": "2026-11-23T16:27:38.179Z",
"page": "/talks/agents-need-an-identity/",
"threads": [
{
"platform": "linkedin",
"url": "https://www.linkedin.com/feed/update/urn:li:share:7000000000000000001/",
"count": 1,
"comments": [
{
"id": "urn:li:comment:(urn:li:activity:…,…)",
"author": { "name": "Alex Example", "handle": "alex-example" },
"createdAt": "2026-11-23T11:06:05.828Z",
"likes": 0,
"replies": [],
"text": "A short reply."
}
]
}
]
}The normaliser strips HTML to plain text, caps replies at 2,000 characters, stores no avatar or image URL, and drops anything hidden on the platform or listed in _hidden.json. Keys are written sorted, so the same input gives the same bytes, which makes “no change, no commit” honest.
How it looks on the page
The theme is a Hugo partial that looks up site.Data.comments by <section>-<slug>, with no JavaScript. Names are shortened to a given name and family-name initial, so “Alex Example” shows as “Alex E.”, and there are no avatars. Replies nest to three levels, my own get an Owner badge, text is escaped, bare URLs become rel="nofollow ugc noopener" links, and every reply has a “View on X” link and each thread a “Reply on X”.
Moderation, privacy and cost
Moderation needs no queue. The platforms filter spam, and I hide anything else on the platform or by adding its id to _hidden.json. Nothing a visitor types touches my site.
On privacy, readers are better off: no third-party requests, no scripts, no cookies. Commenters are slightly worse off, because their public reply, name and handle are copied into a public Git repository whose history keeps them after a deletion. The page shows a short name, but the data holds the platform’s name. Shorten it when you write the data if that bothers you.
Cost is close to nothing. The Function runs about twice per announced network, against a free allowance of 100,000 a day. The workflows run on a public repository, so Action minutes are free. X reads are metered at fractions of a cent, so an X thread is read only when its count changes. The one chore is the dispatch token, which expires after about a year; the renewal steps are in my design notes.
What is still open
The first real replies have arrived: across the lead-in post and the Dublin talk there are three on LinkedIn and two on X, two of them mine, and none on Bluesky yet. Bluesky rests on tests until someone replies there.
Two things I want to build next:
- A fallback “join the conversation” block with prefilled compose links for posts that have no thread yet.
- A seeding tool for the back catalogue that drafts hooks, schedules them through Zernio and lets the webhook record the links.
What to steal
- Decide where conversation should live before you pick software.
- If a source cannot be read from a browser, read it from a job with credentials and publish the result as data.
- Seed automatically with a signed webhook that only triggers a job, and keep a nightly backfill behind it.
- Make the quiet run cheap and byte-identical, poll by age, isolate failures per source, keep stale data, and exit 0.
- A token-made push does not trigger other workflows, so dispatch the deploy yourself with a narrowly scoped token.
- If you parse facets, work in UTF-8 bytes and refuse offsets that land inside a character.
Have you brought conversation back to a static site, and where did you draw the line on privacy?
Next in the series: search that learns without watching.






