From 514c6ac924a50dd13fbb3ef87b1a76cde1f8db6c Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 17 Nov 2026 15:00:38 +0100 Subject: [PATCH] Add Discord invite link to navbar and footer --- assets/css/components/_icon.css | 9 ++++- config/config.exs | 3 +- lib/chesstrainer/branding.ex | 23 ++++++++++- lib/chesstrainer_web/components/layouts.ex | 32 +++++++++++++++ test/chesstrainer/branding_test.exs | 39 +++++++++++++++++++ .../components/layouts_test.exs | 39 +++++++++++++++++++ 6 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 test/chesstrainer/branding_test.exs diff --git a/assets/css/components/_icon.css b/assets/css/components/_icon.css index 1393c02..6b66e70 100644 --- a/assets/css/components/_icon.css +++ b/assets/css/components/_icon.css @@ -1,2 +1,9 @@ .eyebrow { display: flex; align-items: center; gap: 9px; margin-bottom: 27px; color: var(--color-coral-text); text-transform: uppercase; letter-spacing: .13em; font-size: 12px; font-weight: 700; } -.eyebrow svg { width: 20px; height: 20px; } \ No newline at end of file +.eyebrow svg { width: 20px; height: 20px; } + +/* Icon-only external links, e.g. the Discord invite in the navbar and footer. + Colour is inherited so the glyph matches the surrounding link row. */ +.discord-link { display: inline-flex; align-items: center; color: inherit; transition: opacity .2s; } +.discord-link:hover { opacity: .55; } +.discord-link:focus-visible { outline: 2px solid var(--color-coral-control); outline-offset: 3px; border-radius: 4px; } +.discord-link svg { width: 20px; height: 20px; } diff --git a/config/config.exs b/config/config.exs index 6db7d31..8901d74 100644 --- a/config/config.exs +++ b/config/config.exs @@ -15,7 +15,8 @@ config :chesstrainer, :branding, wordmark: "INNERSQUARE", tagline: "Endgame Trainer", support_email: "support@innersquare.app", - mail_from: "no-reply@mail.innersquare.app" + mail_from: "no-reply@mail.innersquare.app", + discord_invite: "https://discord.gg/Z2NfkG7thV" # Prelaunch gating. Production sets these from PRELAUNCH and # MAILING_LIST_ENABLED; dev and test use these defaults. diff --git a/lib/chesstrainer/branding.ex b/lib/chesstrainer/branding.ex index 76d5c59..b4b9d1b 100644 --- a/lib/chesstrainer/branding.ex +++ b/lib/chesstrainer/branding.ex @@ -12,7 +12,8 @@ defmodule Chesstrainer.Branding do wordmark: "INNERSQUARE", tagline: "Endgame Trainer", support_email: "support@innersquare.app", - mail_from: "no-reply@mail.innersquare.app" + mail_from: "no-reply@mail.innersquare.app", + discord_invite: "https://discord.gg/Z2NfkG7thV" ] @doc "The display name, e.g. `\"Lucid Chess\"`." @@ -30,6 +31,26 @@ defmodule Chesstrainer.Branding do @doc "The From address used for outgoing mail." def mail_from, do: get(:mail_from) + @doc """ + The Discord invite URL, or `nil` when no invite is configured. + + Accepts either a bare invite code (`"abc123"`) or a full URL; a bare code is + expanded to `https://discord.gg/`. + """ + def discord_invite_url do + case get(:discord_invite) do + value when is_binary(value) -> + case String.trim(value) do + "" -> nil + "http" <> _ = url -> url + code -> "https://discord.gg/#{code}" + end + + _ -> + nil + end + end + @doc "The home-page title, e.g. `\"Lucid Chess — Endgame Trainer\"`." def home_title, do: "#{name()} — #{tagline()}" diff --git a/lib/chesstrainer_web/components/layouts.ex b/lib/chesstrainer_web/components/layouts.ex index 13d0460..d74a0e3 100644 --- a/lib/chesstrainer_web/components/layouts.ex +++ b/lib/chesstrainer_web/components/layouts.ex @@ -128,6 +128,8 @@ defmodule ChesstrainerWeb.Layouts do <% end %> <% end %> + + <.discord_link /> @@ -225,6 +227,7 @@ defmodule ChesstrainerWeb.Layouts do Terms & Conditions Mentions légales Sitemap + <.discord_link /> © {@year} {Branding.name()} @@ -232,6 +235,35 @@ defmodule ChesstrainerWeb.Layouts do """ end + @doc """ + Renders the Discord invite as an icon-only link. + + The glyph is decorative; the `aria-label` carries the link's purpose for + screen readers. Renders nothing when no invite is configured, so environments + without one never show a dead link. + """ + def discord_link(assigns) do + assigns = assign(assigns, :href, Branding.discord_invite_url()) + + ~H""" + + + + """ + end + @doc """ Shows the flash group with standard titles and content. diff --git a/test/chesstrainer/branding_test.exs b/test/chesstrainer/branding_test.exs new file mode 100644 index 0000000..86091a2 --- /dev/null +++ b/test/chesstrainer/branding_test.exs @@ -0,0 +1,39 @@ +defmodule Chesstrainer.BrandingTest do + use ExUnit.Case, async: false + + alias Chesstrainer.Branding + + describe "discord_invite_url/0" do + setup do + previous = Application.get_env(:chesstrainer, :branding) + on_exit(fn -> restore(:branding, previous) end) + :ok + end + + test "passes a full URL through" do + put_branding(discord_invite: "https://discord.gg/abc123") + + assert Branding.discord_invite_url() == "https://discord.gg/abc123" + end + + test "expands a bare invite code" do + put_branding(discord_invite: " abc123 ") + + assert Branding.discord_invite_url() == "https://discord.gg/abc123" + end + + test "returns nil when the invite is blank" do + put_branding(discord_invite: "") + + assert Branding.discord_invite_url() == nil + end + end + + defp put_branding(overrides) do + config = Application.get_env(:chesstrainer, :branding, []) + Application.put_env(:chesstrainer, :branding, Keyword.merge(config, overrides)) + end + + defp restore(key, nil), do: Application.delete_env(:chesstrainer, key) + defp restore(key, value), do: Application.put_env(:chesstrainer, key, value) +end diff --git a/test/chesstrainer_web/components/layouts_test.exs b/test/chesstrainer_web/components/layouts_test.exs index 75a6cc7..f1d6dde 100644 --- a/test/chesstrainer_web/components/layouts_test.exs +++ b/test/chesstrainer_web/components/layouts_test.exs @@ -5,6 +5,7 @@ defmodule ChesstrainerWeb.LayoutsTest do alias Chesstrainer.Accounts.Scope alias Chesstrainer.Accounts.User + alias Chesstrainer.Branding alias ChesstrainerWeb.Layouts describe "navbar/1" do @@ -30,6 +31,44 @@ defmodule ChesstrainerWeb.LayoutsTest do end end + describe "discord_link/1" do + setup do + previous = Application.get_env(:chesstrainer, :branding) + on_exit(fn -> restore_env(:branding, previous) end) + :ok + end + + test "renders an icon-only link to the configured invite" do + html = render_component(&Layouts.discord_link/1, %{}) + + assert html =~ ~s(href="#{Branding.discord_invite_url()}") + assert html =~ ~s(aria-label="Join the #{Branding.name()} Discord") + assert html =~ ~s(target="_blank") + assert html =~ "noopener noreferrer" + assert html =~ ~r/]*class="discord-link"[^>]*>\s*