From b11f7d47d052c28e40e1f21bdba829bdec7fdf27 Mon Sep 17 00:00:00 2001 From: jamey Date: Mon, 23 Feb 2026 21:37:50 +0000 Subject: [PATCH] add open graph and twitter card meta tags Product pages get og:type=product, og:url, og:image (hero image), and twitter:card=summary_large_image. All other shop pages get og:type=website and twitter:card=summary. og:title and og:description mirror the existing page title and meta description. Co-Authored-By: Claude Sonnet 4.6 --- .../components/layouts/shop_root.html.heex | 25 +++++++++++++++++++ lib/berrypod_web/live/shop/product_show.ex | 6 +++++ 2 files changed, 31 insertions(+) diff --git a/lib/berrypod_web/components/layouts/shop_root.html.heex b/lib/berrypod_web/components/layouts/shop_root.html.heex index 0b59dc1..7376304 100644 --- a/lib/berrypod_web/components/layouts/shop_root.html.heex +++ b/lib/berrypod_web/components/layouts/shop_root.html.heex @@ -14,6 +14,31 @@ <.live_title suffix={" · #{@theme_settings.site_name}"}> {assigns[:page_title]} + <% og_title = + if assigns[:page_title], + do: "#{assigns[:page_title]} · #{@theme_settings.site_name}", + else: @theme_settings.site_name + + og_description = + assigns[:page_description] || + @theme_settings.site_description || + "Welcome to #{@theme_settings.site_name}" %> + + + + + <%= if assigns[:og_url] do %> + + <% end %> + <%= if assigns[:og_image] do %> + + + + <% else %> + + <% end %> + + <%= for preload <- Berrypod.Theme.Fonts.preload_links( @theme_settings.typography, diff --git a/lib/berrypod_web/live/shop/product_show.ex b/lib/berrypod_web/live/shop/product_show.ex index e4eff08..dbe3170 100644 --- a/lib/berrypod_web/live/shop/product_show.ex +++ b/lib/berrypod_web/live/shop/product_show.ex @@ -52,6 +52,9 @@ defmodule BerrypodWeb.Shop.ProductShow do socket |> assign(:page_title, product.title) |> assign(:page_description, meta_description(product.description)) + |> assign(:og_type, "product") + |> assign(:og_url, BerrypodWeb.Endpoint.url() <> "/products/#{slug}") + |> assign(:og_image, og_image_url(all_images)) |> assign(:product, product) |> assign(:all_images, all_images) |> assign(:gallery_images, gallery_images) @@ -216,6 +219,9 @@ defmodule BerrypodWeb.Shop.ProductShow do """ end + defp og_image_url([%{url: "/" <> _ = path} | _]), do: BerrypodWeb.Endpoint.url() <> path + defp og_image_url(_), do: nil + defp meta_description(nil), do: nil defp meta_description(text) do