Skip to content

Commit

Permalink
feat: wrap links as hyperlink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse0Michael committed Aug 2, 2020
1 parent 879094e commit 441b3a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/ahmdrz/goinsta/v2 v2.4.5
github.com/aws/aws-lambda-go v1.13.3
github.com/dghubble/go-twitter v0.0.0-20190719072343-39e5462e111f
github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.3
github.com/joho/godotenv v1.3.0
github.com/kelseyhightower/envconfig v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg=
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
Expand Down
21 changes: 11 additions & 10 deletions pkg/fetcher/api_default_service.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
* jessemichael.me internal
*
* Internal workings of Jesse Michael
*
* API version: v1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package fetcher

import (
Expand All @@ -15,6 +6,7 @@ import (
"log"
"net/http"
"net/url"
"regexp"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -168,6 +160,8 @@ func (s *DefaultApiService) getTwitter(twitterID int64) ([]FeedItem, error) {

items := []FeedItem{}
for _, tweet := range tweets {
fmt.Printf("tweet: %+v", tweet)
fmt.Printf("\n\n\n\n")
tweetURL := fmt.Sprintf("https://twitter.com/%s/status/%s", tweet.User.ScreenName, tweet.IDStr)
author := fmt.Sprintf("<a href='%s' style='text-decoration: none' target='_top'><img class='twitter-avatar' src='%s'> %s: </a>", tweetURL, tweet.User.ProfileImageURL, tweet.User.ScreenName)
media := ""
Expand All @@ -185,13 +179,20 @@ func (s *DefaultApiService) getTwitter(twitterID int64) ([]FeedItem, error) {
Source: "twitter",
Url: tweetURL,
Media: []FeedItemMedia{},
Content: author + tweet.FullText + media,
Content: author + replaceTextWithHyperlink(tweet.FullText) + media,
}
items = append(items, item)
}
return items, nil
}

func replaceTextWithHyperlink(text string) string {
var re = regexp.MustCompile(`\bhttp\S*`)
return re.ReplaceAllStringFunc(text, func(s string) string {
return fmt.Sprintf(`<a href="%s">%s</a>`, s, s)
})
}

func (s *DefaultApiService) getInstagram(instagramID int64) ([]FeedItem, error) {
if s.iClient == nil || instagramID == 0 {
return nil, nil
Expand Down

0 comments on commit 441b3a5

Please sign in to comment.