Skip to content

Commit

Permalink
Tweak og image
Browse files Browse the repository at this point in the history
  • Loading branch information
banga committed Dec 27, 2023
1 parent f69c034 commit 0bf874b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
30 changes: 18 additions & 12 deletions src/components/opengraph/BlogPostOpenGraphImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,39 @@ export function BlogPostOpenGraphImage({
<div
style={{
fontFamily: fontFamily(400),
fontSize: 24,
display: "flex",
width: "100%",
height: "100%",
flexDirection: "column",
flexWrap: "wrap",
alignItems: "center",
justifyContent: "center",
backgroundColor,
color: textColor,
padding: "50px 100px",
lineHeight: 1.5,
gap: "15px",
}}
>
<div
style={{
display: "flex",
flexDirection: "column",
margin: "60px",
lineHeight: 1.5,
flexDirection: "row",
fontFamily: fontFamily(600),
fontSize: 64,
}}
>
<div style={{ fontFamily: fontFamily(600), fontSize: 32 }}>
{post.title}
</div>
<div style={{ display: "flex", flexDirection: "row", gap: "10px" }}>
<div style={{ color: linkColor }}>{hostname}</div>
<div>{renderDate(post.createdDate)}</div>
</div>
{post.title}
</div>
<div
style={{
fontSize: 32,
display: "flex",
flexDirection: "row",
gap: "15px",
}}
>
<div style={{ color: linkColor }}>{hostname}</div>
<div>{renderDate(post.createdDate)}</div>
</div>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ async function writeBlogPostOpenGraphImagesAsync(

const imageBuffer = await generateOpenGraphImageAsync(
// Can't use context provider here because `satori` can't handle it
<BlogPostOpenGraphImage post={post} baseUrl={buildContext.baseUrl} />
<BlogPostOpenGraphImage post={post} baseUrl={buildContext.baseUrl} />,
1200,
600
);
writeFile(openGraphImageOutputPath, imageBuffer);
})
Expand Down
10 changes: 4 additions & 6 deletions src/lib/opengraph-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export function fontFamily(weight: (typeof FONT_WEIGHTS)[number]): string {
}

export async function generateOpenGraphImageAsync(
element: ReactElement
element: ReactElement,
width: number,
height: number
): Promise<Buffer> {
const svg = await satori(element, {
width: 800,
height: 400,
fonts: FONTS,
});
const svg = await satori(element, { width, height, fonts: FONTS });
const resvg = new Resvg(svg, {
fitTo: { mode: "original" },
font: { loadSystemFonts: false },
Expand Down

0 comments on commit 0bf874b

Please sign in to comment.