mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-03 12:10:34 +00:00
Try again
This commit is contained in:
@@ -206,7 +206,7 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page
|
||||
{/* Grid */}
|
||||
<img
|
||||
tw="absolute inset-0 w-[100vw] h-[100vh]"
|
||||
src={await readImage(await fetchSelf(gridAsset))}
|
||||
src={await readStaticImage(gridAsset)}
|
||||
alt="Grid"
|
||||
/>
|
||||
|
||||
@@ -323,3 +323,22 @@ async function readImage(response: Response) {
|
||||
const base64 = Buffer.from(arrayBuffer).toString('base64');
|
||||
return `data:image/${response.headers.get('content-type')};base64,${base64}`;
|
||||
}
|
||||
|
||||
const staticImagesCache = new Map<string, string>();
|
||||
|
||||
/**
|
||||
* Read a static image and cache it in memory.
|
||||
*/
|
||||
async function readStaticImage(url: string) {
|
||||
const cached = staticImagesCache.get(url);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
const response = await fetchSelf(url);
|
||||
const image = await readImage(response);
|
||||
console.log('readStaticImage', url, image);
|
||||
staticImagesCache.set(url, image);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user