mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
21 lines
669 B
TypeScript
21 lines
669 B
TypeScript
import type { APIRoute } from "astro";
|
|
import { getCollection, type CollectionEntry } from "astro:content";
|
|
import { generateOgImageForPost } from "@utils/generateOgImages";
|
|
import { slugifyStr } from "@utils/slugify";
|
|
|
|
export async function getStaticPaths() {
|
|
const posts = await getCollection("blog").then(p =>
|
|
p.filter(({ data }) => !data.draft && !data.ogImage)
|
|
);
|
|
|
|
return posts.map(post => ({
|
|
params: { slug: slugifyStr(post.data.title) },
|
|
props: post,
|
|
}));
|
|
}
|
|
|
|
export const GET: APIRoute = async ({ props }) =>
|
|
new Response(await generateOgImageForPost(props as CollectionEntry<"blog">), {
|
|
headers: { "Content-Type": "image/png" },
|
|
});
|