-
Notifications
You must be signed in to change notification settings - Fork 0
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
478f9dc
commit 561453c
Showing
2 changed files
with
100 additions
and
2 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,90 @@ | ||
import { allDocuments } from "@/contentlayer/generated"; | ||
import { ImageResponse } from "next/og"; | ||
|
||
export const size = { | ||
width: 1200, | ||
height: 630, | ||
}; | ||
|
||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { slug: string[] } } | ||
) { | ||
const { slug } = params; | ||
const target = allDocuments.find((docs) => { | ||
return slug.join("/") === docs._raw.sourceFileDir; | ||
}); | ||
|
||
const font = fetch( | ||
new URL( | ||
"https://fastly.jsdelivr.net/gh/Project-Noonnu/[email protected]/Pretendard-Bold.woff" | ||
) | ||
).then((res) => res.arrayBuffer()); | ||
|
||
return new ImageResponse( | ||
( | ||
<> | ||
{ | ||
// ImageResponse JSX element | ||
} | ||
<div | ||
style={{ | ||
height: "640px", | ||
width: "1200px", | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
backgroundColor: "#fff", | ||
fontSize: 32, | ||
}} | ||
> | ||
<svg | ||
width="75" | ||
viewBox="0 0 75 65" | ||
fill="#000" | ||
style={{ margin: "0 75px" }} | ||
> | ||
<path d="M37.59.25l36.95 64H.64l36.95-64z"></path> | ||
</svg> | ||
<div | ||
style={{ | ||
fontSize: 48, | ||
marginTop: 40, | ||
}} | ||
> | ||
{target?.title} | ||
</div> | ||
<div | ||
style={{ | ||
marginTop: 40, | ||
}} | ||
> | ||
{target?.description} | ||
</div> | ||
</div> | ||
</> | ||
), | ||
{ | ||
...size, | ||
fonts: [ | ||
{ | ||
name: "Pretendard", | ||
data: await font, | ||
style: "normal", | ||
}, | ||
], | ||
} | ||
); | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const docs = allDocuments; | ||
|
||
return docs.map((doc) => { | ||
const path = doc._raw.sourceFileDir; | ||
return { | ||
slug: path.split("/"), | ||
}; | ||
}); | ||
} |