collective page images refactoring
This commit is contained in:
1 parent
087a4b6172
commit
a14db0e8da
6 files changed
+68
-66
No files matched your search
@@ -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(', ')
|
||||
}
|
||||
Reference in new issue
Block a user