Skip to content

Commit b3aa1b6

Browse files
committed
feat: use wsrc.nl as a CDN for the images
https://images.weserv.nl/ is used to cache and resize images based on the needs of different components on the page
1 parent c11bcdc commit b3aa1b6

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

app/components/Exercise/Exercise.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ export default function Exercise(props: ExerciseProps) {
3535
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
3636
setNote(event.target.value);
3737
};
38+
const width: number = 382;
39+
const height: number = Math.floor(width / 16 * 9);
3840

3941
return (
4042
<div className={'w-full max-w-96 flex flex-col rounded-lg border border-neutral-300 dark:border-neutral-600'}>
41-
<div className={'relative aspect-video rounded-t-lg cursor-pointer'}
43+
<div className={'relative rounded-t-lg cursor-pointer'}
4244
onClick={() => setDisplayVideoPlayer(!displayVideoPlayer)}>
4345
{hasPreviewImage ? (
4446
<Image
45-
src={props.exercise.previewImageUrl!}
47+
src={`https://wsrv.nl/?url=${props.exercise.previewImageUrl!}&w=${width}&h=${height}&dpr=2`}
4648
alt={'Woman holding dumbbell in white crew neck t-shirt'}
47-
width={1080}
48-
height={721}
49-
className={'rounded-t-lg object-cover w-96 h-auto'}/>
49+
width={width}
50+
height={height}
51+
className={'rounded-t-lg object-cover'}/>
5052
) : (
5153
<div className='w-full h-auto'>
5254
<PreviewImagePlaceholder/>

app/components/WorkoutPreview/WorkoutPreview.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ export default function WorkoutPreview(props: WorkoutPreviewProps) {
3333
const exercises = topUpPreviewImages(exercisesWithImages)
3434
.map((exercise, index) => {
3535
const width = 128;
36+
const height = Math.floor(width / 16 * 9);
3637
return <Image key={`${exercise.id}-${index}`}
37-
src={exercise.previewImageUrl!}
38+
src={`https://wsrv.nl/?url=${exercise.previewImageUrl!}&w=${width}&h=${height}&dpr=2`}
3839
width={width}
39-
height={width / 16 * 9}
40+
height={height}
4041
alt={exercise.exerciseName}
4142
/>
4243
})

next.config.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const nextConfig = {
77
hostname: '*.public.blob.vercel-storage.com',
88
port: '',
99
},
10+
{
11+
protocol: 'https',
12+
hostname: 'wsrv.nl',
13+
port: '',
14+
},
1015
],
1116
},
1217
};

0 commit comments

Comments
 (0)