feat(postcard): finished default layout with logo header, footer and site name

- default.htm ports WinterCMS's default layout: wrapper, header row with
  the Branding logo (or the site name), the inner-body card and a
  copyright footer; its text wrapper ends with the footer
- built-in header and footer partials (logo/body/url, body)
- layouts get siteName (Branding site name, else the display name of
  mail.from) and year; Brand.SiteName and migration
  202611130002_mail_brand_site_name
- cabana Branding form gets site_name (trimmed, max 255), mapped into the
  Branding preview draft; en/pl copy; img.logo brand CSS
- 35-06 Task 1 (G-35-8)
This commit is contained in:
Jakub Zych
2026-11-13 20:52:52 +01:00
parent fdc2094ffc
commit 093529d45c
24 changed files with 266 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
netmail "net/mail"
"strings"
"sync"
"time"
@@ -145,9 +146,10 @@ func (m *mailer) render(ctx context.Context, msg Message) (RenderedMessage, erro
// options returns the render options of the file version: mail.css, and
// either the saved Branding (its compiled CSS and its logo) or, while none
// has been saved, mail.brandCss. A Branding whose colours do not compile
// keeps mail.brandCss.
// keeps mail.brandCss. The site name is the Branding's, else the display
// name of mail.from.
func (m *mailer) options(brand *Brand) renderOptions {
opts := renderOptions{css: m.opts.CSS, brandCSS: m.opts.BrandCSS}
opts := renderOptions{css: m.opts.CSS, brandCSS: m.opts.BrandCSS, siteName: siteName(brand, m.opts.From), year: time.Now().Year()}
if brand == nil {
return opts
}
@@ -162,6 +164,22 @@ func (m *mailer) options(brand *Brand) renderOptions {
return opts
}
// siteName returns the name the built-in layouts show: the Branding's site
// name, trimmed, else the display name of the sender address from, else
// empty.
func siteName(brand *Brand, from string) string {
if brand != nil {
if name := strings.TrimSpace(brand.SiteName); name != "" {
return name
}
}
addr, err := netmail.ParseAddress(from)
if err != nil {
return ""
}
return strings.TrimSpace(addr.Name)
}
// overrides asks the source once. A failed lookup (no connection, tables not
// migrated yet) is a warning, not a send failure: the file version is sent.
func (m *mailer) overrides(ctx context.Context, template string) Overrides {