make links in bluesky posts clickable

Bluesky linkifies nothing by itself. A URL in the text of a record is
plain text unless a richtext facet says which bytes of the post are a
link and where they point, so our posts carried URLs no one could press.

Each link now travels on the Post as an output.Link with the offsets of
the text it occupies, and the bluesky output turns those into
app.bsky.richtext.facet#link. The offsets are UTF-8 byte offsets, not
character counts: a facet measured in characters slides off the URL as
soon as any Japanese text precedes it, and underlines the wrong words.

Scanning moved from preview.go to findLinks in main.go, which now
reports every link with its offsets rather than just the first one; the
preview card still goes to the first, which is the one a reader meets
first. X is unaffected, as it linkifies URLs itself.

The facet feature only gains its lexicon type when marshalled, so the
test checks the encoded record rather than the struct.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-03 09:35:59 +09:00
parent 953664ff1c
commit d794f65673
7 changed files with 153 additions and 37 deletions

View File

@@ -18,17 +18,6 @@ import (
// tags. They belong in <head>, so reading further is wasted.
const maxHTMLBytes = 1 << 20
// findLink returns the first link in content, or "" if there is none.
func findLink(content string) string {
for _, match := range urlPattern.FindAllString(content, -1) {
raw := trimURL(match)
if u, err := url.Parse(raw); err == nil && u.Host != "" {
return raw
}
}
return ""
}
// linkPreview builds the preview card for a link. Bluesky shows no card of
// its own: whatever the record does not embed is not displayed, so every card
// has to be assembled here.