From 3173d185ed264cc542c1836ea3d06812f0d01dca Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Thu, 13 Mar 2025 10:17:19 -0700 Subject: [PATCH] make og images look nice --- quartz/util/og.tsx | 165 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 127 insertions(+), 38 deletions(-) diff --git a/quartz/util/og.tsx b/quartz/util/og.tsx index 683f71bd1..c8ad663b9 100644 --- a/quartz/util/og.tsx +++ b/quartz/util/og.tsx @@ -6,6 +6,8 @@ import { JSXInternal } from "preact/src/jsx" import { FontSpecification, ThemeKey } from "./theme" import path from "path" import { QUARTZ } from "./path" +import { formatDate } from "../components/Date" +import { getDate } from "../components/Date" const defaultHeaderWeight = [700] const defaultBodyWeight = [400] @@ -173,71 +175,92 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ( fonts: SatoriOptions["fonts"], fileData: QuartzPluginData, ) => { - const fontBreakPoint = 22 + const fontBreakPoint = 32 const useSmallerFont = title.length > fontBreakPoint const iconPath = `https://${cfg.baseUrl}/static/icon.png` + // Format date if available + const rawDate = getDate(cfg, fileData) + const date = rawDate ? formatDate(rawDate, cfg.locale) : null + + // Get tags if available + const tags = fileData.frontmatter?.tags ?? [] + return (
+ {/* Header Section */}
+
- -
-
-

- {title} -

+ {cfg.baseUrl}
+ + {/* Title Section */}
+

+ {title} +

+
+ + {/* Description Section */} +

{description}

+ + {/* Footer with Metadata */} +
+ {/* Left side - Date */} +
+ {date && ( +
+ + + + + + + {date} +
+ )} +
+ + {/* Right side - Tags */} +
+ {tags.slice(0, 3).map((tag: string) => ( +
+ #{tag} +
+ ))} +
+
) }