Skip to content

Commit c169540

Browse files
committed
Fix OG image generation and update imports.
1 parent 3de4d59 commit c169540

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

app/api/og/[name]/route.tsx renamed to app/snippet/[slug]/opengraph-image.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
import { prisma } from "@/prisma/db";
12
import { ImageResponse } from "next/og";
23

3-
// Route segment config
4-
export const runtime = "edge";
5-
6-
export const alt = "Snippets";
4+
export const alt = "About Acme";
75
export const size = {
86
width: 1200,
97
height: 630,
108
};
119

1210
export const contentType = "image/png";
1311

14-
export async function GET(request: any) {
15-
const name = request.nextUrl.searchParams.get("name") || "Snippets";
12+
export default async function Image({ params }: { params: { slug: string } }) {
13+
const post = await prisma.snippet.findUnique({
14+
where: {
15+
id: params.slug,
16+
},
17+
select: {
18+
title: true,
19+
},
20+
});
21+
22+
const name = post?.title || "Manage your code snippets.";
1623
return new ImageResponse(
1724
(
1825
<div
@@ -72,7 +79,10 @@ export async function GET(request: any) {
7279
</div>
7380
</div>
7481
),
82+
// ImageResponse options
7583
{
84+
// For convenience, we can re-use the exported opengraph-image
85+
// size config to also set the ImageResponse's width and height.
7686
...size,
7787
}
7888
);

app/snippet/[slug]/page.tsx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,6 @@ import {
1616
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
1717
import { CalendarIcon } from "@radix-ui/react-icons";
1818

19-
export async function generateMetadata({
20-
params,
21-
}: {
22-
params: { slug: string };
23-
}) {
24-
const post = await prisma.snippet.findUnique({
25-
where: {
26-
id: params.slug,
27-
},
28-
select: {
29-
title: true,
30-
},
31-
});
32-
33-
const name = post?.title || "Manage your code snippets.";
34-
35-
return {
36-
title: name,
37-
openGraph: {
38-
images: [`/api/og/${encodeURIComponent(name)}`],
39-
},
40-
twitter: {
41-
title: name,
42-
description: "View this code snippet on Snippets.",
43-
card: "summary_large_image",
44-
creator: "@abdo_eth",
45-
},
46-
};
47-
}
48-
4919
export default async function Page({ params }: { params: { slug: string } }) {
5020
const session = await getServerSession(authOptions);
5121

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"@/*": ["./*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "app/api/og/[name]/route.tsx"],
2626
"exclude": ["node_modules"]
2727
}

0 commit comments

Comments
 (0)