diff --git a/og-image/api/_lib/chromium.ts b/og-image/api/_lib/chromium.ts index dc8ff57c..e6d01816 100644 --- a/og-image/api/_lib/chromium.ts +++ b/og-image/api/_lib/chromium.ts @@ -19,7 +19,7 @@ export async function getScreenshot( isDev: boolean ) { const page = await getPage(isDev); - await page.setViewport({ width: 2048, height: 1170 }); + await page.setViewport({ width: 1200, height: 630 }); await page.setContent(html); const file = await page.screenshot({ type }); return file; diff --git a/og-image/api/_lib/parser.ts b/og-image/api/_lib/parser.ts index bc4dfe4d..f65fcf27 100644 --- a/og-image/api/_lib/parser.ts +++ b/og-image/api/_lib/parser.ts @@ -5,7 +5,22 @@ import { ParsedRequest } from "./types"; export function parseRequest(req: IncomingMessage) { console.log("HTTP " + req.url); const { pathname, query } = parse(req.url || "/", true); - const { fontSize, images, widths, heights, theme, md } = query || {}; + const { + fontSize, + images, + widths, + heights, + theme, + md, + + // Attributes for Manifold card: + question, + probability, + metadata, + creatorName, + creatorUsername, + creatorAvatarUrl, + } = query || {}; if (Array.isArray(fontSize)) { throw new Error("Expected a single fontSize"); @@ -26,6 +41,15 @@ export function parseRequest(req: IncomingMessage) { text = arr.join("."); } + // Take a url query param and return a single string + const getString = (stringOrArray: string[] | string | undefined): string => { + if (Array.isArray(stringOrArray)) { + // If the query param is an array, return the first element + return stringOrArray[0]; + } + return stringOrArray || ""; + }; + const parsedRequest: ParsedRequest = { fileType: extension === "jpeg" ? extension : "png", text: decodeURIComponent(text), @@ -35,6 +59,15 @@ export function parseRequest(req: IncomingMessage) { images: getArray(images), widths: getArray(widths), heights: getArray(heights), + + question: + getString(question) || "Will you create a prediction market on Manifold?", + probability: getString(probability) || "85", + metadata: getString(metadata) || "Jan 1 • M$ 123 pool", + creatorName: getString(creatorName) || "Manifold Markets", + creatorUsername: getString(creatorUsername) || "ManifoldMarkets", + creatorAvatarUrl: + getString(creatorAvatarUrl) || "https://manifold.markets/logo.png", }; parsedRequest.images = getDefaultImages(parsedRequest.images); return parsedRequest; diff --git a/og-image/api/_lib/template.ts b/og-image/api/_lib/template.ts index 8d89a3cf..3689cc2e 100644 --- a/og-image/api/_lib/template.ts +++ b/og-image/api/_lib/template.ts @@ -1,20 +1,5 @@ -import { readFileSync } from "fs"; -import marked from "marked"; import { sanitizeHtml } from "./sanitizer"; import { ParsedRequest } from "./types"; -const twemoji = require("twemoji"); -const twOptions = { folder: "svg", ext: ".svg" }; -const emojify = (text: string) => twemoji.parse(text, twOptions); - -const rglr = readFileSync( - `${__dirname}/../_fonts/Inter-Regular.woff2` -).toString("base64"); -const bold = readFileSync(`${__dirname}/../_fonts/Inter-Bold.woff2`).toString( - "base64" -); -const mono = readFileSync(`${__dirname}/../_fonts/Vera-Mono.woff2`).toString( - "base64" -); function getCss(theme: string, fontSize: string) { let background = "white"; @@ -30,36 +15,12 @@ function getCss(theme: string, fontSize: string) { return ` @import url('https://fonts.googleapis.com/css2?family=Major+Mono+Display&family=Readex+Pro:wght@400;700&display=swap'); - @font-face { - font-family: 'Inter'; - font-style: normal; - font-weight: normal; - src: url(data:font/woff2;charset=utf-8;base64,${rglr}) format('woff2'); - } - - @font-face { - font-family: 'Inter'; - font-style: normal; - font-weight: bold; - src: url(data:font/woff2;charset=utf-8;base64,${bold}) format('woff2'); - } - - @font-face { - font-family: 'Vera'; - font-style: normal; - font-weight: normal; - src: url(data:font/woff2;charset=utf-8;base64,${mono}) format("woff2"); - } - body { background: ${background}; background-image: radial-gradient(circle at 25px 25px, ${radial} 2%, transparent 0%), radial-gradient(circle at 75px 75px, ${radial} 2%, transparent 0%); background-size: 100px 100px; height: 100vh; - display: flex; - text-align: center; - align-items: center; - justify-content: center; + font-family: "Readex Pro", sans-serif; } code { @@ -108,50 +69,92 @@ function getCss(theme: string, fontSize: string) { font-style: normal; color: ${foreground}; line-height: 1.8; - }`; + } + + .font-major-mono { + font-family: "Major Mono Display", monospace; + } + + .text-primary { + color: #11b981; + } + `; } export function getHtml(parsedReq: ParsedRequest) { - const { text, theme, md, fontSize, images, widths, heights } = parsedReq; + const { + theme, + fontSize, + + question, + probability, + metadata, + creatorName, + creatorUsername, + creatorAvatarUrl, + } = parsedReq; return ` - -
${creatorName}
+@${creatorUsername}
+Austin Chen
+@AustinChen
+