Make og image access resilient on first deploy
This commit is contained in:
parent
1763d7c063
commit
583df5698e
@ -6,6 +6,7 @@ import { ImageResponse } from 'next/og';
|
|||||||
import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
|
import { getImageResponseCacheControlHeaders } from '@/image-response/cache';
|
||||||
import { STATICALLY_OPTIMIZED } from '@/site/config';
|
import { STATICALLY_OPTIMIZED } from '@/site/config';
|
||||||
import { GENERATE_STATIC_PARAMS_LIMIT, getPhotoIds } from '@/photo/db';
|
import { GENERATE_STATIC_PARAMS_LIMIT, getPhotoIds } from '@/photo/db';
|
||||||
|
import { isNextImageReadyBasedOnPhotos } from '@/photo';
|
||||||
|
|
||||||
export let generateStaticParams:
|
export let generateStaticParams:
|
||||||
(() => Promise<{ photoId: string }[]>) | undefined = undefined;
|
(() => Promise<{ photoId: string }[]>) | undefined = undefined;
|
||||||
@ -35,8 +36,18 @@ export async function GET(
|
|||||||
|
|
||||||
const { width, height } = IMAGE_OG_DIMENSION;
|
const { width, height } = IMAGE_OG_DIMENSION;
|
||||||
|
|
||||||
|
// Make sure next/image can be reached from absolute urls,
|
||||||
|
// which may not exist on first pre-render
|
||||||
|
const isNextImageReady = await isNextImageReadyBasedOnPhotos([photo]);
|
||||||
|
|
||||||
return new ImageResponse(
|
return new ImageResponse(
|
||||||
<PhotoImageResponse {...{ photo, width, height, fontFamily }} />,
|
<PhotoImageResponse {...{
|
||||||
|
photo,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fontFamily,
|
||||||
|
isNextImageReady,
|
||||||
|
}} />,
|
||||||
{ width, height, fonts, headers },
|
{ width, height, fonts, headers },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,11 +12,13 @@ export default function PhotoImageResponse({
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
fontFamily,
|
fontFamily,
|
||||||
|
isNextImageReady = true,
|
||||||
}: {
|
}: {
|
||||||
photo: Photo
|
photo: Photo
|
||||||
width: NextImageSize
|
width: NextImageSize
|
||||||
height: number
|
height: number
|
||||||
fontFamily: string
|
fontFamily: string
|
||||||
|
isNextImageReady: boolean
|
||||||
}) {
|
}) {
|
||||||
const model = photo.model
|
const model = photo.model
|
||||||
? formatCameraModelTextShort(cameraFromPhoto(photo))
|
? formatCameraModelTextShort(cameraFromPhoto(photo))
|
||||||
@ -25,7 +27,7 @@ export default function PhotoImageResponse({
|
|||||||
return (
|
return (
|
||||||
<ImageContainer {...{ width, height }}>
|
<ImageContainer {...{ width, height }}>
|
||||||
<ImagePhotoGrid {...{
|
<ImagePhotoGrid {...{
|
||||||
photos: [photo],
|
photos: isNextImageReady ? [photo] : [],
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
...OG_TEXT_BOTTOM_ALIGNMENT && { imagePosition: 'top' },
|
...OG_TEXT_BOTTOM_ALIGNMENT && { imagePosition: 'top' },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user