From 12c99a5673afed8e206f8d69cf132631912adcc5 Mon Sep 17 00:00:00 2001 From: Ben Schlegel Date: Sun, 10 Nov 2024 11:17:33 +0100 Subject: [PATCH] feat(og-image): add config option to use default og image for root path --- quartz/components/Head.tsx | 8 ++++++++ quartz/util/imageHelper.ts | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/quartz/components/Head.tsx b/quartz/components/Head.tsx index 6c25ffbcc..5ef3f0997 100644 --- a/quartz/components/Head.tsx +++ b/quartz/components/Head.tsx @@ -45,6 +45,7 @@ const defaultOptions: SocialImageOptions = { width: 1200, height: 630, imageStructure: defaultImage, + excludeRoot: false, } export default (() => { @@ -145,6 +146,13 @@ export default (() => { fileData.frontmatter?.socialImage ?? fileData.frontmatter?.image ?? 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) { ogImagePath = `https://${cfg.baseUrl}/static/${frontmatterImgUrl}` } diff --git a/quartz/util/imageHelper.ts b/quartz/util/imageHelper.ts index 1f8272ea0..5d587fd9b 100644 --- a/quartz/util/imageHelper.ts +++ b/quartz/util/imageHelper.ts @@ -64,6 +64,10 @@ export type SocialImageOptions = { * Width to generate image with in pixels (should be around 1200px) */ 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) * @param cfg global quartz config