feat: generate dynamic og image for blog posts (#15)

* feat: add dynamic og image using satori
* feat: add og card styling
* feat: add dynamic paths for ogTitle
* feat: add default og url
* ci: change config site url for testing purpose
* fix: update original auto-generate og image style
* refactor: move ogImage jsx inside generateOgImage
* fix: add conditions for filtering draft posts & ogImages
* build: update minor and major dependency updates
* build: update site option in config file
This commit is contained in:
Sat Naing
2022-12-28 09:09:57 +06:30
committed by GitHub
parent f115e1f31d
commit ce3f1dc4a0
5 changed files with 554 additions and 208 deletions
+24
View File
@@ -0,0 +1,24 @@
import type { APIRoute, MarkdownInstance } from "astro";
import generateOgImage from "@utils/generateOgImage";
import type { Frontmatter } from "@types";
export const get: APIRoute = async ({ params }) => ({
body: await generateOgImage(params.ogTitle),
});
const postImportResult = import.meta.glob<MarkdownInstance<Frontmatter>>(
"../contents/**/**/*.md",
{
eager: true,
}
);
const posts = Object.values(postImportResult);
export function getStaticPaths() {
return posts
.filter(({ frontmatter }) => !frontmatter.draft)
.filter(({ frontmatter }) => !frontmatter.ogImage)
.map(({ frontmatter }) => ({
params: { ogTitle: frontmatter.title },
}));
}