fix(og-image): overflow ellipses in title and description

This commit is contained in:
Jacky Zhao 2025-03-05 17:13:19 -08:00
parent f6f417a505
commit 2acfa0fa23
3 changed files with 38 additions and 17 deletions

View file

@ -19,7 +19,7 @@ const config: QuartzConfig = {
baseUrl: "quartz.jzhao.xyz", baseUrl: "quartz.jzhao.xyz",
ignorePatterns: ["private", "templates", ".obsidian"], ignorePatterns: ["private", "templates", ".obsidian"],
defaultDateType: "created", defaultDateType: "created",
generateSocialImages: false, generateSocialImages: true,
theme: { theme: {
fontOrigin: "googleFonts", fontOrigin: "googleFonts",
cdnCaching: true, cdnCaching: true,

View file

@ -98,7 +98,7 @@ export default (() => {
if (fileName) { if (fileName) {
// Generate social image (happens async) // Generate social image (happens async)
generateSocialImage( void generateSocialImage(
{ {
title, title,
description, description,

View file

@ -143,12 +143,10 @@ export const defaultImage: SocialImageOptions["imageStructure"] = (
fonts: SatoriOptions["fonts"], fonts: SatoriOptions["fonts"],
_fileData: QuartzPluginData, _fileData: QuartzPluginData,
) => { ) => {
// How many characters are allowed before switching to smaller font
const fontBreakPoint = 22 const fontBreakPoint = 22
const useSmallerFont = title.length > fontBreakPoint const useSmallerFont = title.length > fontBreakPoint
// Setup to access image
const iconPath = `https://${cfg.baseUrl}/static/icon.png` const iconPath = `https://${cfg.baseUrl}/static/icon.png`
return ( return (
<div <div
style={{ style={{
@ -160,43 +158,66 @@ export const defaultImage: SocialImageOptions["imageStructure"] = (
width: "100%", width: "100%",
backgroundColor: cfg.theme.colors[colorScheme].light, backgroundColor: cfg.theme.colors[colorScheme].light,
gap: "2rem", gap: "2rem",
paddingTop: "1.5rem", padding: "1.5rem 5rem",
paddingBottom: "1.5rem",
paddingLeft: "5rem",
paddingRight: "5rem",
}} }}
> >
<div <div
style={{ style={{
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",
justifyContent: "flex-start",
width: "100%", width: "100%",
flexDirection: "row", flexDirection: "row",
gap: "2.5rem", gap: "2.5rem",
}} }}
> >
<img src={iconPath} width={135} height={135} /> <img src={iconPath} width={135} height={135} />
<p <div
style={{ style={{
display: "flex",
color: cfg.theme.colors[colorScheme].dark, color: cfg.theme.colors[colorScheme].dark,
fontSize: useSmallerFont ? 70 : 82, fontSize: useSmallerFont ? 70 : 82,
fontFamily: fonts[0].name, fontFamily: fonts[0].name,
maxWidth: "70%",
overflow: "hidden",
textOverflow: "ellipsis",
}}
>
<p
style={{
margin: 0,
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}} }}
> >
{title} {title}
</p> </p>
</div> </div>
<p </div>
<div
style={{ style={{
display: "flex",
color: cfg.theme.colors[colorScheme].dark, color: cfg.theme.colors[colorScheme].dark,
fontSize: 44, fontSize: 44,
lineClamp: 3,
fontFamily: fonts[1].name, fontFamily: fonts[1].name,
maxWidth: "100%",
maxHeight: "40%",
overflow: "hidden",
}}
>
<p
style={{
margin: 0,
display: "-webkit-box",
WebkitBoxOrient: "vertical",
WebkitLineClamp: 3,
overflow: "hidden",
textOverflow: "ellipsis",
}} }}
> >
{description} {description}
</p> </p>
</div> </div>
</div>
) )
} }