cap gallery image width to max available variant

Gallery was hardcoding 1200px width, breaking for images with smaller
source dimensions where only 400/800 variants exist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey 2026-02-16 17:48:03 +00:00
parent 3158a94f0b
commit 504c895157

View File

@ -2,6 +2,7 @@ defmodule SimpleshopThemeWeb.Shop.ProductShow do
use SimpleshopThemeWeb, :live_view use SimpleshopThemeWeb, :live_view
alias SimpleshopTheme.Cart alias SimpleshopTheme.Cart
alias SimpleshopTheme.Images.Optimizer
alias SimpleshopTheme.Products alias SimpleshopTheme.Products
alias SimpleshopTheme.Products.{Product, ProductImage} alias SimpleshopTheme.Products.{Product, ProductImage}
@ -23,7 +24,13 @@ defmodule SimpleshopThemeWeb.Shop.ProductShow do
(product.images || []) (product.images || [])
|> Enum.sort_by(& &1.position) |> Enum.sort_by(& &1.position)
|> Enum.map(fn img -> |> Enum.map(fn img ->
%{url: ProductImage.direct_url(img, 1200), color: img.color} width =
case ProductImage.source_width(img) do
nil -> 1200
sw -> Enum.max(Optimizer.applicable_widths(sw))
end
%{url: ProductImage.url(img, width), color: img.color}
end) end)
|> Enum.reject(fn img -> is_nil(img.url) end) |> Enum.reject(fn img -> is_nil(img.url) end)