AlbumImage size calculation

This commit is contained in:
tmshv committed 2019-10-14 16:34:28 +03:00
1 parent ea5055b46c
commit 64f9ba7a21
1 file changed
+24 -12
+24 -12
View File
@@ -18,19 +18,31 @@ function getMeta() {
} }
} }
function resize(maxWidth, width, height) {
const ratio = maxWidth / width
return [
width * ratio,
height * ratio,
]
}
const m = 1 const m = 1
const AlbumImage = ({ data, alt }) => ( const AlbumImage = ({ data, alt }) => {
<picture> const [width, height] = resize(200, data.width, data.height)
<img return (
className="opa" <picture>
alt={alt} <img
src={data.src} className="opa"
width={data.width * m} alt={alt}
height={data.height * m} src={data.src}
srcSet={(data.set || []).map(({ url, density }) => `${url} ${density}x`)} width={width * m}
/> height={height * m}
</picture> srcSet={(data.set || []).map(({ url, density }) => `${url} ${density}x`)}
) />
</picture>
)
}
const GItem = ({ album }) => ( const GItem = ({ album }) => (
<div className="gallery-item"> <div className="gallery-item">