import { config } from "../config"; import { html } from "satori-html"; import { resources } from "./ogResources"; import { Resvg } from "@resvg/resvg-js"; import dayjs from "dayjs"; import satori from "satori"; export async function createOgImage(title: string, datePublished: Date): Promise { const formattedDate = dayjs(datePublished).format("MMMM DD, YYYY"); const markup = await satori( html(` ${formattedDate} ${title} ${config.og.website.toLocaleUpperCase()} ${config.author.name} ${config.author.email} `), { width: config.og.dimensions.width, height: config.og.dimensions.height, fonts: [ { name: "Inter", data: resources.fonts.regular, weight: 400, }, { name: "Inter", data: resources.fonts.bold, weight: 700, }, ], } ); const image = new Resvg(markup, { fitTo: { mode: "width", value: config.og.dimensions.width } }); return image.render().asPng(); }