diff --git a/card.ts b/card.ts index 180082a..8bbd91e 100644 --- a/card.ts +++ b/card.ts @@ -6,8 +6,8 @@ import { writeTempFile, pathToFileURL } from './file'; async function handler(req: IncomingMessage, res: ServerResponse) { try { - const { type, text, fontWeight, images } = parseRequest(req); - const html = getHtml(text, fontWeight, images); + const { type, text, fontWeight, fontSize, images } = parseRequest(req); + const html = getHtml(text, fontWeight, fontSize, images); const filePath = await writeTempFile(text, html); const fileUrl = pathToFileURL(filePath); const file = await getScreenshot(fileUrl, type); diff --git a/parser.ts b/parser.ts index 85a5313..0671937 100644 --- a/parser.ts +++ b/parser.ts @@ -5,16 +5,20 @@ interface ParsedRequest { type: ScreenshotType; text: string; fontWeight: FontWeight; + fontSize: string; images: string[]; }; export function parseRequest(req: IncomingMessage) { console.log('HTTP ' + req.url); const { pathname = '/', query = {} } = parse(req.url || '', true); - const { fontWeight, images } = query; + const { fontWeight, fontSize, images } = query; if (Array.isArray(fontWeight)) { throw new Error('Expected a single fontWeight'); } + if (Array.isArray(fontSize)) { + throw new Error('Expected a single fontSize'); + } const arr = pathname.slice(1).split('.'); const type = arr.pop(); const text = arr.join('.'); @@ -22,6 +26,7 @@ export function parseRequest(req: IncomingMessage) { type: type as ScreenshotType, text: decodeURIComponent(text), fontWeight: fontWeight as FontWeight, + fontSize: fontSize || '75px', images: Array.isArray(images) && images.length > 0 ? images : ['https://assets.zeit.co/image/upload/front/assets/design/now-black.svg'], diff --git a/template.ts b/template.ts index f2a91ca..6eecbc7 100644 --- a/template.ts +++ b/template.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; -function getCss(fontWeight: FontWeight) { +function getCss(fontWeight: FontWeight, fontSize: string) { const regular = `${__dirname}/fonts/Inter-UI-Regular.woff2`; const bold = `${__dirname}/fonts/Inter-UI-Bold.woff2`; const buffer = readFileSync(fontWeight === 'normal' ? regular : bold); @@ -36,16 +36,16 @@ function getCss(fontWeight: FontWeight) { .heading { font-family: 'Inter UI', sans-serif; - font-size: 75px; + font-size: ${fontSize}; font-style: normal; font-weight: ${fontWeight}; }`; } -export function getHtml(text: string, fontWeight: FontWeight, images: string[]) { +export function getHtml(text: string, fontWeight: FontWeight, fontSize: string, images: string[]) { return `