main
 1import { getCollection } from "astro:content";
 2import type { APIRoute, GetStaticPaths, InferGetStaticPropsType } from "astro";
 3import { renderTypstToPdf } from "@/utils/render-typst";
 4
 5export const getStaticPaths = (async () => {
 6  const entries = await getCollection("posts");
 7  return entries.map((entry) => ({
 8    params: {
 9      slug: entry.id,
10    },
11    props: { entry },
12  }));
13}) satisfies GetStaticPaths;
14
15type Props = InferGetStaticPropsType<typeof getStaticPaths>;
16
17export const GET: APIRoute = async ({ props }) => {
18  const entry = (props as Props).entry;
19  const filePath = entry.filePath;
20  if (typeof filePath !== "string") {
21    return new Response("Not found", { status: 404 });
22  }
23  const pdfBuffer = renderTypstToPdf(filePath);
24
25  return new Response(pdfBuffer as Buffer<ArrayBuffer>, {
26    headers: {
27      "Content-Type": "application/pdf",
28    },
29  });
30};