feat(email): every email Minstrel sends uses one layout (#8150)

The password reset, the new-music and activity summaries and the SMTP
test message each drew their own page; the test message had no layout
at all. They now share internal/mailer's layout: the Minstrel name at
the top, the email's heading and message on a card in the design
system's dark theme, and a footer saying which server sent it and why,
signed "— Minstrel", with the notification-settings link on the
summaries. A plain-text body in the same frame goes alongside.

An email supplies only its content templates and a Frame (heading,
server, reason). Links, buttons and quiet text take named styles from
the layout ({{style "link"}}), so colours change in one place; an
unknown style name fails the render. The SMTP test message is a
template now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 10:27:16 -05:00
co-authored by Claude Opus 5.5
parent a18d5aaa11
commit bae3421057
14 changed files with 331 additions and 113 deletions
+17 -21
View File
@@ -1,23 +1,17 @@
package notifications
import (
"bytes"
"embed"
"encoding/json"
"fmt"
htmltemplate "html/template"
"strings"
texttemplate "text/template"
"git.fabledsword.com/bvandeusen/minstrel/internal/mailer"
)
//go:embed templates/digest.txt templates/digest.html
var digestFS embed.FS
var (
digestText = texttemplate.Must(texttemplate.ParseFS(digestFS, "templates/digest.txt"))
digestHTML = htmltemplate.Must(htmltemplate.ParseFS(digestFS, "templates/digest.html"))
)
// digestEmail is one rendered email.
type digestEmail struct {
Subject string
@@ -38,22 +32,24 @@ type digestArtist struct {
}
type digestVars struct {
Name string
Intro string
Items []digestLine
Artists []digestArtist
SettingsURL string
Name string
Intro string
Items []digestLine
Artists []digestArtist
}
// renderDigest renders one group's email. base is the public address; with
// none set, the email still goes out, without links.
func renderDigest(group EmailGroup, name string, items []pendingItem, base string) (digestEmail, error) {
vars := digestVars{Name: name, SettingsURL: joinURL(base, "/settings/notifications")}
vars := digestVars{Name: name}
frame := mailer.Frame{Server: base, NotificationSettings: true}
var subject string
if group == EmailSummary {
vars.Artists = summaryArtists(items, base)
vars.Intro = "New in your library since the last summary:"
subject = "Minstrel: new music in your library"
frame.Heading = "New music in your library"
frame.Reason = "you chose to get new-music summaries by email"
} else {
for _, it := range items {
r := Render(it.Kind, it.Payload)
@@ -61,19 +57,19 @@ func renderDigest(group EmailGroup, name string, items []pendingItem, base strin
}
vars.Intro = "Here's what happened on Minstrel:"
subject = fmt.Sprintf("Minstrel: %d updates", len(items))
frame.Heading = fmt.Sprintf("%d updates", len(items))
if len(items) == 1 {
subject = "Minstrel: " + vars.Items[0].Title
frame.Heading = vars.Items[0].Title
}
frame.Reason = "you chose to get these notifications by email"
}
var text, html bytes.Buffer
if err := digestText.Execute(&text, vars); err != nil {
return digestEmail{}, fmt.Errorf("render text: %w", err)
text, html, err := mailer.Render(digestFS, "templates/digest.txt", "templates/digest.html", vars, frame)
if err != nil {
return digestEmail{}, fmt.Errorf("render digest: %w", err)
}
if err := digestHTML.Execute(&html, vars); err != nil {
return digestEmail{}, fmt.Errorf("render html: %w", err)
}
return digestEmail{Subject: subject, Text: text.String(), HTML: html.String()}, nil
return digestEmail{Subject: subject, Text: text, HTML: html}, nil
}
// summaryArtists groups new-music arrivals by artist, in the order each
+12 -22
View File
@@ -1,25 +1,15 @@
<!doctype html>
<html>
<body style="font-family: -apple-system, system-ui, sans-serif; max-width: 560px; margin: 0 auto; padding: 24px; color: #2c2c2c;">
<p>Hello <strong>{{.Name}}</strong>,</p>
<p>{{.Intro}}</p>
<p style="{{style "p"}}">Hello <strong>{{.Name}}</strong>,</p>
<p style="margin:0;">{{.Intro}}</p>
{{range .Artists}}
<p style="margin: 20px 0 4px; font-weight: 600;">{{if .URL}}<a href="{{.URL}}" style="color: #2c2c2c;">{{.Name}}</a>{{else}}{{.Name}}{{end}}</p>
{{if .Titles}}<ul style="margin: 0; padding-left: 20px;">
{{range .Titles}}<li style="margin: 2px 0;">{{if .URL}}<a href="{{.URL}}" style="color: #4a6b5c;">{{.Title}}</a>{{else}}{{.Title}}{{end}}</li>
{{end}}</ul>{{end}}
<p style="{{style "group"}}">{{if .URL}}<a href="{{.URL}}" style="{{style "link"}}">{{.Name}}</a>{{else}}{{.Name}}{{end}}</p>
{{if .Titles}}<ul style="{{style "list"}}">
{{range .Titles}}<li style="{{style "item"}}">{{if .URL}}<a href="{{.URL}}" style="{{style "link"}}">{{.Title}}</a>{{else}}{{.Title}}{{end}}</li>
{{end}}</ul>{{end}}
{{end}}{{if .Items}}
<ul style="margin: 16px 0; padding-left: 20px;">
{{range .Items}}<li style="margin: 8px 0;">
{{if .URL}}<a href="{{.URL}}" style="color: #2c2c2c; font-weight: 600;">{{.Title}}</a>{{else}}<strong>{{.Title}}</strong>{{end}}
{{if .Body}}<br><span style="color: #555;">{{.Body}}</span>{{end}}
</li>
{{end}}</ul>
<ul style="margin:16px 0 0; padding-left:20px;">
{{range .Items}}<li style="margin:8px 0;">
{{if .URL}}<a href="{{.URL}}" style="{{style "link"}} font-weight:600;">{{.Title}}</a>{{else}}<strong>{{.Title}}</strong>{{end}}
{{if .Body}}<br><span style="{{style "quiet"}}">{{.Body}}</span>{{end}}
</li>
{{end}}</ul>
{{end}}
<p style="font-size: 12px; color: #999; margin-top: 32px; border-top: 1px solid #eee; padding-top: 16px;">
{{if .SettingsURL}}<a href="{{.SettingsURL}}" style="color: #999;">Choose which notifications are emailed to you</a>{{else}}Choose which notifications are emailed to you in Minstrel, under Settings → Notifications.{{end}}<br>
— Minstrel
</p>
</body>
</html>
@@ -11,6 +11,3 @@ Hello {{.Name}},
{{.Body}}{{end}}{{if .URL}}
{{.URL}}{{end}}
{{end}}
{{if .SettingsURL}}Choose which notifications are emailed to you: {{.SettingsURL}}{{else}}Choose which notifications are emailed to you in Minstrel, under Settings → Notifications.{{end}}
— Minstrel