@@ -252,6 +252,8 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page
252
252
height : 630 ,
253
253
fonts : fonts . length ? fonts : undefined ,
254
254
headers : {
255
+ // We don't want to cache the image for too long in the browser
256
+ 'cache-control' : 'public, max-age=300, s-maxage=31536000' ,
255
257
'cache-tag' : [
256
258
getCacheTag ( {
257
259
tag : 'site' ,
@@ -366,19 +368,22 @@ const SUPPORTED_IMAGE_TYPES = [
366
368
async function fetchImage ( url : string , options ?: ResizeImageOptions ) {
367
369
// Skip early some images to avoid fetching them
368
370
const parsedURL = new URL ( url ) ;
369
- if ( UNSUPPORTED_IMAGE_EXTENSIONS . includes ( getExtension ( parsedURL . pathname ) . toLowerCase ( ) ) ) {
370
- return null ;
371
- }
372
371
373
- // We use the image resizer to normalize the image format to PNG.
374
- // as @vercel /og can sometimes fail on some JPEG images.
375
- const response =
376
- checkIsSizableImageURL ( url ) !== SizableImageAction . Resize
377
- ? await fetch ( url )
378
- : await resizeImage ( url , {
379
- ...options ,
380
- format : 'png' ,
381
- } ) ;
372
+ let response : Response ;
373
+ if (
374
+ UNSUPPORTED_IMAGE_EXTENSIONS . includes ( getExtension ( parsedURL . pathname ) . toLowerCase ( ) ) ||
375
+ checkIsSizableImageURL ( url ) === SizableImageAction . Resize
376
+ ) {
377
+ // We use the image resizer to normalize the image format to PNG.
378
+ // as @vercel /og can sometimes fail on some JPEG images, and will fail on avif and webp images.
379
+ response = await resizeImage ( url , {
380
+ ...options ,
381
+ format : 'png' ,
382
+ bypassSkipCheck : true , // Bypass the check to see if the image can be resized
383
+ } ) ;
384
+ } else {
385
+ response = await fetch ( url ) ;
386
+ }
382
387
383
388
// Filter out unsupported image types
384
389
const contentType = response . headers . get ( 'content-type' ) ;
0 commit comments