From 224515ce4f1322a536f0add3b5cf3377c0550784 Mon Sep 17 00:00:00 2001 From: Gingka/Ginger Pepper <33764485+ExperiBass@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:08:07 -0500 Subject: [PATCH] remove spacers from caption before truncating for embed description --- handlers/embed.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/handlers/embed.go b/handlers/embed.go index ab487ca..2517e8c 100644 --- a/handlers/embed.go +++ b/handlers/embed.go @@ -5,6 +5,7 @@ import ( "instafix/utils" "instafix/views" "net/url" + "regexp" "strconv" "strings" @@ -103,6 +104,11 @@ func Embed() fiber.Handler { viewsData.Title = "@" + utils.B2S(item.Username) viewsData.Description = utils.B2S(item.Caption) + + // remove spacers and single tags from description before trunc + trimFiller, _ := regexp.Compile("^(?:\\.|-|#[[:word:]]+)\n") + viewsData.Description = trimFiller.ReplaceAllString(viewsData.Description, "") + if len(viewsData.Description) > 255 { viewsData.Description = viewsData.Description[:250] + "..." }