Skip to content

Commit

Permalink
Remove custom font from og image
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeceHumphreys committed Feb 29, 2024
1 parent b4b636e commit a9372a9
Showing 1 changed file with 4 additions and 55 deletions.
59 changes: 4 additions & 55 deletions app/api/og/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getBreadcrumbs } from 'lib/breadcrumbs';

export async function GET(request: NextRequest) {
try {
const fonts = await getFonts();
const { searchParams } = new URL(request.url);
const hostname = request.headers.get('host');

Expand All @@ -26,7 +25,7 @@ export async function GET(request: NextRequest) {
const image =
path === '/'
? homeImage(hostname)
: pageImage(hostname, breadcrumbs, title, description, fonts);
: pageImage(hostname, breadcrumbs, title, description);

return image;
} catch (e: any) {
Expand Down Expand Up @@ -65,8 +64,7 @@ const pageImage = (
hostname: string | null,
breadcrumbs: string[],
title: string | undefined,
description: string | undefined,
fonts: { name: string; data: ArrayBuffer; style: string; weight: number }[]
description: string | undefined
) => {
return new ImageResponse(
(
Expand Down Expand Up @@ -104,14 +102,13 @@ const pageImage = (
>
{renderBreadcrumb(breadcrumbs)}
</ol>

<h1
style={{
fontSize: '78px',
fontWeight: '700',
fontWeight: 700,
lineHeight: '80px',
marginTop: '4px',
marginLeft: '-4px'
marginLeft: '-6px'
}}
>
{title}
Expand All @@ -132,60 +129,12 @@ const pageImage = (
),
{
// @ts-ignore - The FontOptions type cannot be imported
fonts: fonts,
width: 1200,
height: 630
}
);
};

// Utility functions
async function getFonts() {
// See https://github.com/vercel/next.js/issues/48081 for why this is necessary
const [interRegular, interMedium, interSemiBold, interBold] =
await Promise.all([
fetch(`https://rsms.me/inter/font-files/Inter-Regular.woff`).then((res) =>
res.arrayBuffer()
),
fetch(`https://rsms.me/inter/font-files/Inter-Medium.woff`).then((res) =>
res.arrayBuffer()
),
fetch(`https://rsms.me/inter/font-files/Inter-SemiBold.woff`).then(
(res) => res.arrayBuffer()
),
fetch(`https://rsms.me/inter/font-files/Inter-Bold.woff`).then((res) =>
res.arrayBuffer()
)
]);

return [
{
name: 'Inter',
data: interRegular,
style: 'normal',
weight: 400
},
{
name: 'Inter',
data: interMedium,
style: 'normal',
weight: 500
},
{
name: 'Inter',
data: interSemiBold,
style: 'normal',
weight: 600
},
{
name: 'Inter',
data: interBold,
style: 'normal',
weight: 700
}
];
}

// Utility function for getting URL parameters
const getUrlParam = (searchParams: URLSearchParams, key: string) =>
searchParams.has(key) ? searchParams.get(key)?.slice(0, 100) : '';
Expand Down

0 comments on commit a9372a9

Please sign in to comment.