@@ -127,6 +127,7 @@ func (pb *PostBuilder) buildFor(server string, c *http.Client) (*postRequest, er
127127
128128 pb .parseLinks ()
129129 pb .parseMentions (server , c )
130+ pb .parseTags ()
130131 if len (pb .facets ) > 0 {
131132 record .Facets = make ([]facet , len (pb .facets ))
132133 for i , f := range pb .facets {
@@ -224,6 +225,29 @@ func (pb *PostBuilder) parseMentions(server string, c *http.Client) {
224225 }
225226}
226227
228+ func (pb * PostBuilder ) parseTags () {
229+ tag_regex := `[\s^](?P<tag>#[^\d\s]\S*)\b`
230+ r , err := regexp .Compile (tag_regex )
231+ if err != nil {
232+ log .Printf ("Error compiling regex: %v" , err )
233+ return
234+ }
235+ matches := r .FindAllSubmatchIndex ([]byte (pb .content ), - 1 )
236+ for _ , match := range matches {
237+ start := match [2 ] // start position of the tag group
238+ end := match [3 ]
239+ tag := pb .content [start + 1 : end ] // +1 to skip the '#' character
240+ f := & facet {
241+ Features : []feature {
242+ {Type : "app.bsky.richtext.facet#tag" , Tag : tag },
243+ },
244+ }
245+ f .Index .ByteStart = start
246+ f .Index .ByteEnd = end
247+ pb .facets = append (pb .facets , f )
248+ }
249+ }
250+
227251type postRequest struct {
228252 Repo string `json:"repo"`
229253 Collection string `json:"collection"`
@@ -252,8 +276,9 @@ type facet struct {
252276
253277type feature struct {
254278 Type string `json:"$type"`
255- Handle string `json:"handle,omitempty"`
256279 Did string `json:"did,omitempty"`
280+ Handle string `json:"handle,omitempty"`
281+ Tag string `json:"tag,omitempty"`
257282 Uri string `json:"uri,omitempty"`
258283}
259284
0 commit comments