Add Discord invite link to navbar and footer

This commit is contained in:
2026-11-17 15:00:38 +01:00
parent e0b446bbfb
commit 514c6ac924
6 changed files with 142 additions and 3 deletions
+8 -1
View File
@@ -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; }
.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; }
+2 -1
View File
@@ -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.
+22 -1
View File
@@ -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/<code>`.
"""
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()}"
@@ -128,6 +128,8 @@ defmodule ChesstrainerWeb.Layouts do
<% end %>
</div>
<% end %>
<.discord_link />
</div>
</nav>
</header>
@@ -225,6 +227,7 @@ defmodule ChesstrainerWeb.Layouts do
<a href="/terms-conditions">Terms & Conditions</a>
<a href="/mentions-legales">Mentions légales</a>
<a href="/sitemap.xml">Sitemap</a>
<.discord_link />
</nav>
<small>© {@year} {Branding.name()}</small>
@@ -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"""
<a
:if={@href}
class="discord-link"
href={@href}
target="_blank"
rel="noopener noreferrer"
aria-label={"Join the #{Branding.name()} Discord"}
>
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path
fill="currentColor"
d="M20.317 4.3698a19.7913 19.7913 0 0 0-4.8851-1.5152.0741.0741 0 0 0-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 0 0-.0785-.037 19.7363 19.7363 0 0 0-4.8852 1.515.0699.0699 0 0 0-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 0 0 .0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 0 0 .0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 0 0-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 0 1-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 0 1 .0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 0 1 .0785.0105c.1202.0991.246.1971.3728.2914a.077.077 0 0 1-.0066.1277c-.5986.3428-1.2201.6447-1.8739.8923a.0766.0766 0 0 0-.0407.1057c.36.699.7715 1.3647 1.225 1.9942a.076.076 0 0 0 .0843.0276c1.9608-.6066 3.9493-1.5218 6.0021-3.0294a.077.077 0 0 0 .0322-.0561c.5008-5.1763-.8398-9.6746-3.5543-13.6607a.061.061 0 0 0-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z"
/>
</svg>
</a>
"""
end
@doc """
Shows the flash group with standard titles and content.
+39
View File
@@ -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
@@ -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/<a[^>]*class="discord-link"[^>]*>\s*<svg/
end
test "is rendered by the navbar and the footer" do
navbar = render_component(&Layouts.navbar/1, %{current_scope: nil})
assert navbar =~ ~s(class="discord-link")
footer = render_component(&Layouts.footer/1, %{})
assert footer =~ ~s(class="discord-link")
end
test "renders nothing when no invite is configured" do
Application.put_env(
:chesstrainer,
:branding,
Keyword.put(Application.get_env(:chesstrainer, :branding, []), :discord_invite, "")
)
html = render_component(&Layouts.discord_link/1, %{})
refute html =~ "discord-link"
end
end
describe "colour_mode_toggle/1" do
test "renders light and dark modes as a labelled radiogroup" do
html = render_component(&Layouts.colour_mode_toggle/1, %{})