mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Transactional mail, crawler metadata, and asset measurement (#179)
* Send transactional email from no-reply@mail.innersquare.app Centralise the sender identity, reply-to address and SES configuration set in Chesstrainer.Mail so no notifier can drift. Add MAIL_REDIRECT_TO for smoke tests and a mix mail.check task that exercises the SES mailbox simulators, and document the setup in the deploy guide and .env.example. * Tighten crawler metadata and keep play pages out of search Canonical URLs no longer carry query strings, public pages get an OG image, WebSite JSON-LD and a per-page language, and the sitemap dates the landing page only. Play and guest-training routes are marked noindex so tens of thousands of near-identical pages stay out of the index. * Measure built asset sizes with mix assets.sizes Report raw, gzip and brotli sizes for built JS and CSS, and record the current numbers plus the board-code split recommendation in docs/assets.md.
This commit is contained in:
@@ -2,20 +2,15 @@ defmodule Chesstrainer.Accounts.UserNotifier do
|
||||
import Swoosh.Email
|
||||
|
||||
alias Chesstrainer.Branding
|
||||
alias Chesstrainer.Mailer
|
||||
alias Chesstrainer.Mail
|
||||
|
||||
# Delivers the email using the application mailer.
|
||||
defp deliver(recipient, subject, body) do
|
||||
email =
|
||||
new()
|
||||
|> to(recipient)
|
||||
|> from({Branding.name(), Branding.mail_from()})
|
||||
|> subject(subject)
|
||||
|> text_body(body)
|
||||
|
||||
with {:ok, _metadata} <- Mailer.deliver(email) do
|
||||
{:ok, email}
|
||||
end
|
||||
new()
|
||||
|> to(recipient)
|
||||
|> subject(subject)
|
||||
|> text_body(body)
|
||||
|> Mail.deliver()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
@@ -12,7 +12,7 @@ defmodule Chesstrainer.Branding do
|
||||
wordmark: "INNERSQUARE",
|
||||
tagline: "Endgame Trainer",
|
||||
support_email: "support@innersquare.app",
|
||||
mail_from: "no-reply@innersquare.app"
|
||||
mail_from: "no-reply@mail.innersquare.app"
|
||||
]
|
||||
|
||||
@doc "The display name, e.g. `\"Lucid Chess\"`."
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
defmodule Chesstrainer.Mail do
|
||||
@moduledoc """
|
||||
House rules for every outgoing email.
|
||||
|
||||
Notifiers build the message body and hand it here, so the sender identity,
|
||||
reply-to address, SES configuration set and the test redirect are applied in
|
||||
exactly one place and no sender can forget them.
|
||||
|
||||
The From address lives on the `mail.` subdomain so transactional mail is
|
||||
distinct from the addresses that receive mail on the apex domain. SES
|
||||
verification of the parent domain covers the subdomain, so no separate
|
||||
identity is required for the From header to be accepted.
|
||||
"""
|
||||
|
||||
alias Chesstrainer.Branding
|
||||
alias Chesstrainer.Mailer
|
||||
|
||||
@default_configuration_set "my-first-configuration-set"
|
||||
|
||||
@doc """
|
||||
Applies the house rules and delivers the email.
|
||||
|
||||
Returns `{:ok, email}` so notifiers can report the message they sent.
|
||||
"""
|
||||
def deliver(%Swoosh.Email{} = email) do
|
||||
email = prepare(email)
|
||||
|
||||
with {:ok, _metadata} <- Mailer.deliver(email) do
|
||||
{:ok, email}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Applies the house rules without delivering.
|
||||
|
||||
Exposed so tooling (such as `mix mail.check`) can inspect or send the exact
|
||||
message the application would send.
|
||||
"""
|
||||
def prepare(%Swoosh.Email{} = email) do
|
||||
email
|
||||
|> Swoosh.Email.from({Branding.name(), Branding.mail_from()})
|
||||
|> Swoosh.Email.reply_to(Branding.support_email())
|
||||
|> Swoosh.Email.put_provider_option(:configuration_set_name, configuration_set())
|
||||
|> redirect()
|
||||
end
|
||||
|
||||
defp configuration_set do
|
||||
Application.get_env(:chesstrainer, :ses_configuration_set, @default_configuration_set)
|
||||
end
|
||||
|
||||
# Rewrites every recipient to one address so a staging or production smoke
|
||||
# test can send through real SES without reaching users. The original
|
||||
# recipients stay in the subject and in an `X-Original-To` header so the
|
||||
# redirected message explains itself.
|
||||
defp redirect(email) do
|
||||
case Application.get_env(:chesstrainer, :mail_redirect_to) do
|
||||
address when is_binary(address) and address != "" ->
|
||||
originals = recipients(email)
|
||||
|
||||
require Logger
|
||||
|
||||
Logger.warning("mail redirect: #{Enum.join(originals, ", ")} -> #{address}")
|
||||
|
||||
%{email | to: [{"", address}], cc: [], bcc: []}
|
||||
|> Swoosh.Email.header("X-Original-To", Enum.join(originals, ", "))
|
||||
|> Swoosh.Email.subject("[→ #{Enum.join(originals, ", ")}] #{email.subject}")
|
||||
|
||||
_unset ->
|
||||
email
|
||||
end
|
||||
end
|
||||
|
||||
defp recipients(email) do
|
||||
[email.to, email.cc, email.bcc]
|
||||
|> List.flatten()
|
||||
|> Enum.reject(&is_nil/1)
|
||||
|> Enum.map(fn
|
||||
{_name, address} -> address
|
||||
address when is_binary(address) -> address
|
||||
end)
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ defmodule Chesstrainer.MailingList.Notifier do
|
||||
import Swoosh.Email
|
||||
|
||||
alias Chesstrainer.Branding
|
||||
alias Chesstrainer.Mailer
|
||||
alias Chesstrainer.Mail
|
||||
|
||||
@doc """
|
||||
Delivers the confirmation email for a mailing-list subscription.
|
||||
@@ -30,16 +30,10 @@ defmodule Chesstrainer.MailingList.Notifier do
|
||||
end
|
||||
|
||||
defp deliver(recipient, subject, body) do
|
||||
email =
|
||||
new()
|
||||
|> to(recipient)
|
||||
|> from({Branding.name(), Branding.mail_from()})
|
||||
|> reply_to(Branding.support_email())
|
||||
|> subject(subject)
|
||||
|> text_body(body)
|
||||
|
||||
with {:ok, _metadata} <- Mailer.deliver(email) do
|
||||
{:ok, email}
|
||||
end
|
||||
new()
|
||||
|> to(recipient)
|
||||
|> subject(subject)
|
||||
|> text_body(body)
|
||||
|> Mail.deliver()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user