Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export async function GET(req: NextRequest) {

// biome-ignore lint/suspicious/noConsole: we want to log here
console.log(`serving icon for ${context.site.id}`);
const response = await serveIcon(context, req);
// biome-ignore lint/suspicious/noConsole: we want to log here
console.log(`served icon for ${context.site.id}`);
return response;
return await serveIcon(context, req);
} catch (err) {
// biome-ignore lint/suspicious/noConsole: we want to log here
console.log(`serveIcon error: ${err}`, (err as Error).stack);
Expand Down
14 changes: 10 additions & 4 deletions packages/gitbook/src/routes/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ export async function serveIcon(context: GitBookSiteContext, req: Request) {
const contentTitle = site.title;

// Load the font locally to prevent the shared instance used by ImageResponse.
const font = await fetch(new URL('../fonts/Inter/Inter-Regular.ttf', import.meta.url)).then(
(res) => res.arrayBuffer()
);
const fontOrigin = await fetch(
new URL('../fonts/Inter/Inter-Regular.ttf', import.meta.url)
).then((res) => res.arrayBuffer());
const dst = new ArrayBuffer(fontOrigin.byteLength);
new Uint8Array(dst).set(new Uint8Array(fontOrigin));

if (dst.detached) {
console.log('about to use detached font buffer..');
}

return new ImageResponse(
<div
Expand Down Expand Up @@ -86,7 +92,7 @@ export async function serveIcon(context: GitBookSiteContext, req: Request) {
height: size.height,
fonts: [
{
data: font,
data: dst,
name: 'Inter',
weight: 400,
style: 'normal',
Expand Down
Loading