mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Preprocess thumbnail attributes
This commit is contained in:
parent
a1b2594b4a
commit
9d4d447802
2 changed files with 30 additions and 27 deletions
|
|
@ -10,12 +10,12 @@
|
||||||
<div class="relative overflow-hidden w-full pb-16/9">
|
<div class="relative overflow-hidden w-full pb-16/9">
|
||||||
<picture>
|
<picture>
|
||||||
<source
|
<source
|
||||||
:sizes="thumbnailSizes"
|
:sizes="video.thumbnail.sizes"
|
||||||
:data-srcset="thumbnailSrcset"
|
:data-srcset="video.thumbnail.srcset"
|
||||||
type="image/jpg"
|
type="image/jpg"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
:data-src="video.thumbnails.default.url"
|
:data-src="video.thumbnail.src"
|
||||||
:alt="video.name"
|
:alt="video.name"
|
||||||
class="lazyload absolute h-full w-full object-cover"
|
class="lazyload absolute h-full w-full object-cover"
|
||||||
>
|
>
|
||||||
|
|
@ -64,8 +64,6 @@
|
||||||
|
|
||||||
import 'lazysizes'
|
import 'lazysizes'
|
||||||
|
|
||||||
// import { getVideoEndpoint } from '~/helpers/app-derived.js'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
video: {
|
video: {
|
||||||
|
|
@ -74,26 +72,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
thumbnailSizes () {
|
|
||||||
let maxWidth = 0
|
|
||||||
Object.entries(this.video.thumbnails).forEach(([thumbnailKey, thumbnail]) => {
|
|
||||||
if (thumbnail.width > maxWidth) maxWidth = thumbnail.width
|
|
||||||
})
|
|
||||||
|
|
||||||
// example:
|
|
||||||
// "(max-width: 640px) 100vw, 640px"
|
|
||||||
return `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`
|
|
||||||
},
|
|
||||||
thumbnailSrcset () {
|
|
||||||
// console.log('this.video', this.video)
|
|
||||||
|
|
||||||
// example:
|
|
||||||
// https://vumbnail.com/358629078.jpg 640w, https://vumbnail.com/358629078_large.jpg 640w, https://vumbnail.com/358629078_medium.jpg 200w, https://vumbnail.com/358629078_small.jpg 100w
|
|
||||||
return Object.entries(this.video.thumbnails).map(([thumbnailKey, thumbnail]) => {
|
|
||||||
// console.log('thumbnail', thumbnail)
|
|
||||||
return `${thumbnail.url} ${thumbnail.width}w`
|
|
||||||
}).join(', ')
|
|
||||||
},
|
|
||||||
pill () {
|
pill () {
|
||||||
// if this video has a banchmark tag
|
// if this video has a banchmark tag
|
||||||
// then pill is 'Benchmark'
|
// then pill is 'Benchmark'
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,30 @@ const generateVideoTags = function ( video ) {
|
||||||
return videoTags
|
return videoTags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const makeThumbnailData = function ( thumbnails ) {
|
||||||
|
|
||||||
|
let maxWidth = 0
|
||||||
|
Object.entries( thumbnails ).forEach(([thumbnailKey, thumbnail]) => {
|
||||||
|
if (thumbnail.width > maxWidth) maxWidth = thumbnail.width
|
||||||
|
})
|
||||||
|
|
||||||
|
const sizes = `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`
|
||||||
|
|
||||||
|
const srcset = Object.entries( thumbnails ).map(([thumbnailKey, thumbnail]) => {
|
||||||
|
// console.log('thumbnail', thumbnail)
|
||||||
|
return `${thumbnail.url} ${thumbnail.width}w`
|
||||||
|
}).join(', ')
|
||||||
|
|
||||||
|
|
||||||
|
const src = thumbnails.default.url
|
||||||
|
|
||||||
|
return {
|
||||||
|
sizes,
|
||||||
|
srcset,
|
||||||
|
src
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default async function ( applist ) {
|
export default async function ( applist ) {
|
||||||
|
|
||||||
// Fetch Commits
|
// Fetch Commits
|
||||||
|
|
@ -139,14 +163,15 @@ export default async function ( applist ) {
|
||||||
lastUpdated,
|
lastUpdated,
|
||||||
apps,
|
apps,
|
||||||
slug,
|
slug,
|
||||||
channel:{
|
channel: {
|
||||||
name: fetchedVideos[videoId].rawData.snippet.channelTitle,
|
name: fetchedVideos[videoId].rawData.snippet.channelTitle,
|
||||||
id: fetchedVideos[videoId].rawData.snippet.channelId
|
id: fetchedVideos[videoId].rawData.snippet.channelId
|
||||||
},
|
},
|
||||||
// Convert tags set into array
|
// Convert tags set into array
|
||||||
tags: Array.from(tags),
|
tags: Array.from(tags),
|
||||||
timestamps: fetchedVideos[videoId].timestamps,
|
timestamps: fetchedVideos[videoId].timestamps,
|
||||||
thumbnails: fetchedVideos[videoId].rawData.snippet.thumbnails,
|
// thumbnails: fetchedVideos[videoId].rawData.snippet.thumbnails,
|
||||||
|
thumbnail: makeThumbnailData( fetchedVideos[videoId].rawData.snippet.thumbnails ),
|
||||||
endpoint: getVideoEndpoint({
|
endpoint: getVideoEndpoint({
|
||||||
slug
|
slug
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue