Skip to content

Commit

Permalink
feat: og image routes
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqmanuja authored and satnaing committed Sep 21, 2023
1 parent 0f82206 commit a83c871
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pages/og.png.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { APIRoute } from "astro";
import { generateOgImageForSite } from "@utils/generateOgImages";

export const GET: APIRoute = async () =>
new Response(await generateOgImageForSite(), {
headers: { "Content-Type": "image/png" },
});
20 changes: 20 additions & 0 deletions src/pages/posts/[slug]/index.png.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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" },
});

0 comments on commit a83c871

Please sign in to comment.