Skip to content

Commit

Permalink
Add opengraph and twitter image
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcginnes committed Jan 31, 2024
1 parent cadeb31 commit 89dfc21
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Binary file added src/app/NunitoSans_10pt-Black.ttf
Binary file not shown.
Binary file added src/app/NunitoSans_10pt-Medium.ttf
Binary file not shown.
71 changes: 71 additions & 0 deletions src/app/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ImageResponse } from "next/og"

// Route segment config
export const runtime = "edge"

// Image metadata
export const alt = "Kris McGinnes Portfolio"
export const size = {
width: 1200,
height: 630,
}

export const contentType = "image/png"

// Image generation
export default async function Image() {
// Font
const nunitoMedium = fetch(
new URL("./NunitoSans_10pt-Medium.ttf", import.meta.url),
).then((res) => res.arrayBuffer())

const nunitoBlack = fetch(
new URL("./NunitoSans_10pt-Black.ttf", import.meta.url),
).then((res) => res.arrayBuffer())

return new ImageResponse(
(
// ImageResponse JSX element
<div
style={{
background: "#18181b",
color: "#fafafa",
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
gap: "0.5rem",
alignItems: "center",
justifyContent: "center",
}}
>
<div style={{ color: "#fafafa", fontWeight: 900, fontSize: 128 }}>
Kris McGinnes
</div>
<div style={{ color: "#bbf7d0", fontSize: 72, fontWeight: 500 }}>
Engineer & Designer
</div>
</div>
),
// ImageResponse options
{
// For convenience, we can re-use the exported opengraph-image
// size config to also set the ImageResponse's width and height.
...size,
fonts: [
{
name: "NunitoSans",
data: await nunitoMedium,
style: "normal",
weight: 500,
},
{
name: "NunitoSans",
data: await nunitoBlack,
style: "normal",
weight: 900,
},
],
},
)
}

0 comments on commit 89dfc21

Please sign in to comment.