mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:01:42 +08:00
fix: add an option to disable dynamic OG image generation (#476)
* fix: add an option to disable dynamic OG image generation Add new `dynamicOgImage` option in the `SITE` object inside `src/config.ts` file to disable auto og-image generation during build. Resolves #428 * docs: update guides for `SITE.dynamicOgImage` option
This commit is contained in:
@@ -2,8 +2,13 @@ import type { APIRoute } from "astro";
|
||||
import { getCollection, type CollectionEntry } from "astro:content";
|
||||
import { generateOgImageForPost } from "@/utils/generateOgImages";
|
||||
import { slugifyStr } from "@/utils/slugify";
|
||||
import { SITE } from "@/config";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
if (!SITE.dynamicOgImage) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const posts = await getCollection("blog").then(p =>
|
||||
p.filter(({ data }) => !data.draft && !data.ogImage)
|
||||
);
|
||||
@@ -14,7 +19,18 @@ export async function getStaticPaths() {
|
||||
}));
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async ({ props }) =>
|
||||
new Response(await generateOgImageForPost(props as CollectionEntry<"blog">), {
|
||||
headers: { "Content-Type": "image/png" },
|
||||
});
|
||||
export const GET: APIRoute = async ({ props }) => {
|
||||
if (!SITE.dynamicOgImage) {
|
||||
return new Response(null, {
|
||||
status: 404,
|
||||
statusText: "Not found",
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(
|
||||
await generateOgImageForPost(props as CollectionEntry<"blog">),
|
||||
{
|
||||
headers: { "Content-Type": "image/png" },
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user