Skip to content

Commit

Permalink
refactor(seo): common open graph image dimensions constant
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 10, 2024
1 parent b74e7e3 commit 5783740
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/app/api/openGraphImage/route.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ImageResponse } from "next/og";
import { NextRequest } from "next/server";
import OpenGraphImage from "./OpenGraphImage";
import { OPEN_GRAPH_IMAGE_DIMENSIONS } from "../../../utils/seo";

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
Expand All @@ -9,8 +10,8 @@ export async function GET(request: NextRequest) {
return new ImageResponse(
<OpenGraphImage title={title} description={description ?? undefined} />,
{
width: 1200,
height: 630,
width: OPEN_GRAPH_IMAGE_DIMENSIONS.width,
height: OPEN_GRAPH_IMAGE_DIMENSIONS.height,
},
);
}
9 changes: 7 additions & 2 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type CompanyInfo = {
defaultSEO: SeoData;
};

export const OPEN_GRAPH_IMAGE_DIMENSIONS = {
width: 1200,
height: 630,
};

export async function fetchSeoData(
query: string,
variables?: any,
Expand Down Expand Up @@ -102,8 +107,8 @@ export async function generateMetadataFromSeo(
})}`;
const sanityImageUrl = seo?.imageUrl || companyInfo?.defaultSEO?.imageUrl;
const sanityImageParams = `?${new URLSearchParams({
w: "1200",
h: "630",
w: OPEN_GRAPH_IMAGE_DIMENSIONS.width.toString(),
h: OPEN_GRAPH_IMAGE_DIMENSIONS.height.toString(),
fit: "fill",
fm: "png", // required for transparent
bg: "00000000", // transparent
Expand Down

0 comments on commit 5783740

Please sign in to comment.