collective page images refactoring

This commit is contained in:
tmshv committed 2020-03-03 05:58:35 +03:00
1 parent 087a4b6172
commit a14db0e8da
6 files changed
+68 -66

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { ImageSize } from 'src/types'
export type ResizeOptions = {
width: number
height: number
}
export function resizeImage(src: string, options: ResizeOptions): string {
return `https://images.weserv.nl/?url=${src}&w=${options.width}&h=${options.height}&n=-1`
}
export function imageSrcSet(src: string, sizes: ImageSize[]): string {
const set = sizes
.map(x => ({
value: x,
href: resizeImage(src, {
width: x,
height: x,
}),
}))
return set
.map(x => `${x.href} ${x.value}w`)
.join(', ')
}