This commit is contained in:
Tomas Dvorak
2025-10-28 22:38:27 +01:00
parent 3d621e2187
commit 823fabee02
106 changed files with 9011 additions and 3930 deletions
+50 -35
View File
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"log"
"net/url"
"path/filepath"
"strings"
"time"
@@ -475,46 +474,62 @@ func (na *NewsletterAutomation) sendNewsletterToRecipients(recipients []string,
return nil
}
// HTML builders
func (na *NewsletterAutomation) buildBlogNotificationHTML(article *models.Article, articleURL string) string {
baseFE := strings.TrimSuffix(config.AppConfig.FrontendBaseURL, "/")
// Build tracked link
token, _ := utils.GenerateSubscriberToken("newsletter@system", 60*24*30)
trackedURL := fmt.Sprintf("%s/api/v1/email/click?u=%s&t=%s",
strings.TrimSuffix(config.AppConfig.PublicAPIBaseURL, "/"),
url.QueryEscape(articleURL),
url.QueryEscape(token))
html := fmt.Sprintf(`
// Short description: prefer excerpt; otherwise derive from content
desc := strings.TrimSpace(article.Excerpt)
if desc == "" {
plain := utils.SanitizeString(article.Content)
if len(plain) > 260 {
cut := 240
if cut < len(plain) {
for cut < len(plain) && plain[cut] != ' ' {
cut++
}
}
if cut > len(plain) { cut = len(plain) }
plain = strings.TrimSpace(plain[:cut]) + "…"
}
desc = plain
}
// Category badge (if available)
cat := strings.TrimSpace(article.CategoryName)
var catHTML string
if cat != "" {
catHTML = fmt.Sprintf(`<div style="margin-bottom:10px;"><span style="display:inline-block;background:#e3f2fd;color:#1e3a8a;border:1px solid #90cdf4;border-radius:999px;padding:4px 10px;font-size:12px;font-weight:600;">%s</span></div>`, htmlEsc(cat))
}
// Cover image (optional)
var imgHTML string
if strings.TrimSpace(article.ImageURL) != "" {
imgHTML = fmt.Sprintf(`<div style="margin:0 0 15px 0;"><img src="%s" alt="cover" style="width:100%%;height:auto;border-radius:6px;"/></div>`, htmlEsc(article.ImageURL))
}
html := fmt.Sprintf(`
<div style="max-width: 600px; margin: 0 auto; font-family: Arial, sans-serif;">
<h2 style="color: #1e3a8a; margin-bottom: 20px;">Nový článek na webu</h2>
<div style="border-left: 4px solid #2563eb; padding: 20px; background: #f8fafc; margin: 20px 0;">
<h3 style="margin: 0 0 15px 0; color: #1e3a8a;">%s</h3>
<p style="color: #4a5568; line-height: 1.6; margin: 0 0 15px 0;">%s</p>
<a href="%s" style="display: inline-block; padding: 12px 24px; background: #2563eb; color: white; text-decoration: none; border-radius: 6px; font-weight: 600;">Číst článek</a>
</div>
<p style="color: #718096; font-size: 14px; margin-top: 30px;">
<a href="%s/newsletter/preferences?token=%s" style="color: #2563eb;">Spravovat předvolby</a>
</p>
<h2 style="color: #1e3a8a; margin-bottom: 12px;">Nový článek na webu</h2>
<div style="border-left: 4px solid #2563eb; padding: 18px; background: #f8fafc; margin: 16px 0; border-radius:6px;">
%s
<h3 style="margin: 0 0 10px 0; color: #1e3a8a; font-size:22px;">%s</h3>
%s
<p style="color: #4a5568; line-height: 1.6; margin: 0 0 12px 0;">%s</p>
<a href="%s" style="display: inline-block; padding: 12px 20px; background: #2563eb; color: white; text-decoration: none; border-radius: 6px; font-weight: 600;">Číst článek</a>
</div>
</div>
`, htmlEsc(article.Title), htmlEsc(article.Excerpt), trackedURL, baseFE, url.QueryEscape(token))
return html
`, catHTML, htmlEsc(article.Title), imgHTML, htmlEsc(desc), articleURL)
return html
}
func (na *NewsletterAutomation) buildMatchReminderHTML(match Match, notifType string) string {
var intro string
if notifType == "reminder_48h" {
intro = "Připomínáme nadcházející zápas:"
} else {
intro = "Zápas je dnes!"
}
html := fmt.Sprintf(`
var intro string
if notifType == "reminder_48h" {
intro = "Připomínáme nadcházející zápas:"
} else {
intro = "Zápas je dnes!"
}
html := fmt.Sprintf(`
<div style="max-width: 600px; margin: 0 auto; font-family: Arial, sans-serif;">
<h2 style="color: #1e3a8a; margin-bottom: 20px;">%s</h2>