add meta descriptions to all shop pages
All checks were successful
deploy / deploy (push) Successful in 1m38s

Product pages: first 155 chars of description, stripped of HTML, truncated on word boundary.
Collections: contextual description based on collection type.
Content pages (about, delivery, privacy, terms): from hero_description text.
Contact: static description.
Home falls through to site_description from settings (already in layout).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey 2026-02-23 21:31:35 +00:00
parent 45f05c8bb7
commit c6da3b3d2b
4 changed files with 31 additions and 1 deletions

View File

@ -31,6 +31,7 @@ defmodule BerrypodWeb.Shop.Collection do
{:noreply, {:noreply,
socket socket
|> assign(:page_title, title) |> assign(:page_title, title)
|> assign(:page_description, collection_description(title))
|> assign(:collection_title, title) |> assign(:collection_title, title)
|> assign(:current_category, category) |> assign(:current_category, category)
|> assign(:current_sort, sort) |> assign(:current_sort, sort)
@ -75,6 +76,10 @@ defmodule BerrypodWeb.Shop.Collection do
{:noreply, push_patch(socket, to: ~p"/collections/#{slug}?sort=#{sort}")} {:noreply, push_patch(socket, to: ~p"/collections/#{slug}?sort=#{sort}")}
end end
defp collection_description("All Products"), do: "Browse our full range of products."
defp collection_description("Sale"), do: "Browse our current sale items."
defp collection_description(title), do: "Browse our #{String.downcase(title)} collection."
defp collection_path(slug, "featured"), do: ~p"/collections/#{slug}" defp collection_path(slug, "featured"), do: ~p"/collections/#{slug}"
defp collection_path(slug, sort), do: ~p"/collections/#{slug}?sort=#{sort}" defp collection_path(slug, sort), do: ~p"/collections/#{slug}?sort=#{sort}"

View File

@ -3,7 +3,10 @@ defmodule BerrypodWeb.Shop.Contact do
@impl true @impl true
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
{:ok, assign(socket, :page_title, "Contact")} {:ok,
socket
|> assign(:page_title, "Contact")
|> assign(:page_description, "Get in touch with us for any questions or help with your order.")}
end end
@impl true @impl true

View File

@ -24,6 +24,7 @@ defmodule BerrypodWeb.Shop.Content do
defp page_config(:about) do defp page_config(:about) do
%{ %{
page_title: "About", page_title: "About",
page_description: "Your story goes here this is sample content for the demo shop",
active_page: "about", active_page: "about",
hero_title: "About the studio", hero_title: "About the studio",
hero_description: "Your story goes here this is sample content for the demo shop", hero_description: "Your story goes here this is sample content for the demo shop",
@ -37,6 +38,7 @@ defmodule BerrypodWeb.Shop.Content do
defp page_config(:delivery) do defp page_config(:delivery) do
%{ %{
page_title: "Delivery & returns", page_title: "Delivery & returns",
page_description: "Everything you need to know about shipping and returns.",
active_page: "delivery", active_page: "delivery",
hero_title: "Delivery & returns", hero_title: "Delivery & returns",
hero_description: "Everything you need to know about shipping and returns", hero_description: "Everything you need to know about shipping and returns",
@ -47,6 +49,7 @@ defmodule BerrypodWeb.Shop.Content do
defp page_config(:privacy) do defp page_config(:privacy) do
%{ %{
page_title: "Privacy policy", page_title: "Privacy policy",
page_description: "How we handle your personal information.",
active_page: "privacy", active_page: "privacy",
hero_title: "Privacy policy", hero_title: "Privacy policy",
hero_description: "How we handle your personal information", hero_description: "How we handle your personal information",
@ -57,6 +60,7 @@ defmodule BerrypodWeb.Shop.Content do
defp page_config(:terms) do defp page_config(:terms) do
%{ %{
page_title: "Terms of service", page_title: "Terms of service",
page_description: "The terms and conditions governing purchases from our shop.",
active_page: "terms", active_page: "terms",
hero_title: "Terms of service", hero_title: "Terms of service",
hero_description: "The legal bits", hero_description: "The legal bits",

View File

@ -51,6 +51,7 @@ defmodule BerrypodWeb.Shop.ProductShow do
socket = socket =
socket socket
|> assign(:page_title, product.title) |> assign(:page_title, product.title)
|> assign(:page_description, meta_description(product.description))
|> assign(:product, product) |> assign(:product, product)
|> assign(:all_images, all_images) |> assign(:all_images, all_images)
|> assign(:gallery_images, gallery_images) |> assign(:gallery_images, gallery_images)
@ -214,4 +215,21 @@ defmodule BerrypodWeb.Shop.ProductShow do
<BerrypodWeb.PageTemplates.pdp {assigns} /> <BerrypodWeb.PageTemplates.pdp {assigns} />
""" """
end end
defp meta_description(nil), do: nil
defp meta_description(text) do
plain = String.replace(text, ~r/<[^>]+>/, "")
if String.length(plain) <= 155 do
plain
else
plain
|> String.slice(0, 155)
|> String.split(~r/\s+/)
|> Enum.drop(-1)
|> Enum.join(" ")
|> Kernel.<>("")
end
end
end end