Skip to content

Commit 2d9db0b

Browse files
committed
better opengraph images
1 parent a21c195 commit 2d9db0b

6 files changed

Lines changed: 44 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- name: Prepare assets
4545
run: |
4646
wget https://raw.githubusercontent.com/adrienverge/copr-some-nice-fonts/590400b0e1426d7b10bdda48ab565d3d2b144f5e/Verdana.ttf -O quartz/redistless/Verdana.ttf
47+
wget https://raw.githubusercontent.com/ueaner/fonts/8c1bccdc1622a2538c35abbd004ce367a949f642/Menlo-Regular.ttf -O quartz/redistless/Menlo.ttf
4748
4849
- name: Build Quartz
4950
run: npx quartz build

Menlo-Regular.ttf

464 KB
Binary file not shown.

quartz/plugins/transformers/frontmatter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ declare module "vfile" {
147147
cssclasses: string[]
148148
socialImage: string
149149
comments: boolean | string
150+
headers: {[title: string]: string[]}
150151
}>
151152
}
152153
}

quartz/redistless/Menlo.ttf

464 KB
Binary file not shown.

quartz/redistless/Verdana.ttf

168 KB
Binary file not shown.

quartz/util/og.tsx

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function getSatoriFonts(headerFont: FontSpecification, bodyFont: Fo
3636
name: headerFontName,
3737
data,
3838
weight,
39-
style: "normal" as const,
39+
style: "normal",
4040
}
4141
})
4242

@@ -47,10 +47,17 @@ export async function getSatoriFonts(headerFont: FontSpecification, bodyFont: Fo
4747
name: bodyFontName,
4848
data,
4949
weight,
50-
style: "normal" as const,
50+
style: "normal",
5151
}
5252
})
5353

54+
const data = await fetchTtf("Menlo", 600)
55+
if(data) {
56+
bodyFontPromises.push(new Promise((resolve) => {
57+
resolve({name: "Menlo", data: data, weight: 600, style: "monospace"})
58+
}))
59+
}
60+
5461
const [headerFonts, bodyFonts] = await Promise.all([
5562
Promise.all(headerFontPromises),
5663
Promise.all(bodyFontPromises),
@@ -78,6 +85,9 @@ export async function fetchTtf(
7885
if(rawFontName === "Verdana") {
7986
return await fs.readFile(path.join("quartz", "redistless", "Verdana.ttf"))
8087
}
88+
if(rawFontName === "Menlo") {
89+
return await fs.readFile(path.join("quartz", "redistless", "Menlo.ttf"))
90+
}
8191

8292
const fontName = rawFontName.replaceAll(" ", "+")
8393
const cacheKey = `${fontName}-${weight}`
@@ -201,6 +211,14 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ({
201211
const bodyFont = getFontSpecificationName(cfg.theme.typography.body)
202212
const headerFont = getFontSpecificationName(cfg.theme.typography.header)
203213

214+
let hasRichBody = false;
215+
216+
if(fileData.frontmatter?.headers) {
217+
const keys = Object.keys(fileData.frontmatter.headers)
218+
if(keys.length > 0) hasRichBody = true;
219+
}
220+
221+
204222
return (
205223
<div
206224
style={{
@@ -267,7 +285,7 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ({
267285
textOverflow: "ellipsis",
268286
}}
269287
>
270-
{title}
288+
{fileData.frontmatter?.title} | DM Ref
271289
</h1>
272290
</div>
273291

@@ -291,7 +309,27 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ({
291309
textOverflow: "ellipsis",
292310
}}
293311
>
294-
{description}
312+
<div style={{
313+
display: "flex",
314+
flexDirection: "column",
315+
}}>
316+
{hasRichBody ? Object.keys(fileData.frontmatter?.headers!).slice(0, 3).map((header) => (
317+
<div key={header} style={{
318+
display: "flex",
319+
flexDirection: "row",
320+
flex: 1
321+
}}>
322+
<p style={{textDecoration: "underline", fontWeight: "bold"}}>
323+
{header}:
324+
</p>
325+
{fileData.frontmatter?.headers ? (
326+
<p style={{marginLeft: "10px", fontFamily: header === "Format" ? "Menlo" : bodyFont}}>
327+
{fileData.frontmatter.headers[header][0]?.slice(0, 55)}{fileData.frontmatter.headers[header][0]?.length > 55 ? "..." : ""}{fileData.frontmatter?.headers[header].length > 1 ? " +" : "" }
328+
</p>
329+
) : ""}
330+
</div>
331+
)) : description}
332+
</div>
295333
</p>
296334
</div>
297335

0 commit comments

Comments
 (0)