mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Exclude youtube thumbnails larger that 700px wide
This commit is contained in:
parent
dad4b51b9b
commit
e2dcf8bac4
1 changed files with 18 additions and 10 deletions
|
|
@ -84,23 +84,31 @@ const generateVideoTags = function ( video ) {
|
||||||
return videoTags
|
return videoTags
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeThumbnailData = function ( thumbnails ) {
|
const makeThumbnailData = function ( thumbnails, widthLimit = null ) {
|
||||||
|
|
||||||
|
const thumbnailEntries = Object.entries( thumbnails )
|
||||||
|
const srcsetArray = []
|
||||||
|
|
||||||
let maxWidth = 0
|
let maxWidth = 0
|
||||||
Object.entries( thumbnails ).forEach(([thumbnailKey, thumbnail]) => {
|
|
||||||
|
thumbnailEntries.forEach(([thumbnailKey, thumbnail]) => {
|
||||||
|
if ( widthLimit !== null && widthLimit < thumbnail.width) return
|
||||||
|
|
||||||
|
// If this width is more than known maxWidth
|
||||||
|
// then set maxWidth
|
||||||
if (thumbnail.width > maxWidth) maxWidth = thumbnail.width
|
if (thumbnail.width > maxWidth) maxWidth = thumbnail.width
|
||||||
|
|
||||||
|
// Add this width to our srcset
|
||||||
|
srcsetArray.push(`${thumbnail.url} ${thumbnail.width}w`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const sizes = `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`
|
const sizes = `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`
|
||||||
|
const srcset = srcsetArray.join(', ')
|
||||||
const srcset = Object.entries( thumbnails ).map(([thumbnailKey, thumbnail]) => {
|
|
||||||
// console.log('thumbnail', thumbnail)
|
|
||||||
return `${thumbnail.url} ${thumbnail.width}w`
|
|
||||||
}).join(', ')
|
|
||||||
|
|
||||||
|
|
||||||
const src = thumbnails.default.url
|
const src = thumbnails.default.url
|
||||||
|
|
||||||
|
// console.log('srcsetArray', srcsetArray)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sizes,
|
sizes,
|
||||||
srcset,
|
srcset,
|
||||||
|
|
@ -170,7 +178,7 @@ export default async function ( applist ) {
|
||||||
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 ),
|
thumbnail: makeThumbnailData( fetchedVideos[videoId].rawData.snippet.thumbnails, 700 ),
|
||||||
endpoint: getVideoEndpoint({
|
endpoint: getVideoEndpoint({
|
||||||
slug
|
slug
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue