From fe9040ada438ccd5a723d4e012e1cc0045ae9472 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 7 May 2022 13:01:09 -0500 Subject: [PATCH] Use replaceAll package for older node support --- helpers/listing-page.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/helpers/listing-page.js b/helpers/listing-page.js index cd9c223..66be718 100644 --- a/helpers/listing-page.js +++ b/helpers/listing-page.js @@ -1,5 +1,7 @@ import has from 'just-has' +// https://anguscroll.com/just/just-replace-all +import replaceAll from 'just-replace-all' import { getAppType @@ -21,13 +23,21 @@ function makeDescription ( listing ) { return `Latest reported support status of ${ listing.name } on Apple Silicon and Apple M1 Pro and M1 Max Processors.` } +function convertYoutubeImageUrl ( stringWithUrls, extension ) { + let workingString = stringWithUrls + + workingString = replaceAll( stringWithUrls, 'ytimg.com/vi/', `ytimg.com/vi_${ extension }/`) + + workingString = workingString.replace(/.png|.jpg|.jpeg/g, `.${ extension }`) + + return workingString +} + export function getVideoImages ( video ) { // Catch the case where the video has no thumbnails if ( !has( video, 'thumbnail' ) ) throw new Error('No thumbnail found') - const convertYoutubeImageUrl = ( stringWithUrls, extension ) => stringWithUrls.replaceAll('ytimg.com/vi/', `ytimg.com/vi_${ extension }/`).replace(/.png|.jpg|.jpeg/g, `.${ extension }`) - const webpSource = { ...video.thumbnail, srcset: convertYoutubeImageUrl( video.thumbnail.srcset, 'webp' ),