diff --git a/src/components/video/poster.astro b/src/components/video/poster.astro index d5c05c4..bd86966 100644 --- a/src/components/video/poster.astro +++ b/src/components/video/poster.astro @@ -1,23 +1,57 @@ --- import { getVideoImages } from '~/helpers/listing-page.js' const { - video + video, + loading = 'lazy' } = Astro.props const images = getVideoImages( video ) + +function makeSourceAttributes ( [ key, source ] ) { + const sizes = source.sizes + const type = `image/${ key }` + + if ( loading === 'eager' ) { + return { + sizes, + type, + srcset: source.srcset, + } + } + + // Lazysizes attributes + return { + sizes, + type, + 'data-srcset': source.srcset + } +} + +function makeImgAttributes ( src ) { + + if ( loading === 'eager' ) { + return { + src: src, + } + } + + // Lazysizes attributes + return { + 'data-src': src, + } +} + --- { Object.entries( images.sources ).map( ([ key, source ]) => ( - ) ) } + )) } {