diff --git a/lib/berrypod_web/live/shop/collection.ex b/lib/berrypod_web/live/shop/collection.ex index 7cde998..ad24947 100644 --- a/lib/berrypod_web/live/shop/collection.ex +++ b/lib/berrypod_web/live/shop/collection.ex @@ -31,6 +31,7 @@ defmodule BerrypodWeb.Shop.Collection do {:noreply, socket |> assign(:page_title, title) + |> assign(:page_description, collection_description(title)) |> assign(:collection_title, title) |> assign(:current_category, category) |> assign(:current_sort, sort) @@ -75,6 +76,10 @@ defmodule BerrypodWeb.Shop.Collection do {:noreply, push_patch(socket, to: ~p"/collections/#{slug}?sort=#{sort}")} 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, sort), do: ~p"/collections/#{slug}?sort=#{sort}" diff --git a/lib/berrypod_web/live/shop/contact.ex b/lib/berrypod_web/live/shop/contact.ex index ec707c9..f9603bc 100644 --- a/lib/berrypod_web/live/shop/contact.ex +++ b/lib/berrypod_web/live/shop/contact.ex @@ -3,7 +3,10 @@ defmodule BerrypodWeb.Shop.Contact do @impl true 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 @impl true diff --git a/lib/berrypod_web/live/shop/content.ex b/lib/berrypod_web/live/shop/content.ex index 84107e7..cb1d383 100644 --- a/lib/berrypod_web/live/shop/content.ex +++ b/lib/berrypod_web/live/shop/content.ex @@ -24,6 +24,7 @@ defmodule BerrypodWeb.Shop.Content do defp page_config(:about) do %{ page_title: "About", + page_description: "Your story goes here – this is sample content for the demo shop", active_page: "about", hero_title: "About the studio", 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 %{ page_title: "Delivery & returns", + page_description: "Everything you need to know about shipping and returns.", active_page: "delivery", hero_title: "Delivery & 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 %{ page_title: "Privacy policy", + page_description: "How we handle your personal information.", active_page: "privacy", hero_title: "Privacy policy", hero_description: "How we handle your personal information", @@ -57,6 +60,7 @@ defmodule BerrypodWeb.Shop.Content do defp page_config(:terms) do %{ page_title: "Terms of service", + page_description: "The terms and conditions governing purchases from our shop.", active_page: "terms", hero_title: "Terms of service", hero_description: "The legal bits", diff --git a/lib/berrypod_web/live/shop/product_show.ex b/lib/berrypod_web/live/shop/product_show.ex index 02e907b..e4eff08 100644 --- a/lib/berrypod_web/live/shop/product_show.ex +++ b/lib/berrypod_web/live/shop/product_show.ex @@ -51,6 +51,7 @@ defmodule BerrypodWeb.Shop.ProductShow do socket = socket |> assign(:page_title, product.title) + |> assign(:page_description, meta_description(product.description)) |> assign(:product, product) |> assign(:all_images, all_images) |> assign(:gallery_images, gallery_images) @@ -214,4 +215,21 @@ defmodule BerrypodWeb.Shop.ProductShow do """ 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