feat(og-image): add config option to use default og image for root path

This commit is contained in:
Ben Schlegel 2024-11-10 11:17:33 +01:00
parent 07aa615138
commit 12c99a5673
No known key found for this signature in database
GPG Key ID: 8BDB8891C1575E22
2 changed files with 12 additions and 0 deletions

View File

@ -45,6 +45,7 @@ const defaultOptions: SocialImageOptions = {
width: 1200, width: 1200,
height: 630, height: 630,
imageStructure: defaultImage, imageStructure: defaultImage,
excludeRoot: false,
} }
export default (() => { export default (() => {
@ -145,6 +146,13 @@ export default (() => {
fileData.frontmatter?.socialImage ?? fileData.frontmatter?.socialImage ??
fileData.frontmatter?.image ?? fileData.frontmatter?.image ??
fileData.frontmatter?.cover fileData.frontmatter?.cover
// Override with default og image if config option is set
if (fileData.slug === "index") {
ogImagePath = ogImageDefaultPath
}
// Override with frontmatter url if existing
if (frontmatterImgUrl) { if (frontmatterImgUrl) {
ogImagePath = `https://${cfg.baseUrl}/static/${frontmatterImgUrl}` ogImagePath = `https://${cfg.baseUrl}/static/${frontmatterImgUrl}`
} }

View File

@ -64,6 +64,10 @@ export type SocialImageOptions = {
* Width to generate image with in pixels (should be around 1200px) * Width to generate image with in pixels (should be around 1200px)
*/ */
width: number width: number
/**
* Wether to use the auto generated image for the root path ("/", when set to false) or the default og image (when set to true).
*/
excludeRoot: boolean
/** /**
* JSX to use for generating image. See satori docs for more info (https://github.com/vercel/satori) * JSX to use for generating image. See satori docs for more info (https://github.com/vercel/satori)
* @param cfg global quartz config * @param cfg global quartz config