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:
2026-11-17 10:29:45 +01:00
committed by GitHub
parent b33c5e334a
commit 37e0ac8e56
24 changed files with 666 additions and 44 deletions
+2 -1
View File
@@ -368,7 +368,8 @@ defmodule ChesstrainerWeb.Layouts do
matomo_url: url,
matomo_site_id: site_id && to_string(site_id),
analytics_enabled:
is_binary(url) and url != "" and site_id not in [nil, ""] and is_nil(user)
is_binary(url) and byte_size(url) > 0 and is_binary(site_id) and byte_size(site_id) > 0 and
is_nil(user)
)
~H"""
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang={assigns[:lang] || "en"}>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -30,7 +30,24 @@
content={assigns[:meta_description]}
/>
<meta :if={assigns[:canonical_url]} property="og:url" content={assigns[:canonical_url]} />
<meta :if={assigns[:meta_description]} name="twitter:card" content="summary" />
<meta
:if={assigns[:meta_description]}
property="og:image"
content={assigns[:og_image_url] || SEO.og_image_url()}
/>
<meta :if={assigns[:meta_description]} property="og:image:width" content="1200" />
<meta :if={assigns[:meta_description]} property="og:image:height" content="630" />
<meta
:if={assigns[:meta_description]}
property="og:image:alt"
content={"#{Branding.name()} — #{Branding.tagline()}"}
/>
<meta :if={assigns[:meta_description]} name="twitter:card" content="summary_large_image" />
<meta
:if={assigns[:meta_description]}
name="twitter:image"
content={assigns[:og_image_url] || SEO.og_image_url()}
/>
<meta
:if={assigns[:meta_description]}
name="twitter:title"
@@ -73,6 +90,9 @@
>
</script>
<Layouts.theme_script />
<script :if={assigns[:json_ld]} type="application/ld+json">
<%= raw(assigns[:json_ld]) %>
</script>
</head>
<body>
<a
@@ -6,6 +6,7 @@ defmodule ChesstrainerWeb.PageController do
alias Chesstrainer.Branding
alias Chesstrainer.DailyPuzzles
alias Chesstrainer.Endgames
alias ChesstrainerWeb.SEO
@description "Short, focused endgame puzzles against tablebase-perfect defence. " <>
"Learn to see the winning move and make the endgame your strongest phase."
@@ -15,13 +16,15 @@ defmodule ChesstrainerWeb.PageController do
render_coming_soon(conn)
else
endgames = Endgames.curated_endgames()
canonical_url = SEO.canonical_url(conn)
conn
|> assign(:js_entry, ~p"/assets/js/marketing.js")
|> assign(:page_title, Branding.home_title())
|> assign(:title_suffix, "")
|> assign(:meta_description, @description)
|> assign(:canonical_url, current_url(conn))
|> assign(:canonical_url, canonical_url)
|> assign(:json_ld, SEO.json_ld(canonical_url))
|> assign(:mailing_list_enabled, mailing_list_enabled?())
|> render(:home,
endgames: endgames,
@@ -43,7 +46,7 @@ defmodule ChesstrainerWeb.PageController do
:meta_description,
"How #{Branding.name()} collects, uses, and protects your personal data."
)
|> assign(:canonical_url, current_url(conn))
|> assign(:canonical_url, SEO.canonical_url(conn))
|> render(:privacy)
end
@@ -53,7 +56,7 @@ defmodule ChesstrainerWeb.PageController do
|> assign(:page_title, Branding.title("Terms & Conditions"))
|> assign(:title_suffix, "")
|> assign(:meta_description, "The terms that apply when you use #{Branding.name()}.")
|> assign(:canonical_url, current_url(conn))
|> assign(:canonical_url, SEO.canonical_url(conn))
|> render(:terms_conditions)
end
@@ -66,7 +69,8 @@ defmodule ChesstrainerWeb.PageController do
:meta_description,
"Éditeur, hébergeur et informations légales de #{Branding.name()}."
)
|> assign(:canonical_url, current_url(conn))
|> assign(:canonical_url, SEO.canonical_url(conn))
|> assign(:lang, "fr")
|> render(:mentions_legales)
end
@@ -86,7 +90,7 @@ defmodule ChesstrainerWeb.PageController do
|> assign(:page_title, Branding.home_title())
|> assign(:title_suffix, "")
|> assign(:meta_description, @description)
|> assign(:canonical_url, current_url(conn))
|> assign(:canonical_url, SEO.canonical_url(conn))
|> assign(:noindex, true)
|> assign(:mailing_list_enabled, mailing_list_enabled?())
|> render(:coming_soon)
@@ -11,28 +11,37 @@ defmodule ChesstrainerWeb.SitemapController do
use ChesstrainerWeb, :controller
def index(conn, _params) do
urls = [
url(conn, ~p"/"),
url(conn, ~p"/privacy"),
url(conn, ~p"/terms-conditions"),
url(conn, ~p"/mentions-legales")
# The landing page changes every day (daily puzzle, counts), so its
# lastmod is honest. The legal pages have no stored modification time, and
# an invented lastmod is worse than none.
entries = [
{url(conn, ~p"/"), Date.utc_today()},
{url(conn, ~p"/privacy"), nil},
{url(conn, ~p"/terms-conditions"), nil},
{url(conn, ~p"/mentions-legales"), nil}
]
conn
|> put_resp_content_type("application/xml")
|> send_resp(200, render_sitemap(urls))
|> send_resp(200, render_sitemap(entries))
end
defp render_sitemap(urls) do
entries = Enum.map_join(urls, &" <url><loc>#{escape(&1)}</loc></url>\n")
defp render_sitemap(entries) do
urls =
Enum.map_join(entries, fn {loc, lastmod} ->
" <url><loc>#{escape(loc)}</loc>#{lastmod_entry(lastmod)}</url>\n"
end)
"""
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
#{entries}</urlset>
#{urls}</urlset>
"""
end
defp lastmod_entry(nil), do: ""
defp lastmod_entry(%Date{} = date), do: "<lastmod>#{Date.to_iso8601(date)}</lastmod>"
# Templates escape automatically; this response is built as a plain string,
# so XML-significant characters must be escaped here.
defp escape(value) do
+3 -1
View File
@@ -111,7 +111,9 @@ defmodule ChesstrainerWeb.Router do
end
scope "/", ChesstrainerWeb do
pipe_through [:browser]
# App surface: play pages, auth forms and guest training are reachable
# without a session but must never appear in search results.
pipe_through [:browser, :noindex]
live_session :current_user,
on_mount: [
+49
View File
@@ -0,0 +1,49 @@
defmodule ChesstrainerWeb.SEO do
@moduledoc """
Absolute URLs and crawler metadata for controller-rendered pages.
Search engines need absolute URLs, so these helpers read the endpoint's
configured host rather than the request host (which is a proxy address).
Canonical URLs deliberately drop the query string: campaign parameters such
as `?utm_source=...` must not become canonical pages of their own.
"""
alias Chesstrainer.Branding
alias ChesstrainerWeb.Endpoint
@og_image "/images/og.png"
@logo "/apple-touch-icon.png"
@doc "The request path as an absolute canonical URL, without any query string."
def canonical_url(conn) do
Phoenix.VerifiedRoutes.unverified_url(conn, conn.request_path)
end
@doc "Absolute URL of the social share image."
def og_image_url, do: Endpoint.url() <> @og_image
@doc """
JSON-LD for the site, encoded as a string ready for a
`<script type="application/ld+json">` block.
"""
def json_ld(url) do
%{
"@context" => "https://schema.org",
"@graph" => [
%{
"@type" => "WebSite",
"name" => Branding.name(),
"url" => url
},
%{
"@type" => "Organization",
"name" => Branding.name(),
"url" => url,
"logo" => Endpoint.url() <> @logo
}
]
}
|> Jason.encode!()
end
end