Skip to content

Commit

Permalink
adding hashtag and url extraction for posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Parker-Kasiewicz committed Oct 27, 2024
1 parent c98e0fd commit 8f09c7d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/hydrator/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ func (h *Hydrator) flattenFullProfile(profile *bsky.ActorDefs_ProfileViewDetaile
return
}

func (h *Hydrator) flattenFacets(facets []*bsky.RichtextFacet) (hashtags []string, urls []string) {
if facets != nil {
for _, facet := range facets {
if facet != nil {
features := facet.Features
for _, feature := range features {
if feature.RichtextFacet_Tag != nil {
tag := feature.RichtextFacet_Tag.Tag
hashtags = append(hashtags, tag)
}
if feature.RichtextFacet_Link != nil {
url := feature.RichtextFacet_Link.Uri
urls = append(urls, url)
}
}
}
}
}
return
}

func (h *Hydrator) flattenPostView(post *bsky.FeedDefs_PostView) (result map[string]interface{}) {
if post == nil {
return nil
Expand Down Expand Up @@ -282,6 +303,10 @@ func (h *Hydrator) flattenPostView(post *bsky.FeedDefs_PostView) (result map[str
result["Embed"] = h.flattenEmbed(rec.Embed)
}

hashtags, urls := h.flattenFacets(rec.Facets)
result["Hashtags"] = hashtags
result["URLs"] = urls

return
}

Expand Down Expand Up @@ -311,6 +336,10 @@ func (h *Hydrator) flattenPost(post *bsky.FeedPost) (result map[string]interface
result["Embed"] = h.flattenEmbed(post.Embed)
}

hashtags, urls := h.flattenFacets(post.Facets)
result["Hashtags"] = hashtags
result["URLs"] = urls

return
}

Expand Down

0 comments on commit 8f09c7d

Please sign in to comment.