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
+19 -1
View File
@@ -17,6 +17,15 @@ defmodule ChesstrainerWeb.Router do
plug :accepts, ["json"]
end
# Crawler files are plain text and XML, so they must not negotiate HTML.
pipeline :seo do
end
# Never let search engines index private or authenticated areas.
pipeline :noindex do
plug ChesstrainerWeb.Plugs.NoIndex
end
scope "/", ChesstrainerWeb do
pipe_through :browser
@@ -28,7 +37,7 @@ defmodule ChesstrainerWeb.Router do
end
scope "/admin", ChesstrainerWeb do
pipe_through [:browser, :require_admin_user]
pipe_through [:browser, :noindex, :require_admin_user]
live_session :endgames,
on_mount: [{ChesstrainerWeb.UserAuth, :require_admin}] do
@@ -101,6 +110,15 @@ defmodule ChesstrainerWeb.Router do
delete "/users/log-out", UserSessionController, :delete
end
# Crawler files live outside the catch-all so they are real responses, not
# the branded 404 page.
scope "/", ChesstrainerWeb do
pipe_through :seo
get "/robots.txt", RobotsController, :index
get "/sitemap.xml", SitemapController, :index
end
# Keep this last: routes match in definition order. It gives unmatched paths a
# branded 404 page with the site chrome instead of Phoenix's bare status page.
scope "/", ChesstrainerWeb do