import type { APIRoute, GetStaticPaths, GetStaticPathsItem, InferGetStaticPropsType, } from "astro"; import { html } from "satori-html"; import { getAllPages, getAllPosts, getSettings, invariant } from "../../../api"; import satoriOG from "../satori"; export const getStaticPaths: GetStaticPaths = async () => { const result: GetStaticPathsItem[] = []; const [posts, pages, settings] = await Promise.all([ getAllPosts(), await getAllPages(), await getSettings(), ]); const allPosts = [...posts, ...pages]; invariant(settings, "Settings are required"); allPosts.map((allPosts) => { result.push({ params: { slug: allPosts.slug }, props: { title: allPosts.title, image: allPosts.feature_image, }, }); }); return result; }; export type Props = InferGetStaticPropsType; export const GET: APIRoute = async ({ props, site }) => { const settings = await getSettings(); invariant(settings, "Settings are required"); const fontFile = await fetch( "https://og-playground.vercel.app/inter-latin-ext-700-normal.woff", ); const fontData: ArrayBuffer = await fontFile.arrayBuffer(); return await satoriOG({ template: html`
${ settings.title } - Authors
${site}
`, width: 1920, height: 1080, }).toResponse({ satori: { fonts: [ { name: "Inter Latin", data: fontData, style: "normal", }, ], }, }); };