a love letter to tangled (android, iOS, and a search API)
at main 35 lines 1.0 kB view raw
1package normalize 2 3import "tangled.org/desertthunder.dev/twister/internal/store" 4 5const collectionString = "sh.tangled.string" 6 7// StringAdapter normalizes sh.tangled.string records (code snippets/gists). 8type StringAdapter struct{} 9 10func (a *StringAdapter) Collection() string { return collectionString } 11func (a *StringAdapter) RecordType() string { return "string" } 12 13func (a *StringAdapter) Searchable(record map[string]any) bool { 14 return str(record, "contents") != "" 15} 16 17func (a *StringAdapter) Normalize(event TapRecordEvent) (*store.Document, error) { 18 r := event.Record 19 rec := r.Record 20 21 return &store.Document{ 22 ID: StableID(r.DID, r.Collection, r.RKey), 23 DID: r.DID, 24 Collection: r.Collection, 25 RKey: r.RKey, 26 ATURI: BuildATURI(r.DID, r.Collection, r.RKey), 27 CID: r.CID, 28 RecordType: a.RecordType(), 29 Title: str(rec, "filename"), 30 Body: str(rec, "contents"), 31 Summary: str(rec, "description"), 32 TagsJSON: "[]", 33 CreatedAt: str(rec, "createdAt"), 34 }, nil 35}