Skip to content

Commit

Permalink
twitter: clean tweet link
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed May 6, 2023
1 parent 222da73 commit db83525
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/twitter/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package twitter
import (
"errors"
"net/url"
"regexp"
)

func EffectiveUrl(rawUrl string) (string, error) {
Expand All @@ -18,5 +19,7 @@ func EffectiveUrl(rawUrl string) (string, error) {
}
uri.RawQuery = ""
uri.Scheme = "https"
reTrimmer := regexp.MustCompile("/photo/[0-9]+$|/video/[0-9]+$|/retweets/with_comments$")
uri.Path = reTrimmer.ReplaceAllString(uri.Path, "")
return "https://publish.twitter.com/oembed?url=" + uri.String(), nil
}

0 comments on commit db83525

Please sign in to comment.