mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
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:
@@ -0,0 +1,45 @@
|
||||
defmodule ChesstrainerWeb.SitemapController do
|
||||
@moduledoc """
|
||||
Generates `/sitemap.xml` for the indexable public pages.
|
||||
|
||||
Endgame play pages are deliberately left out: there are tens of thousands of
|
||||
them and they render the same interactive surface with only the position
|
||||
differing, so listing them all would be index bloat. Revisit that if public
|
||||
browse pages (by Key or theme) exist and are worth ranking.
|
||||
"""
|
||||
|
||||
use ChesstrainerWeb, :controller
|
||||
|
||||
def index(conn, _params) do
|
||||
urls = [
|
||||
url(conn, ~p"/"),
|
||||
url(conn, ~p"/privacy"),
|
||||
url(conn, ~p"/terms-conditions")
|
||||
]
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/xml")
|
||||
|> send_resp(200, render_sitemap(urls))
|
||||
end
|
||||
|
||||
defp render_sitemap(urls) do
|
||||
entries = Enum.map_join(urls, &" <url><loc>#{escape(&1)}</loc></url>\n")
|
||||
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
#{entries}</urlset>
|
||||
"""
|
||||
end
|
||||
|
||||
# Templates escape automatically; this response is built as a plain string,
|
||||
# so XML-significant characters must be escaped here.
|
||||
defp escape(value) do
|
||||
value
|
||||
|> String.replace("&", "&")
|
||||
|> String.replace("<", "<")
|
||||
|> String.replace(">", ">")
|
||||
|> String.replace("\"", """)
|
||||
|> String.replace("'", "'")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user