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:
@@ -14,6 +14,15 @@ type Preview struct {
|
||||
Thumb *Image
|
||||
}
|
||||
|
||||
// Link is a URL inside a post's text, located by the UTF-8 byte offsets
|
||||
// bluesky needs to mark it up: it does not linkify text on its own, so a URL
|
||||
// no one points at stays unclickable.
|
||||
type Link struct {
|
||||
URL string
|
||||
ByteStart int
|
||||
ByteEnd int
|
||||
}
|
||||
|
||||
// Ref identifies a post an output has already published so it can later be
|
||||
// replied to or deleted. The fields are output specific; only the ones the
|
||||
// publishing output filled in are meaningful to it.
|
||||
@@ -34,6 +43,7 @@ func (r Ref) IsZero() bool {
|
||||
type Post struct {
|
||||
Text string
|
||||
Images []Image
|
||||
Links []Link
|
||||
Preview *Preview
|
||||
// ReplyTo is the Ref this same output returned for the post being
|
||||
// replied to, or nil for a top level post.
|
||||
|
||||
Reference in New Issue
Block a user