1+ import { readFile } from 'node:fs/promises' ;
2+ import { join } from 'node:path' ;
13import { ImageResponse } from 'next/og' ;
2- import { NextRequest } from 'next/server' ;
4+ import type { NextRequest } from 'next/server' ;
35import { SITE_NAME } from '@/site/config/site' ;
46
5- export const runtime = 'edge' ;
7+ export const runtime = 'nodejs' ;
8+
9+ const fontPath = join ( process . cwd ( ) , 'app' , 'api' , 'og' , 'Pretendard-Bold.ttf' ) ;
10+ let fontDataPromise : Promise < ArrayBuffer > | null = null ;
11+
12+ function loadFontData ( ) : Promise < ArrayBuffer > {
13+ if ( ! fontDataPromise ) {
14+ fontDataPromise = readFile ( fontPath ) . then (
15+ ( font ) =>
16+ font . buffer . slice (
17+ font . byteOffset ,
18+ font . byteOffset + font . byteLength
19+ ) as ArrayBuffer
20+ ) ;
21+ }
22+
23+ return fontDataPromise ;
24+ }
625
726export async function GET ( req : NextRequest ) {
827 const { searchParams } = new URL ( req . url ) ;
928 const title = searchParams . get ( 'title' ) || SITE_NAME ;
1029 const date = searchParams . get ( 'date' ) ;
1130 const tags = searchParams . get ( 'tags' ) ?. split ( ',' ) || [ ] ;
1231
13- // Load Noto Sans KR for consistent rendering across environments
14- // Using a Google Fonts raw file as a reliable source
15- const fontData = await fetch (
16- new URL (
17- 'https://github.com/google/fonts/raw/main/ofl/notosanskr/NotoSansKR-Bold.otf' ,
18- import . meta. url
19- )
20- ) . then ( ( res ) => res . arrayBuffer ( ) ) ;
32+ const fontData = await loadFontData ( ) ;
2133
2234 return new ImageResponse (
2335 < div
@@ -37,7 +49,7 @@ export async function GET(req: NextRequest) {
3749 display : 'flex' ,
3850 flexDirection : 'column' ,
3951 gap : '20px' ,
40- fontFamily : '"Noto Sans KR" ' ,
52+ fontFamily : 'Pretendard ' ,
4153 } }
4254 >
4355 { date && (
@@ -73,6 +85,7 @@ export async function GET(req: NextRequest) {
7385 < div
7486 key = { tag }
7587 style = { {
88+ display : 'flex' ,
7689 backgroundColor : 'rgba(49, 130, 246, 0.1)' ,
7790 color : '#3182f6' ,
7891 padding : '8px 24px' ,
@@ -102,7 +115,7 @@ export async function GET(req: NextRequest) {
102115 fontSize : '32px' ,
103116 fontWeight : 700 ,
104117 color : '#3182f6' ,
105- fontFamily : '"Noto Sans KR" ' ,
118+ fontFamily : 'Pretendard ' ,
106119 } }
107120 >
108121 { SITE_NAME }
@@ -114,7 +127,7 @@ export async function GET(req: NextRequest) {
114127 height : 630 ,
115128 fonts : [
116129 {
117- name : 'Noto Sans KR ' ,
130+ name : 'Pretendard ' ,
118131 data : fontData ,
119132 style : 'normal' ,
120133 weight : 700 ,
0 commit comments