Files
tweetdistributor/output/output.go
sirrow d794f65673 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>
2026-08-03 09:35:59 +09:00

58 lines
1.5 KiB
Go

package output
type Image struct {
Data []byte
ContentType string
Filename string
}
// Preview is a link preview card ("プレビュー窓") to attach to a post.
type Preview struct {
URL string
Title string
Description string
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.
type Ref struct {
ID string `json:"id,omitempty"` // twitter: tweet ID
URI string `json:"uri,omitempty"` // bluesky: at:// URI of the record
CID string `json:"cid,omitempty"` // bluesky: record CID
RootURI string `json:"rooturi,omitempty"`
RootCID string `json:"rootcid,omitempty"`
}
// IsZero reports whether the ref points at nothing.
func (r Ref) IsZero() bool {
return r == Ref{}
}
// Post is a single message to distribute.
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.
ReplyTo *Ref
}
type OutputInterface interface {
Write(Post) (Ref, error)
Delete(Ref) error
GetName() string
}