diff --git a/src/lib/assets/og/me.jpg b/src/lib/assets/og/me-inline.jpg similarity index 100% rename from src/lib/assets/og/me.jpg rename to src/lib/assets/og/me-inline.jpg diff --git a/src/routes/og.png/+server.ts b/src/routes/og.png/+server.ts index cabae2c..83e0878 100644 --- a/src/routes/og.png/+server.ts +++ b/src/routes/og.png/+server.ts @@ -4,32 +4,16 @@ import { html as toReactNode } from 'satori-html'; import { OgImage } from '$lib/components/site'; import GeistRegular from '$lib/assets/og/Geist-Regular.woff'; import GeistBold from '$lib/assets/og/Geist-Bold.woff'; -import imageData from '$lib/assets/og/me.jpg?base64'; -// import { readFile } from 'fs/promises'; -// import path from 'path'; +import imageData from '$lib/assets/og/me-inline.jpg'; const height = 630; const width = 1200; -// const getImageData = async () => { -// // try { -// const imagePath = path.join(process.cwd(), Me); -// const meImage = await readFile(imagePath); -// return Buffer.from(meImage).toString('base64'); -// // } catch (error) { -// // console.error('Error reading image:', error); -// // throw error; -// // } -// }; - /** @type {import('./$types').RequestHandler} */ export const GET = async ({ url }) => { - // try { const title = url.searchParams.get('title') ?? undefined; const subTitle = url.searchParams.get('subTitle') ?? undefined; - // const imageData = await getImageData(); - // eslint-disable-next-line @typescript-eslint/no-explicit-any const result = (OgImage as any).render({ title, subTitle, imageData }); const element = toReactNode(`${result.html}`); @@ -66,13 +50,4 @@ export const GET = async ({ url }) => { 'cache-control': 'public, max-age=86400, immutable' } }); - // } catch (error) { - // console.error('Error generating image:', error); - // return new Response('Internal Server Error', { - // status: 500, - // headers: { - // 'content-type': 'text/plain' - // } - // }); - // } }; diff --git a/vite.config.ts b/vite.config.ts index 56ea929..7700d0e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,12 +4,7 @@ import { defineConfig } from 'vite'; import fs from 'fs'; export default defineConfig({ - plugins: [enhancedImages(), sveltekit(), rawFonts(['.woff']), base64()], - server: { - fs: { - allow: ['./'] - } - }, + plugins: [base64(['.jpg']), enhancedImages(), rawFonts(['.woff']), sveltekit()], define: { 'import.meta.env.VERCEL_URL': JSON.stringify(process.env.VERCEL_URL) } @@ -27,18 +22,14 @@ function rawFonts(ext: string[]) { }; } -function base64() { +function base64(ext: string[]) { return { name: 'vite-plugin-base64-loader', transform(_code: string, id: string) { - const [path, query] = id.split('?'); - - if (query !== 'base64') { - return null; + if (id.includes('inline') && ext.some((e) => id.endsWith(e))) { + const base64 = fs.readFileSync(id, { encoding: 'base64' }); + return { code: `export default ${JSON.stringify(base64)}`, map: null }; } - - const base64 = fs.readFileSync(path, { encoding: 'base64' }); - return { code: `export default ${JSON.stringify(base64)}`, map: null }; } }; }