diff --git a/components-eleventy/video/card.js b/components-eleventy/video/card.js index a21fb49..ba5501a 100644 --- a/components-eleventy/video/card.js +++ b/components-eleventy/video/card.js @@ -1,3 +1,4 @@ +import renderPoster from './poster.js' function pill ( text ) { return /* html */` @@ -20,6 +21,8 @@ export default async function ( video, options = {} ) { // console.log('video', video) + const posterHtml = renderPoster( video ) + return /* html */`
- - - ${video.name} - + ${ posterHtml }
- - ${ Object.entries( mergedSources ).map( ([ key, source ]) => (/* html */` - - `) ).join('') } - - ${ video.name } - - ` -} +import renderPoster from './poster.js' function renderTimestamps ( video ) { const timestampsForRender = video.timestamps.map( timestamp => { diff --git a/components-eleventy/video/poster.js b/components-eleventy/video/poster.js new file mode 100644 index 0000000..d78d888 --- /dev/null +++ b/components-eleventy/video/poster.js @@ -0,0 +1,32 @@ + + +export default function ( video ) { + const webpSource = { + ...video.thumbnail, + srcset: video.thumbnail.srcset.replaceAll('ytimg.com/vi/', 'ytimg.com/vi_webp/').replace(/.png|.jpg|.jpeg/g, '.webp') + } + + const mergedSources = { + webp: webpSource, + jpeg: video.thumbnail + } + + return /* html */` + + + ${ Object.entries( mergedSources ).map( ([ key, source ]) => (/* html */` + + `) ).join('') } + + ${ video.name } + + ` +}