Skip to content

Commit 910252f

Browse files
author
printf("bosshudsawat.com")
committed
feat: Generate OG and Twitter images from local files and explicitly link them in metadata.
1 parent 7e3a6ee commit 910252f

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/app/layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@ export const metadata: Metadata = {
1919
siteName: "Boss Hudsawat Portfolio",
2020
title: "Boss Hudsawat - Full Stack Developer & Tech Speaker",
2121
description: "Portfolio of Boss Hudsawat, a passionate software engineer, tech speaker, and robotics enthusiast. Explore my work experience, achievements, and technical expertise.",
22+
images: [
23+
{
24+
url: "/opengraph-image",
25+
width: 1200,
26+
height: 630,
27+
alt: "Boss Hudsawat - Full Stack Developer & Tech Speaker",
28+
},
29+
],
2230
},
2331
twitter: {
2432
card: "summary_large_image",
2533
title: "Boss Hudsawat - Full Stack Developer & Tech Speaker",
2634
description: "Portfolio of Boss Hudsawat, a passionate software engineer, tech speaker, and robotics enthusiast.",
35+
images: ["/twitter-image"],
2736
creator: "@bosshudsawat", // Add your Twitter handle if you have one
2837
},
2938
icons: {

src/app/opengraph-image.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ImageResponse } from 'next/og'
2-
3-
export const runtime = 'edge'
2+
import { join } from 'node:path'
3+
import { readFileSync } from 'node:fs'
44

55
export const alt = 'Boss Hudsawat - Full Stack Developer & Tech Speaker'
66
export const contentType = 'image/png'
@@ -10,10 +10,9 @@ export const size = {
1010
}
1111

1212
export default async function Image() {
13-
// Fetch the profile image
14-
const profileImageSrc = await fetch('https://bosshudsawat.com/img/boss-3.jpg').then(
15-
(res) => res.arrayBuffer()
16-
)
13+
// Read the profile image from the filesystem
14+
const profileImageDetails = join(process.cwd(), 'public/img/boss-3.jpg')
15+
const profileImageSrc = readFileSync(profileImageDetails).buffer
1716

1817
return new ImageResponse(
1918
(

src/app/twitter-image.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ImageResponse } from 'next/og'
2-
3-
export const runtime = 'edge'
2+
import { join } from 'node:path'
3+
import { readFileSync } from 'node:fs'
44

55
export const alt = 'Boss Hudsawat - Full Stack Developer & Tech Speaker'
66
export const contentType = 'image/png'
@@ -10,10 +10,9 @@ export const size = {
1010
}
1111

1212
export default async function Image() {
13-
// Fetch the profile image
14-
const profileImageSrc = await fetch('https://bosshudsawat.com/img/boss-3.jpg').then(
15-
(res) => res.arrayBuffer()
16-
)
13+
// Read the profile image from the filesystem
14+
const profileImageDetails = join(process.cwd(), 'public/img/boss-3.jpg')
15+
const profileImageSrc = readFileSync(profileImageDetails).buffer
1716

1817
return new ImageResponse(
1918
(
@@ -153,4 +152,4 @@ export default async function Image() {
153152
...size,
154153
}
155154
)
156-
}
155+
}

0 commit comments

Comments
 (0)