Skip to content

Commit

Permalink
Unification in home page
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-jagruti-a committed Dec 18, 2023
1 parent e66ec95 commit 54af504
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions blogs/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"
"utils"
"fmt"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -71,17 +72,18 @@ func Get(c *gin.Context) {
c.AbortWithStatus(http.StatusInternalServerError)
return
}

// bind data to struct
var blogs Blog
json.Unmarshal(responseData, &blogs)

filteredItems := []Item{}
existingBlogs := []Item{}

fmt.Println(blogs)
// filter weekly and newletteres
for _, item := range blogs.Items {

if !strings.Contains(strings.ToLower(item.Title), "weekly") && !strings.Contains(strings.ToLower(item.Title), "newsletter") {
item.Thumbnail = extractFirstImgSrc(item.Description)
item.Description = truncateTo20Words(item.Description)
filteredItems = append(filteredItems, item)
}
Expand Down Expand Up @@ -150,6 +152,18 @@ func truncateTo20Words(description string) string {
}
return strings.Join(words, " ") + "..."
}
func extractFirstImgSrc(description string) string {
imgRegex := regexp.MustCompile(`<img[^>]+\bsrc="([^"]+)"[^>]*>`)

match := imgRegex.FindStringSubmatch(description)

if len(match) > 1 {
return match[1]
}

return ""
}


// make array or slice unique
func Unique(arr []Item) []Item {
Expand Down

0 comments on commit 54af504

Please sign in to comment.