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:
parent
3158a94f0b
commit
504c895157
@ -2,6 +2,7 @@ defmodule SimpleshopThemeWeb.Shop.ProductShow do
|
||||
use SimpleshopThemeWeb, :live_view
|
||||
|
||||
alias SimpleshopTheme.Cart
|
||||
alias SimpleshopTheme.Images.Optimizer
|
||||
alias SimpleshopTheme.Products
|
||||
alias SimpleshopTheme.Products.{Product, ProductImage}
|
||||
|
||||
@ -23,7 +24,13 @@ defmodule SimpleshopThemeWeb.Shop.ProductShow do
|
||||
(product.images || [])
|
||||
|> Enum.sort_by(& &1.position)
|
||||
|> 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)
|
||||
|> Enum.reject(fn img -> is_nil(img.url) end)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user