From 6acaee1b5a780985fc4351c3c96b4eaf977c02e9 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Wed, 27 Apr 2022 14:29:21 -0500 Subject: [PATCH] Add video copmenents --- src/components/video/card.astro | 63 ++++++++++++++++++++++++ src/components/video/poster.astro | 31 ++++++++++++ src/components/video/row.astro | 79 +++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 src/components/video/card.astro create mode 100644 src/components/video/poster.astro create mode 100644 src/components/video/row.astro diff --git a/src/components/video/card.astro b/src/components/video/card.astro new file mode 100644 index 0000000..59160b8 --- /dev/null +++ b/src/components/video/card.astro @@ -0,0 +1,63 @@ +--- +import Poster from './poster.astro' + +const { + video, + width = '325px', + classes = 'w-full flex-shrink-0 flex-grow-0 border-2 border-transparent rounded-2xl overflow-hidden' +} = Astro.props + +const cardClasses = `video-card ${ classes }` + +--- +
+ +
+
+
+ +
+
+
+
+ + + +
+ + { ( video.tags.includes('benchmark') ) ? +
+ Benchmark +
: '' + } + +
+ + +
+
{ video.name }
+
+
+
+
+ + diff --git a/src/components/video/poster.astro b/src/components/video/poster.astro new file mode 100644 index 0000000..77d6539 --- /dev/null +++ b/src/components/video/poster.astro @@ -0,0 +1,31 @@ +--- +const { + video +} = Astro.props + +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 +} +--- + + + { Object.entries( mergedSources ).map( ([ key, source ]) => ( + + ) ) } + + { + diff --git a/src/components/video/row.astro b/src/components/video/row.astro new file mode 100644 index 0000000..59e8240 --- /dev/null +++ b/src/components/video/row.astro @@ -0,0 +1,79 @@ +--- +import Card from './card.astro' + +const { + videos, + cardWidth = '325', + classes = '' +} = Astro.props + +// Math.random should be unique because of its seeding algorithm. +// Convert it to base 36 (numbers + letters), and grab the first 9 characters +// after the decimal. +const uid = Math.random().toString(36).substr(2, 9) +const rowId = `row-${ uid }` +const rowSelector = `#${ rowId }` + +--- +
+ +
+ { videos.map(video => ( + + )) } +
+ + + + +
+ + + +