Skip to content

Commit f772aae

Browse files
committed
feat(site): improve og readability
1 parent 49124de commit f772aae

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed
3.27 MB
Binary file not shown.
-12.8 KB
Loading
-34.1 KB
Loading

docs/.vitepress/plugins/satori-og.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import pLimit from "p-limit";
1111
const SIZE = { width: 1200, height: 630 };
1212
const OUT_DIR = "docs/public/og";
1313
const FONT_FILE = "docs/.vitepress/assets/FlexSansGB-Regular.ttf";
14+
const FONT_FILE_SEMIBOLD = "docs/.vitepress/assets/FlexSansGB-SemiBold.ttf";
1415
const BG_FILE = "docs/.vitepress/assets/cleanroom-og-base.jpg";
1516
const SHARP_CONCURRENCY = 4;
1617
const SATORI_CONCURRENCY = Math.max(4, os.cpus().length);
@@ -25,8 +26,10 @@ type PageMeta = {
2526
export default function SatoriOg() {
2627
const root = process.cwd();
2728
let fontData: Buffer | undefined;
29+
let fontData2: Buffer | undefined;
2830
let bgBase64: string | undefined;
2931
let fontMtime = 0;
32+
let fontMtime2 = 0;
3033
let bgMtime = 0;
3134

3235
async function ensureFont() {
@@ -39,7 +42,16 @@ export default function SatoriOg() {
3942
fontData = buf;
4043
fontMtime = st.mtimeMs;
4144
}
42-
return fontData!;
45+
if (!fontData2) {
46+
const fontPath = path.resolve(root, FONT_FILE_SEMIBOLD);
47+
const [buf, st] = await Promise.all([
48+
fs.readFile(fontPath),
49+
fs.stat(fontPath),
50+
]);
51+
fontData2 = buf;
52+
fontMtime2 = st.mtimeMs;
53+
}
54+
return [fontData!, fontData2!];
4355
}
4456

4557
async function ensureBgBase64() {
@@ -119,7 +131,10 @@ export default function SatoriOg() {
119131
}
120132

121133
async function renderSvg(meta: PageMeta) {
122-
const [bg, font] = await Promise.all([ensureBgBase64(), ensureFont()]);
134+
const [bg, [font, font2]] = await Promise.all([
135+
ensureBgBase64(),
136+
ensureFont(),
137+
]);
123138
const html = `
124139
<div style="
125140
position:relative;
@@ -128,12 +143,12 @@ export default function SatoriOg() {
128143
<img src="${bg}" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;"/>
129144
<div style="display:flex;flex-direction:column;padding:240px 64px 64px 64px;height:100%;justify-content:space-between;">
130145
<div style="display:flex;flex-direction:column;">
131-
<div style="font-size:52px;line-height:1.2;font-weight:700;max-width:1000px;">
146+
<div style="font-size:52px;line-height:1.2;font-weight:700;max-width:1000px;font-family:'Flex Sans GB SemiBold';">
132147
${escapeHtml(meta.title)}
133148
</div>
134149
${
135150
meta.description
136-
? `<div style="margin-top:24px;font-size:28px;opacity:.85;max-width:1000px;">
151+
? `<div style="margin-top:24px;font-size:28px;opacity:.90;max-width:1000px;">
137152
${escapeHtml(meta.description)}
138153
</div>`
139154
: ``
@@ -149,6 +164,12 @@ export default function SatoriOg() {
149164
height: SIZE.height,
150165
fonts: [
151166
{ name: "Flex Sans GB", data: font, weight: 400, style: "normal" },
167+
{
168+
name: "Flex Sans GB SemiBold",
169+
data: font2,
170+
weight: 600,
171+
style: "normal",
172+
},
152173
],
153174
});
154175
}

0 commit comments

Comments
 (0)