berrypod/lib/berrypod_web/live/shop/home.ex
jamey 4e36b654d3 add JSON-LD structured data
Product pages: Product schema (name, description, image, price/currency,
availability) + BreadcrumbList (Home > Category > Product). Home page:
Organization schema (name, url). Uses Jason with html_safe escaping so
the JSON is safe to embed in <script> tags.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-23 22:37:34 +00:00

41 lines
850 B
Elixir

defmodule BerrypodWeb.Shop.Home do
use BerrypodWeb, :live_view
alias Berrypod.Products
@impl true
def mount(_params, _session, socket) do
products = Products.list_visible_products(limit: 8)
base = BerrypodWeb.Endpoint.url()
site_name = socket.assigns.theme_settings.site_name
org_ld =
Jason.encode!(
%{
"@context" => "https://schema.org",
"@type" => "Organization",
"name" => site_name,
"url" => base <> "/"
},
escape: :html_safe
)
socket =
socket
|> assign(:page_title, "Home")
|> assign(:og_url, base <> "/")
|> assign(:json_ld, org_ld)
|> assign(:products, products)
{:ok, socket}
end
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.home {assigns} />
"""
end
end