mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
2f82febff4
Changes made - update font source with Google font - add error handling in font fetching logic - update docs in dynamic-og-images blog post --------- Co-authored-by: satnaing <satnaingdev@gmail.com>
21 lines
608 B
TypeScript
21 lines
608 B
TypeScript
import { Resvg } from "@resvg/resvg-js";
|
|
import { type CollectionEntry } from "astro:content";
|
|
import postOgImage from "./og-templates/post";
|
|
import siteOgImage from "./og-templates/site";
|
|
|
|
function svgBufferToPngBuffer(svg: string) {
|
|
const resvg = new Resvg(svg);
|
|
const pngData = resvg.render();
|
|
return pngData.asPng();
|
|
}
|
|
|
|
export async function generateOgImageForPost(post: CollectionEntry<"blog">) {
|
|
const svg = await postOgImage(post);
|
|
return svgBufferToPngBuffer(svg);
|
|
}
|
|
|
|
export async function generateOgImageForSite() {
|
|
const svg = await siteOgImage();
|
|
return svgBufferToPngBuffer(svg);
|
|
}
|