-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d756c28
commit 03810d9
Showing
7 changed files
with
91 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* eslint-disable @next/next/no-img-element */ | ||
import { ImageResponse } from 'next/server' | ||
|
||
export const runtime = 'edge' | ||
|
||
export async function GET(request: Request) { | ||
const imageData = (await fetch( | ||
new URL('../../../public/images/social-card-template.jpg', import.meta.url) | ||
).then((res) => res.arrayBuffer())) as string | ||
|
||
try { | ||
const { searchParams } = new URL(request.url) | ||
|
||
const title = searchParams.get('title') ?? 'No post title' | ||
|
||
return new ImageResponse( | ||
( | ||
<div tw="absolute inset-0 flex flex-col"> | ||
<img | ||
src={imageData} | ||
alt="" | ||
tw="flex-1 w-full h-full" | ||
style={{ objectFit: 'cover', objectPosition: 'center' }} | ||
/> | ||
<div tw="absolute flex flex-col items-start justify-start w-full px-10 py-10 sm:justify-between"> | ||
<div tw="flex items-start justify-start w-full"> | ||
<div tw="text-white text-7xl font-bold">{title}</div> | ||
</div> | ||
</div> | ||
</div> | ||
), | ||
{ | ||
width: 1200, | ||
height: 630, | ||
} | ||
) | ||
} catch (e: any) { | ||
console.log(`${e.message}`) | ||
return new Response(`Failed to generate the image`, { | ||
status: 500, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.