Skip to content

Commit

Permalink
handle twitter mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Sep 9, 2021
1 parent 7e63656 commit 346be83
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/twitter/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func externalName(external string) string {
return "image: " + external + "\n"
} else if strings.Contains(external, "t.co") {
return "external: " + external + "\n"
} else if external != "" {
panic("unknown not external URL passed: " + external)
}
return ""
}
Expand Down Expand Up @@ -66,7 +68,8 @@ func paragraph(html string) (string, []string) {
if err != nil {
panic(err)
}
removeHashtagsLinks(doc.Find("p a"))
removeAllHashtagLinks(doc.Find("p a"))
removeAllMentionLinks(doc.Find("p a"))
external := popExternalLinks(doc.Find("p a"))
msg, err := doc.Find("p").Html()
if err != nil {
Expand All @@ -87,7 +90,16 @@ func popExternalLinks(sel *goquery.Selection) (ret []string) {
return ret
}

func removeHashtagsLinks(sel *goquery.Selection) {
func removeAllMentionLinks(sel *goquery.Selection) {
sel.Each(func(i int, s *goquery.Selection) {
mention := s.Text()
if strings.HasPrefix(mention, "@") {
s.ReplaceWithHtml(mention)
}
})
}

func removeAllHashtagLinks(sel *goquery.Selection) {
sel.Each(func(i int, s *goquery.Selection) {
hashtag := s.Text()
if strings.HasPrefix(hashtag, "#") {
Expand Down

0 comments on commit 346be83

Please sign in to comment.