add sitemap, robots, and noindex admin routes (#85)

Serve a runtime sitemap.xml with the indexable marketing pages only; endgame play pages are left out to avoid indexing tens of thousands of near-identical pages. Generate robots.txt at runtime so it points at the sitemap on the deployment's host, and send X-Robots-Tag: noindex from every /admin response.
This commit is contained in:
2026-11-06 23:04:10 +01:00
parent 924a3e08dc
commit eaf72a7686
9 changed files with 174 additions and 7 deletions
@@ -59,6 +59,27 @@ defmodule ChesstrainerWeb.AdminGatingTest do
assert html_response(conn, 200)
end
test "admin routes are marked noindex for crawlers", %{conn: conn} do
conn = get(conn, ~p"/admin/endgames")
assert get_resp_header(conn, "x-robots-tag") == ["noindex, nofollow"]
{:ok, admin} = Accounts.update_user_role(user_fixture(), :admin)
conn =
build_conn()
|> log_in_user(admin)
|> get(~p"/admin/endgames")
assert get_resp_header(conn, "x-robots-tag") == ["noindex, nofollow"]
end
test "public pages are not marked noindex", %{conn: conn} do
conn = get(conn, ~p"/")
assert get_resp_header(conn, "x-robots-tag") == []
end
test "the navbar hides the Admin link from members", %{conn: conn} do
conn =
conn
@@ -0,0 +1,22 @@
defmodule ChesstrainerWeb.RobotsControllerTest do
use ChesstrainerWeb.ConnCase, async: true
alias ChesstrainerWeb.Endpoint
describe "GET /robots.txt" do
test "allows crawlers and points at the sitemap", %{conn: conn} do
body = conn |> get(~p"/robots.txt") |> response(200)
assert body =~ "User-agent: *"
assert body =~ "Allow: /"
assert body =~ "Sitemap: #{Endpoint.url()}/sitemap.xml"
end
test "is served as plain text", %{conn: conn} do
conn = get(conn, ~p"/robots.txt")
assert [content_type] = get_resp_header(conn, "content-type")
assert content_type =~ "text/plain"
end
end
end
@@ -0,0 +1,26 @@
defmodule ChesstrainerWeb.SitemapControllerTest do
use ChesstrainerWeb.ConnCase, async: true
alias ChesstrainerWeb.Endpoint
describe "GET /sitemap.xml" do
test "lists only the public marketing pages", %{conn: conn} do
body = conn |> get(~p"/sitemap.xml") |> response(200)
base_url = Endpoint.url()
assert body =~ ~s(<?xml version="1.0" encoding="UTF-8"?>)
assert body =~ ~s(<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">)
assert body =~ "<loc>#{base_url}/</loc>"
assert body =~ "<loc>#{base_url}/privacy</loc>"
assert body =~ "<loc>#{base_url}/terms-conditions</loc>"
assert length(:binary.matches(body, "<url>")) == 3
end
test "is served as XML", %{conn: conn} do
conn = get(conn, ~p"/sitemap.xml")
assert [content_type] = get_resp_header(conn, "content-type")
assert content_type =~ "application/xml"
end
end
end