berrypod/lib/berrypod_web/controllers/seo_controller.ex
jamey a41771efc8 integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout:
- Shop components: layout nav, cart, product links
- Controllers: cart, checkout, contact, seo, order lookup
- Shop pages: collection, product, search, checkout success, etc.
- Site context: nav item url resolution

Admin URL management:
- Settings page: prefix editor with validation feedback
- Page renderer: url_editor component for page URLs
- CSS for url editor styling

Test updates for cache isolation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-01 00:36:17 +01:00

80 lines
1.9 KiB
Elixir

defmodule BerrypodWeb.SeoController do
use BerrypodWeb, :controller
alias Berrypod.{Pages, Products}
alias BerrypodWeb.R
def robots(conn, _params) do
base = BerrypodWeb.Endpoint.url()
content = """
User-agent: *
Allow: /
Disallow: /admin/
Disallow: /api/
Disallow: /users/
Disallow: /webhooks/
Disallow: /checkout/
Sitemap: #{base}/sitemap.xml
"""
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, content)
end
def sitemap(conn, _params) do
base = BerrypodWeb.Endpoint.url()
products = Products.list_visible_products()
categories = Products.list_categories()
static_pages = [
{R.home(), "daily", "1.0"},
{R.collection("all"), "daily", "0.9"},
{R.about(), "monthly", "0.5"},
{R.contact(), "monthly", "0.5"},
{R.delivery(), "monthly", "0.5"},
{R.privacy(), "monthly", "0.3"},
{R.terms(), "monthly", "0.3"}
]
category_pages =
Enum.map(categories, fn cat ->
{R.collection(cat.slug), "daily", "0.8"}
end)
product_pages =
Enum.map(products, fn product ->
{R.product(product.slug), "weekly", "0.9"}
end)
custom_pages =
Pages.list_custom_pages()
|> Enum.filter(& &1.published)
|> Enum.map(fn page -> {"/#{page.slug}", "weekly", "0.6"} end)
all_pages = static_pages ++ category_pages ++ product_pages ++ custom_pages
entries =
Enum.map_join(all_pages, "\n", fn {path, changefreq, priority} ->
" <url>\n" <>
" <loc>#{base}#{path}</loc>\n" <>
" <changefreq>#{changefreq}</changefreq>\n" <>
" <priority>#{priority}</priority>\n" <>
" </url>"
end)
xml = """
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
#{entries}
</urlset>
"""
conn
|> put_resp_content_type("application/xml")
|> send_resp(200, xml)
end
end