From 1a7a15f478fe52b15477f42c99e576e697c84288 Mon Sep 17 00:00:00 2001 From: skeris Date: Wed, 2 Apr 2025 01:44:59 +0300 Subject: [PATCH] hardfix imgvar --- clients/mailclient/utils.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/clients/mailclient/utils.go b/clients/mailclient/utils.go index ed80d90..2e60965 100644 --- a/clients/mailclient/utils.go +++ b/clients/mailclient/utils.go @@ -73,13 +73,27 @@ var tmplFuncs = template.FuncMap{ } func RenderImage(content string) template.HTML { - var res model.ImageContent - err := json.Unmarshal([]byte(content), &res) - if err != nil { - return SplitContent(content) + contents := strings.Split(content, "`,`") + var builder strings.Builder + + for i, cnt := range contents { + if i == 0 { + cnt = strings.TrimPrefix(cnt, "`") + } + if i == len(contents)-1 { + cnt = strings.TrimSuffix(cnt, "`") + } + + var res model.ImageContent + err := json.Unmarshal([]byte(cnt), &res) + if err != nil { + return SplitContent(content) + } else { + builder.WriteString(fmt.Sprintf("%s
", res.Description, res.Image)) + } } - tpl := template.HTML(fmt.Sprintf("%s
", res.Description, res.Image)) - return tpl + + return template.HTML(builder.String()) } func SplitContent(content string) template.HTML {