From 54af50434e9920ed30db2f3926abf18187406a01 Mon Sep 17 00:00:00 2001 From: cp-jagruti-a Date: Mon, 18 Dec 2023 10:51:32 +0530 Subject: [PATCH] Unification in home page --- blogs/blog.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/blogs/blog.go b/blogs/blog.go index ad110a247..eb1d141d6 100644 --- a/blogs/blog.go +++ b/blogs/blog.go @@ -11,6 +11,7 @@ import ( "strings" "time" "utils" + "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/gin-gonic/gin" @@ -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) } @@ -150,6 +152,18 @@ func truncateTo20Words(description string) string { } return strings.Join(words, " ") + "..." } +func extractFirstImgSrc(description string) string { + imgRegex := regexp.MustCompile(`]+\bsrc="([^"]+)"[^>]*>`) + + match := imgRegex.FindStringSubmatch(description) + + if len(match) > 1 { + return match[1] + } + + return "" +} + // make array or slice unique func Unique(arr []Item) []Item {