From 3c038677d67cc66cbb80442bd2c5b4a61e8f43bb Mon Sep 17 00:00:00 2001 From: Ben Schlegel Date: Sat, 23 Sep 2023 14:56:33 +0200 Subject: [PATCH] feat: support custom og images via frontmatter --- quartz/components/Head.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/quartz/components/Head.tsx b/quartz/components/Head.tsx index 48bb0c84c..deda84745 100644 --- a/quartz/components/Head.tsx +++ b/quartz/components/Head.tsx @@ -129,7 +129,12 @@ export default (() => { const slug = fileData.filePath const filePath = slug?.replaceAll("/", "-") const title = fileData.frontmatter?.title ?? "Untitled" - const description = fileData.description?.trim() ?? "No description provided" + + // Get file description (priority: frontmatter > fileData > default) + let description = fileData.description?.trim() ?? "No description provided" + if (fileData.frontmatter?.socialDescription) { + description = fileData.frontmatter.socialDescription + } if (cfg.generateSocialImages) { // Generate folders for social images (if they dont exist yet) @@ -158,7 +163,13 @@ export default (() => { // Use default og image if filePath doesnt exist (for autogenerated paths with no .md file) const useDefaultOgImage = filePath === undefined || !cfg.generateSocialImages - const ogImagePath = useDefaultOgImage ? ogImageDefaultPath : ogImageGeneratedPath + // Path to og/social image (priority: frontmatter > generated image (if enabled) > default image) + let ogImagePath = useDefaultOgImage ? ogImageDefaultPath : ogImageGeneratedPath + + const frontmatterImgUrl = fileData.frontmatter?.socialImageUrl + if (frontmatterImgUrl) { + ogImagePath = `https://${cfg.baseUrl}/static/${frontmatterImgUrl}` + } return ( @@ -174,7 +185,7 @@ export default (() => { - +