diff --git a/src/components/atoms/Image.svelte b/src/components/atoms/Image.svelte index 999876c..a5aaaaa 100644 --- a/src/components/atoms/Image.svelte +++ b/src/components/atoms/Image.svelte @@ -17,15 +17,7 @@ large?: { width?: number, height?: number } } - - /** - * Get asset url from size - * @description Adds the size and the format to the result - * @returns string `id?key={key}-{size}-{format}` - */ - const getSizeUrl = (key: string, size: string, format: string) => { - return getAssetUrlKey(id, `${key}-${size}-${format}`) - } + let srcSet = { webp: [], jpg: [] } /** @@ -52,20 +44,32 @@ /** * Image attributes */ - const imgWidth: number = sizes && sizes.small ? sizes.small.width : width - const imgHeight: number = sizes && sizes.small ? sizes.small.height : height - const imgSrc = id ? getSizeUrl(sizeKey, 'small', 'jpg') : src ? src : null + $: imgWidth = sizes && sizes.small ? sizes.small.width : width + $: imgHeight = sizes && sizes.small ? sizes.small.height : height + $: imgSrc = id ? getAssetUrlKey(id, `${sizeKey}-small-jpg`) : src ? src : null + $: srcSet = { + webp: [ + `${getAssetUrlKey(id, `${sizeKey}-small-webp`)} 345w`, + sizes && sizes.medium ? `${getAssetUrlKey(id, `${sizeKey}-medium-webp`)} 768w` : null, + sizes && sizes.large ? `${getAssetUrlKey(id, `${sizeKey}-large-webp`)} 1280w` : null, + ], + jpg: [ + `${getAssetUrlKey(id, `${sizeKey}-small-jpg`)} 345w`, + sizes && sizes.medium ? `${getAssetUrlKey(id, `${sizeKey}-medium-jpg`)} 768w` : null, + sizes && sizes.large ? `${getAssetUrlKey(id, `${sizeKey}-large-jpg`)} 1280w` : null, + ] + }