landing page (#63)

* remove daisyui and rebuild styles

* very basic setup of new design - missing components etc

* basic navbar with reusable landing components

* basic puzzle of the day

* update todos

* update todos

* add curated landing puzzle cards with selectable board (#55)

* update with footer

* add button to solve today's puzzle

* Make landing page a dead view

Render the home page from PageController with a static board preview, link puzzle cards and CTAs to public-code play routes, count puzzles from the DB, and add a global footer.

* Serve a marketing-only JS bundle on the landing page

Build a small marketing entry point with phoenix_html and the plain-DOM navbar, select it on controller-rendered pages, and keep the full LiveView bundle for LiveView pages.

* Add landing page SEO metadata

Replace the Phoenix default title with a descriptive Lucid Chess title, and add description, canonical, Open Graph, and Twitter card tags to the landing page.

* Complete the hero copy block

Add the spark icon primitive and the Endgames, made clear eyebrow. The primary CTA keeps linking to the active puzzle rather than scrolling to the board.

* Add a persisted global daily puzzle

Assign one endgame per UTC day in a daily_puzzles table with a unique date, preferring endgames unused in the last 30 days and falling back to any. Concurrent first requests insert with on-conflict-ignore and read the winning row. The landing board now shows the daily puzzle.

* remove unused CSS, nav links, time pill

* allow devices to connect to dev server by changing IP address to 0.0.0.0

* Restore the colour-mode switch and add a dark palette

* Use brand colour tokens on the play page

* self host fonts  - closes issue #62

* begin splitting CSS into modules

* remove hover on hero chessboard, split more css modules

* remove interactivity from hero chessboard

* update todo
This commit is contained in:
2026-11-05 13:52:14 +01:00
committed by GitHub
parent fd6277ef92
commit 93806b9ab2
60 changed files with 2253 additions and 11028 deletions
+108
View File
@@ -0,0 +1,108 @@
defmodule Chesstrainer.DailyPuzzlesTest do
use Chesstrainer.DataCase
alias Chesstrainer.DailyPuzzles
alias Chesstrainer.DailyPuzzles.DailyPuzzle
alias Chesstrainer.Endgames
alias Chesstrainer.Endgames.Endgame
alias Chesstrainer.Repo
alias Ecto.Adapters.SQL.Sandbox
@kr "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
@kr_other "8/8/4k3/8/8/3K1R2/8/8 w - - 0 1"
@kq "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1"
defp create_endgame!(fen) do
{:ok, endgame} =
Endgames.create_endgame(%{fen: fen, color: :white, result: :win, rating: 1500})
endgame
end
test "returns nil and persists nothing when there are no endgames" do
date = ~D[2026-01-01]
assert DailyPuzzles.for_date(date) == nil
assert Repo.get_by(DailyPuzzle, date: date) == nil
end
test "persists one stable endgame for the day" do
endgame = create_endgame!(@kr)
date = ~D[2026-01-01]
assert DailyPuzzles.for_date(date).id == endgame.id
assert DailyPuzzles.for_date(date).id == endgame.id
assert %DailyPuzzle{endgame_id: endgame_id} = Repo.get_by(DailyPuzzle, date: date)
assert endgame_id == endgame.id
assert Repo.aggregate(DailyPuzzle, :count) == 1
end
test "rotates through endgames across consecutive days" do
create_endgame!(@kr)
create_endgame!(@kr_other)
create_endgame!(@kq)
day = ~D[2026-01-01]
ids = for offset <- 0..2, do: DailyPuzzles.for_date(Date.add(day, offset)).id
assert length(Enum.uniq(ids)) == 3
end
test "falls back to an endgame when the eligible pool is exhausted" do
endgame = create_endgame!(@kr)
day = ~D[2026-01-01]
assert DailyPuzzles.for_date(day).id == endgame.id
assert DailyPuzzles.for_date(Date.add(day, 1)).id == endgame.id
end
test "concurrent first requests create a single assignment" do
date = ~D[2026-01-01]
fens = [@kr, @kr_other, @kq]
cleanup = fn ->
Sandbox.unboxed_run(Repo, fn ->
Repo.delete_all(from daily_puzzle in DailyPuzzle, where: daily_puzzle.date == ^date)
Repo.delete_all(from endgame in Endgame, where: endgame.fen in ^fens)
end)
end
# This test commits outside the sandbox so the worker tasks use real,
# separate connections and actually race on the unique date constraint.
cleanup.()
on_exit(cleanup)
endgame_ids =
Sandbox.unboxed_run(Repo, fn ->
for fen <- fens, do: create_endgame!(fen).id
end)
tasks =
for _ <- 1..8 do
Task.async(fn ->
receive do
:go -> :ok
end
Sandbox.unboxed_run(Repo, fn -> DailyPuzzles.for_date(date).id end)
end)
end
Enum.each(tasks, &send(&1.pid, :go))
assigned_ids = Task.await_many(tasks, 10_000)
assert [assigned_id] = Enum.uniq(assigned_ids)
assert assigned_id in endgame_ids
count =
Sandbox.unboxed_run(Repo, fn ->
Repo.aggregate(
from(daily_puzzle in DailyPuzzle, where: daily_puzzle.date == ^date),
:count
)
end)
assert count == 1
end
end
+78
View File
@@ -5,6 +5,12 @@ defmodule Chesstrainer.EndgamesTest do
alias Chesstrainer.Endgames.Endgame
alias Chesstrainer.Themes
setup do
previous = Application.get_env(:chesstrainer, :curated_endgame_codes)
on_exit(fn -> Application.put_env(:chesstrainer, :curated_endgame_codes, previous) end)
:ok
end
@kr "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
@kr_other "8/8/4k3/8/8/3K1R2/8/8 w - - 0 1"
@kq "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1"
@@ -302,4 +308,76 @@ defmodule Chesstrainer.EndgamesTest do
assert Endgames.list_key_groups(%{key: "KQ v K"}) == [{"KQ v K", 1}]
end
end
describe "count_endgames/0" do
test "returns 0 when there are no endgames" do
assert Endgames.count_endgames() == 0
end
test "counts every stored endgame" do
create_endgame!(@kr)
create_endgame!(@kq)
assert Endgames.count_endgames() == 2
end
end
describe "random_endgame/0" do
test "returns nil when there are no endgames" do
assert Endgames.random_endgame() == nil
end
test "returns one of the existing endgames" do
kr = create_endgame!(@kr)
kq = create_endgame!(@kq)
assert Endgames.random_endgame().id in [kr.id, kq.id]
end
end
describe "curated_endgames/1" do
test "returns the configured endgames in order with themes preloaded" do
{:ok, theme} = Themes.create_theme(%{name: "Opposition", category: :endgame})
first = create_endgame!(@kr, [theme])
second = create_endgame!(@kq)
Application.put_env(:chesstrainer, :curated_endgame_codes, [
first.public_code,
second.public_code
])
assert [one, two] = Endgames.curated_endgames(2)
assert one.id == first.id
assert two.id == second.id
assert Enum.map(one.themes, & &1.name) == ["Opposition"]
end
test "fills missing or unresolved codes from the database" do
first = create_endgame!(@kr)
second = create_endgame!(@kq)
Application.put_env(:chesstrainer, :curated_endgame_codes, [first.public_code, "missing"])
endgames = Endgames.curated_endgames(2)
assert length(endgames) == 2
assert hd(endgames).id == first.id
assert Enum.any?(endgames, &(&1.id == second.id))
end
test "returns a date-seeded selection when nothing is configured" do
first = create_endgame!(@kr)
second = create_endgame!(@kq)
Application.put_env(:chesstrainer, :curated_endgame_codes, [])
ids = Endgames.curated_endgames(3) |> Enum.map(& &1.id)
assert Enum.sort(ids) == Enum.sort([first.id, second.id])
end
test "returns an empty list when there are no endgames" do
Application.put_env(:chesstrainer, :curated_endgame_codes, [])
assert Endgames.curated_endgames() == []
end
end
end
+31
View File
@@ -114,4 +114,35 @@ defmodule Chesstrainer.FENTest do
assert FEN.piece_count(nil) == nil
end
end
describe "board/1" do
test "returns eight ranks of eight squares" do
board = FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
assert length(board) == 8
assert Enum.all?(board, &(length(&1) == 8))
end
test "expands empty-square digits into nil squares" do
assert FEN.board("8/8/8/8/8/8/8/8") ==
List.duplicate(List.duplicate(nil, 8), 8)
end
test "maps each piece letter to its square" do
board = FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1")
assert Enum.at(board, 2) == [nil, nil, nil, "k", nil, nil, nil, nil]
assert Enum.at(board, 5) == [nil, nil, nil, "K", nil, "R", nil, nil]
end
test "reads only the board field" do
assert FEN.board("8/8/3k4/8/8/3K1R2/8/8 w - - 37 99") ==
FEN.board("8/8/3k4/8/8/3K1R2/8/8")
end
test "returns nil for a malformed board" do
assert FEN.board("not a fen") == nil
assert FEN.board(nil) == nil
end
end
end
@@ -0,0 +1,76 @@
defmodule ChesstrainerWeb.LandingComponentsTest do
use ChesstrainerWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Chesstrainer.Endgames.Endgame
alias Chesstrainer.Themes.Theme
alias ChesstrainerWeb.LandingComponents
@endgame %Endgame{
fen: "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1",
color: :white,
key: "KR v K"
}
test "renders the endgame's pieces, side to move, and caption" do
html = render_component(&LandingComponents.board_preview/1, %{endgame: @endgame})
assert html =~ "KR v K"
assert html =~ "To move"
assert html =~ "White"
assert html =~ "♔"
assert html =~ "♖"
assert html =~ "♚"
assert html =~ "Today’s position"
end
test "falls back to a neutral position without an endgame" do
html = render_component(&LandingComponents.board_preview/1, %{endgame: nil})
assert html =~ "Featured position"
assert html =~ "White"
assert html =~ "♖"
end
test "renders themes under the position title" do
endgame = %{
fen: @endgame.fen,
color: :white,
key: "KR v K",
themes: [%Theme{name: "Lucena"}]
}
html = render_component(&LandingComponents.board_preview/1, %{endgame: endgame})
assert html =~ "Lucena"
end
test "renders the spark icon as a decorative primitive" do
html = render_component(&LandingComponents.icon_spark/1, %{})
assert html =~ "<svg"
assert html =~ ~s(aria-hidden="true")
assert html =~ "currentColor"
end
describe "puzzle_count_label/1" do
test "shows counts below 100 exactly" do
assert LandingComponents.puzzle_count_label(0) == "0"
assert LandingComponents.puzzle_count_label(47) == "47"
assert LandingComponents.puzzle_count_label(99) == "99"
end
test "floors counts of 100 or more to hundreds" do
assert LandingComponents.puzzle_count_label(100) == "100+"
assert LandingComponents.puzzle_count_label(199) == "100+"
assert LandingComponents.puzzle_count_label(999) == "900+"
end
test "floors counts of 1000 or more to thousands" do
assert LandingComponents.puzzle_count_label(1000) == "1000+"
assert LandingComponents.puzzle_count_label(1999) == "1000+"
assert LandingComponents.puzzle_count_label(2400) == "2000+"
end
end
end
@@ -0,0 +1,35 @@
defmodule ChesstrainerWeb.LayoutsTest do
use ChesstrainerWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias ChesstrainerWeb.Layouts
describe "colour_mode_toggle/1" do
test "renders all three modes as a labelled radiogroup" do
html = render_component(&Layouts.colour_mode_toggle/1, %{})
assert html =~ ~s(role="radiogroup")
assert html =~ ~s(aria-label="Colour mode")
for {mode, label} <- [
{"system", "System colour mode"},
{"light", "Light colour mode"},
{"dark", "Dark colour mode"}
] do
assert html =~ ~s(data-phx-theme="#{mode}")
assert html =~ ~s(aria-label="#{label}")
assert html =~ ~s(role="radio")
end
assert html =~ ~s(aria-checked="true")
end
test "is rendered by the navbar" do
html = render_component(&Layouts.navbar/1, %{current_scope: nil})
assert html =~ ~s(aria-label="Colour mode")
assert html =~ ~s(class="nav-right")
end
end
end
@@ -1,8 +1,186 @@
defmodule ChesstrainerWeb.PageControllerTest do
use ChesstrainerWeb.ConnCase
test "GET /", %{conn: conn} do
conn = get(conn, ~p"/")
assert html_response(conn, 200) =~ "Peace of mind from prototype to production"
import Chesstrainer.AccountsFixtures
alias Chesstrainer.DailyPuzzles
alias Chesstrainer.Endgames
alias Chesstrainer.Themes
@fen_kr "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
@fen_kr_other "8/8/4k3/8/8/3K1R2/8/8 w - - 0 1"
@fen_kq "8/8/3k4/8/8/3K1Q2/8/8 w - - 0 1"
setup do
previous = Application.get_env(:chesstrainer, :curated_endgame_codes)
on_exit(fn -> Application.put_env(:chesstrainer, :curated_endgame_codes, previous) end)
:ok
end
defp create_endgame(fen, rating, theme_name) do
{:ok, theme} = Themes.create_theme(%{name: theme_name, category: :endgame})
{:ok, endgame} =
Endgames.create_endgame(%{fen: fen, color: :white, result: :win, rating: rating}, [theme])
endgame
end
defp curated! do
beginner = create_endgame(@fen_kr, 1500, "Opposition")
intermediate = create_endgame(@fen_kr_other, 1800, "Lucena")
advanced = create_endgame(@fen_kq, 2100, "Philidor")
Application.put_env(:chesstrainer, :curated_endgame_codes, [
beginner.public_code,
intermediate.public_code,
advanced.public_code
])
{beginner, intermediate, advanced}
end
@description "Short, focused endgame puzzles against tablebase-perfect defence. " <>
"Learn to see the winning move and make the endgame your strongest phase."
test "GET / renders the landing page, navbar, and footer", %{conn: conn} do
html = conn |> get(~p"/") |> html_response(200)
document = LazyHTML.from_document(html)
assert html =~ "Learn to see the"
assert html =~ "LUCID"
assert html =~ "Method"
assert html =~ "Puzzles"
assert html =~ "Start training"
assert html =~ ~s(id="nav-links")
assert html =~ "menu-button"
assert html =~ ~s(class="site-footer")
assert html =~ "© #{DateTime.utc_now().year} Lucid Chess"
assert html =~ ~p"/endgames"
assert html =~ "/assets/js/marketing.js"
refute html =~ "/assets/js/app.js"
assert LazyHTML.text(LazyHTML.query(document, "title")) =~ "Lucid Chess — Endgame Trainer"
refute html =~ "Phoenix Framework"
eyebrow = LazyHTML.query(document, ".eyebrow")
assert LazyHTML.text(eyebrow) =~ "Endgames, made clear"
assert LazyHTML.attribute(LazyHTML.query(eyebrow, "svg"), "aria-hidden") == ["true"]
assert LazyHTML.attribute(LazyHTML.query(document, ~s(meta[name="description"])), "content") ==
[@description]
assert [canonical] =
LazyHTML.attribute(LazyHTML.query(document, ~s(link[rel="canonical"])), "href")
assert URI.parse(canonical).path == "/"
for {selector, content} <- [
{~s(meta[property="og:type"]), "website"},
{~s(meta[property="og:site_name"]), "Lucid Chess"},
{~s(meta[property="og:title"]), "Lucid Chess — Endgame Trainer"},
{~s(meta[property="og:description"]), @description},
{~s(meta[property="og:url"]), canonical},
{~s(meta[name="twitter:card"]), "summary"},
{~s(meta[name="twitter:title"]), "Lucid Chess — Endgame Trainer"},
{~s(meta[name="twitter:description"]), @description}
] do
assert LazyHTML.attribute(LazyHTML.query(document, selector), "content") == [content]
end
end
test "guest navbar links to log in and register", %{conn: conn} do
html = conn |> get(~p"/") |> html_response(200)
assert html =~ ~p"/users/log-in"
assert html =~ ~p"/users/register"
refute html =~ ~p"/users/settings"
end
test "signed-in navbar links to settings and log out", %{conn: conn} do
html =
conn
|> log_in_user(user_fixture())
|> get(~p"/")
|> html_response(200)
assert html =~ ~p"/users/settings"
assert html =~ ~p"/users/log-out"
refute html =~ ~p"/users/register"
end
test "renders curated cards and the daily board", %{conn: conn} do
{beginner, intermediate, advanced} = curated!()
daily = DailyPuzzles.today()
html = conn |> get(~p"/") |> html_response(200)
document = LazyHTML.from_document(html)
assert LazyHTML.attribute(LazyHTML.query(document, ".puzzle-card"), "href") == [
"/endgames/#{beginner.public_code}/play",
"/endgames/#{intermediate.public_code}/play",
"/endgames/#{advanced.public_code}/play"
]
board = LazyHTML.text(LazyHTML.query(document, ".board-caption"))
assert board =~ daily.key
for theme <- daily.themes do
assert board =~ theme.name
end
assert LazyHTML.text(LazyHTML.query(document, ".board-topline")) =~ "White"
assert html =~ "Try today's puzzle"
assert html =~ "Begin with the basics"
assert html =~ "<span>puzzles</span>"
end
test "hero and progress CTAs link to the daily puzzle", %{conn: conn} do
curated!()
daily = DailyPuzzles.today()
html = conn |> get(~p"/") |> html_response(200)
document = LazyHTML.from_document(html)
play_path = "/endgames/#{daily.public_code}/play"
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [play_path]
assert LazyHTML.attribute(LazyHTML.query(document, ".progress-banner a"), "href") == [
play_path
]
refute html =~ "/endgames//play"
end
test "shows the same daily puzzle across requests", %{conn: conn} do
curated!()
daily = DailyPuzzles.today()
first = conn |> get(~p"/") |> html_response(200)
second = conn |> get(~p"/") |> html_response(200)
for html <- [first, second] do
board = LazyHTML.text(LazyHTML.query(LazyHTML.from_document(html), ".board-caption"))
assert board =~ daily.key
end
end
test "renders without endgames", %{conn: conn} do
Application.put_env(:chesstrainer, :curated_endgame_codes, [])
html = conn |> get(~p"/") |> html_response(200)
document = LazyHTML.from_document(html)
assert html =~ "Featured position"
assert html =~ "<span>puzzles</span>"
refute html =~ "puzzle-card"
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [
"/endgames"
]
assert LazyHTML.attribute(LazyHTML.query(document, ".progress-banner a"), "href") == [
"/endgames"
]
end
end
@@ -17,7 +17,7 @@ defmodule ChesstrainerWeb.EndgameLive.IndexTest do
assert html =~ "max-w-7xl"
assert has_element?(view, "#key-group-K-v-K")
assert has_element?(view, "#key-group-K-v-K .badge", "2")
assert has_element?(view, "#key-group-count-K-v-K", "2")
end
test "trims the table to the key columns", %{conn: conn} do
@@ -17,6 +17,8 @@ defmodule ChesstrainerWeb.EndgameLive.PlayerIndexTest do
assert html =~ "Endgames"
assert html =~ "max-w-7xl"
assert html =~ "/assets/js/app.js"
refute html =~ "/assets/js/marketing.js"
assert has_element?(view, "#key-group-K-v-K")
refute html =~ "Lucena"
@@ -11,8 +11,8 @@ defmodule ChesstrainerWeb.EndgameLive.ShowTest do
{:ok, view, _html} = live(conn, ~p"/admin/endgames/#{endgame.id}")
assert has_element?(view, "li.list-row", "Public code")
assert has_element?(view, "li.list-row", endgame.public_code)
assert has_element?(view, "li", "Public code")
assert has_element?(view, "#public-code", endgame.public_code)
assert has_element?(view, "h1", endgame.id)
end