11import type { APIRoute } from 'astro'
22import { getCollection } from 'astro:content'
33import { generateOpenGraphImage } from 'astro-og-canvas'
4- import kevinBrownAvatar from '@assets/images/avatars/kevin-brown.webp '
4+ import { fileURLToPath } from 'node:url '
55import { buildApiErrorResponse , handleApiFunctionError } from '@pages/api/_utils/errors'
66import { createApiFunctionContext } from '@pages/api/_utils/requestContext'
77
88export const prerender = false
99
1010const ROUTE = '/api/social-card'
11+ const AVATAR_FILE_PATH = fileURLToPath (
12+ new URL ( '../../../assets/images/avatars/kevin-brown.webp' , import . meta. url )
13+ )
1114const DEFAULT_TITLE = 'Platform Engineering by Kevin Brown'
1215const DEFAULT_DESCRIPTION =
1316 'Platform engineer helping teams harden delivery, modernize cloud platforms, and improve developer experience.'
1417
15- type ImageMetadataWithFsPath = typeof kevinBrownAvatar & {
16- fsPath ?: string
17- }
18-
1918type CollectionKey = 'articles' | 'caseStudies' | 'services' | 'downloads'
2019type PaletteKey = 'articles' | 'case-studies' | 'services' | 'downloads' | 'default'
2120
@@ -60,16 +59,6 @@ const gradientPalette: Record<PaletteKey, [number, number, number][]> = {
6059 ] ,
6160}
6261
63- const getAvatarFilePath = ( ) : string => {
64- const avatarFilePath = ( kevinBrownAvatar as ImageMetadataWithFsPath ) . fsPath
65-
66- if ( ! avatarFilePath ) {
67- throw new Error ( 'Kevin Brown avatar asset is missing a local file path' )
68- }
69-
70- return avatarFilePath
71- }
72-
7362/** Normalize slug parameters to a consistent format */
7463const normalizeSlug = ( value : string | null ) : string => {
7564 if ( ! value ) return 'home'
@@ -133,7 +122,6 @@ export const GET: APIRoute = async ({ request, clientAddress, cookies }) => {
133122 const slug = normalizeSlug ( url . searchParams . get ( 'slug' ) )
134123 const titleOverride = url . searchParams . get ( 'title' )
135124 const descriptionOverride = url . searchParams . get ( 'description' )
136- const avatarPath = getAvatarFilePath ( )
137125
138126 const contentIndex = await buildContentIndex ( )
139127 const matchedEntry = contentIndex [ slug ]
@@ -153,7 +141,7 @@ export const GET: APIRoute = async ({ request, clientAddress, cookies }) => {
153141 bgGradient : gradientPalette [ palette ] ,
154142 padding : 80 ,
155143 logo : {
156- path : avatarPath ,
144+ path : AVATAR_FILE_PATH ,
157145 size : [ 140 , 140 ] ,
158146 } ,
159147 font : {
0 commit comments