fix annotation image not appearing for the second time

This commit is contained in:
rramiachraf 2024-03-04 23:34:46 +01:00
parent 028d32375d
commit b6a0203e93

View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"regexp" "regexp"
"strings"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/rramiachraf/dumb/data" "github.com/rramiachraf/dumb/data"
@ -83,11 +82,13 @@ func Annotations(l *logrus.Logger) http.HandlerFunc {
} }
func cleanBody(body string) string { func cleanBody(body string) string {
var withCleanedImageLinks = strings.ReplaceAll(body, "https://images.rapgenius.com/", "/images/") re := regexp.MustCompile(`(?i)https:\/\/images\.(rapgenius|genius)\.com\/`)
withCleanedImageLinks = strings.ReplaceAll(body, "https://images.genius.com/", "/images/") clean := re.ReplaceAllString(body, "/images/")
var re = regexp.MustCompile(`https?:\/\/[a-z]*.?genius.com`) re = regexp.MustCompile(`https?:\/\/[a-z]*.?genius.com`)
var withCleanedLinks = re.ReplaceAllString(withCleanedImageLinks, "") clean = re.ReplaceAllString(clean, "")
return withCleanedLinks fmt.Println(clean)
return clean
} }