@@ -31,18 +31,19 @@ Copy and paste the following code into your project.
3131``` tsx title="app/api/og/route.tsx"
3232import { ImageResponse } from ' next/og'
3333
34+ import { OpenGraph } from ' @/components/ui/open-graph'
3435import { appName } from ' @/lib/shared'
35- import { OpenGraph } from ' @/registry/ui/open-graph'
3636
3737export const revalidate = false
3838
39- export async function GET(req : Request ) {
39+ export async function GET(req : Request , _ : RouteContext < ' /api/og ' > ) {
4040 const url = new URL (req .url )
4141
42- const { searchParams } = url
43- const title = searchParams .get (' title' ) ?? ' Default Title'
44- const description = searchParams .get (' description' ) ?? ' Default Description'
45- const image = searchParams .get (' image' ) ?? undefined
42+ const title = url .searchParams .get (' title' ) ?? ' '
43+ const description = url .searchParams .get (' description' ) ?? ' '
44+ let image = url .searchParams .get (' image' ) ?? ' '
45+ if (image && ! image .startsWith (' http' ))
46+ image = new URL (image , req .url ).toString ()
4647
4748 const logoUrl = new URL (' /icon-512.png' , req .url ).toString ()
4849
@@ -52,7 +53,6 @@ export async function GET(req: Request) {
5253 title = { title }
5354 description = { description }
5455 image = { image }
55- // oxlint-disable-next-line jsx-a11y/alt-text, next/no-img-element
5656 logo = { <img src = { logoUrl } width = { 56 } height = { 56 } />}
5757 caption = { url .hostname }
5858 />,
0 commit comments