fix: use publisher social image font weight

This commit is contained in:
Nancy
2026-06-25 21:30:07 -07:00
committed by Patrick Erichsen
parent 6165a99419
commit fbd5d51d64
3 changed files with 60 additions and 2 deletions
+19
View File
@@ -125,4 +125,23 @@ describe("ogAssets", () => {
]),
);
});
it("loads publisher fonts with Bricolage 700 first", async () => {
readFileMock.mockResolvedValue(Buffer.from([9, 8, 7]));
const { getPublisherFontBuffers } = await import("./ogAssets");
const first = await getPublisherFontBuffers();
const second = await getPublisherFontBuffers();
expect(first).toHaveLength(6);
expect(second).toEqual(first);
expect(readFileMock).toHaveBeenCalledTimes(6);
expect(String(readFileMock.mock.calls[0]?.[0])).toContain(
"bricolage-grotesque-latin-700-normal.woff2",
);
expect(String(readFileMock.mock.calls[1]?.[0])).toContain(
"bricolage-grotesque-latin-800-normal.woff2",
);
});
});
+39
View File
@@ -14,6 +14,7 @@ let clawHubLogoDataUrlPromise: Promise<string> | null = null;
let watermarkDataUrlPromise: Promise<string> | null = null;
let resvgWasmPromise: Promise<Uint8Array> | null = null;
let fontBuffersPromise: Promise<Uint8Array[]> | null = null;
let publisherFontBuffersPromise: Promise<Uint8Array[]> | null = null;
let resvgInitPromise: Promise<void> | null = null;
function getServerRootUrl() {
@@ -130,3 +131,41 @@ export async function getFontBuffers() {
}
return fontBuffersPromise;
}
export async function getPublisherFontBuffers() {
if (!publisherFontBuffersPromise) {
publisherFontBuffersPromise = Promise.all([
readFile(
getServerUrl(
"node_modules/@fontsource/bricolage-grotesque/files/bricolage-grotesque-latin-700-normal.woff2",
),
),
readFile(
getServerUrl(
"node_modules/@fontsource/bricolage-grotesque/files/bricolage-grotesque-latin-800-normal.woff2",
),
),
readFile(
getServerUrl(
"node_modules/@fontsource/bricolage-grotesque/files/bricolage-grotesque-latin-500-normal.woff2",
),
),
readFile(
getServerUrl(
"node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-500-normal.woff2",
),
),
readFile(
getServerUrl(
"node_modules/@fontsource/noto-sans-sc/files/noto-sans-sc-chinese-simplified-800-normal.woff2",
),
),
readFile(
getServerUrl(
"node_modules/@fontsource/noto-sans-sc/files/noto-sans-sc-chinese-simplified-500-normal.woff2",
),
),
]).then((buffers) => buffers.map((buffer) => new Uint8Array(buffer)));
}
return publisherFontBuffersPromise;
}
+2 -2
View File
@@ -9,7 +9,7 @@ import {
FONT_MONO,
FONT_SANS,
getClawHubLogoDataUrl,
getFontBuffers,
getPublisherFontBuffers,
} from "../../og/ogAssets";
import { pngResponse } from "../../og/pngResponse";
import { buildPublisherOgSvg } from "../../og/publisherOgSvg";
@@ -78,7 +78,7 @@ export default defineEventHandler(async (event) => {
const [clawHubLogoDataUrl, fontBuffers] = await Promise.all([
getClawHubLogoDataUrl(),
ensureResvgWasm().then(() => getFontBuffers()),
ensureResvgWasm().then(() => getPublisherFontBuffers()),
]);
const avatarDataUrl = await fetchPublisherProfileImageDataUrl(avatarFromQuery || meta?.image);
const organizationImageUrls =