From 64f9ba7a21400bbe8369dd4d421dcf3bf907209e Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 16:34:28 +0300 Subject: [PATCH] AlbumImage size calculation --- pages/gallery.jsx | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/pages/gallery.jsx b/pages/gallery.jsx index 2f3db5ff..7006780b 100644 --- a/pages/gallery.jsx +++ b/pages/gallery.jsx @@ -18,19 +18,31 @@ function getMeta() { } } +function resize(maxWidth, width, height) { + const ratio = maxWidth / width + + return [ + width * ratio, + height * ratio, + ] +} + const m = 1 -const AlbumImage = ({ data, alt }) => ( - - {alt} `${url} ${density}x`)} - /> - -) +const AlbumImage = ({ data, alt }) => { + const [width, height] = resize(200, data.width, data.height) + return ( + + {alt} `${url} ${density}x`)} + /> + + ) +} const GItem = ({ album }) => (