From b6a0203e936b8af50d54a325e476e82d796a270a Mon Sep 17 00:00:00 2001 From: rramiachraf <51409801+rramiachraf@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:34:46 +0100 Subject: [PATCH] fix annotation image not appearing for the second time --- handlers/annotations.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/handlers/annotations.go b/handlers/annotations.go index ccec630..70dff1d 100644 --- a/handlers/annotations.go +++ b/handlers/annotations.go @@ -7,7 +7,6 @@ import ( "fmt" "net/http" "regexp" - "strings" "github.com/gorilla/mux" "github.com/rramiachraf/dumb/data" @@ -83,11 +82,13 @@ func Annotations(l *logrus.Logger) http.HandlerFunc { } func cleanBody(body string) string { - var withCleanedImageLinks = strings.ReplaceAll(body, "https://images.rapgenius.com/", "/images/") - withCleanedImageLinks = strings.ReplaceAll(body, "https://images.genius.com/", "/images/") + re := regexp.MustCompile(`(?i)https:\/\/images\.(rapgenius|genius)\.com\/`) + clean := re.ReplaceAllString(body, "/images/") - var re = regexp.MustCompile(`https?:\/\/[a-z]*.?genius.com`) - var withCleanedLinks = re.ReplaceAllString(withCleanedImageLinks, "") + re = regexp.MustCompile(`https?:\/\/[a-z]*.?genius.com`) + clean = re.ReplaceAllString(clean, "") - return withCleanedLinks + fmt.Println(clean) + + return clean }