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

@@ -14,6 +14,7 @@ import (
"strings"
"sync"
texttemplate "text/template"
"time"
"github.com/yuin/goldmark"
)
@@ -38,7 +39,7 @@ var builtinLayoutAliases = map[string]string{
}
// builtinPartials are the partials postcard ships, callable by bare name.
var builtinPartials = []string{"button", "panel", "subcopy", "table"}
var builtinPartials = []string{"button", "panel", "subcopy", "table", "header", "footer"}
var (
dangerousScheme = regexp.MustCompile(`(?i)(?:javascript|vbscript|data):`)
@@ -100,8 +101,8 @@ type parsedPartial struct {
}
// NewCatalog returns a catalog that already contains postcard's built-in
// layouts (default, system and minimal) and partials (button, panel, table
// and subcopy). It holds no template.
// layouts (default, system and minimal) and partials (button, panel, table,
// subcopy, header and footer). It holds no template.
func NewCatalog() *Catalog {
c := &Catalog{
templates: make(map[string]*parsedTemplate),
@@ -500,6 +501,11 @@ type renderOptions struct {
brandCSS string
// logoURL is the Branding logo's absolute URL, or empty.
logoURL string
// siteName is the name the built-in layouts show in their header and
// footer: the Branding's site name, else the display name of mail.from.
siteName string
// year is the year of the copyright line; zero is the current year.
year int
// overrides are the database overrides to apply; the zero value renders
// the file version.
overrides Overrides
@@ -645,12 +651,18 @@ func (c *Catalog) renderParts(msg Message, src renderSource, opts renderOptions)
css += "\n" + opts.css
}
}
year := opts.year
if year == 0 {
year = time.Now().Year()
}
text, err := execTextFuncs(layout.name+".text", layout.textWrap, map[string]any{
"Content": textBody,
"Subject": subject,
"css": css,
"brandCss": opts.brandCSS,
"logoUrl": opts.logoURL,
"siteName": opts.siteName,
"year": year,
}, texttemplate.FuncMap{"partial": partials.textCall})
if err != nil {
return out, partLayoutText, err
@@ -661,6 +673,8 @@ func (c *Catalog) renderParts(msg Message, src renderSource, opts renderOptions)
"css": template.CSS(css),
"brandCss": template.CSS(opts.brandCSS),
"logoUrl": opts.logoURL,
"siteName": opts.siteName,
"year": year,
}, template.FuncMap{"partial": partials.htmlCall})
if err != nil {
return out, partLayoutHTML, err