4b2412c49c
* Copy in og-image code * Add "yarn start" command in lieu of vercel * Don't require that images be sourced from vercel * Load in Major Mono and Readex fonts * Fix vercel config (?) * Replace default image with Manifold's * Add some brief instructions on getting started * In the UI, use the default image * Fix typescript errors * More typescript fixing
27 lines
644 B
TypeScript
27 lines
644 B
TypeScript
import core from "puppeteer-core";
|
|
import { getOptions } from "./options";
|
|
import { FileType } from "./types";
|
|
let _page: core.Page | null;
|
|
|
|
async function getPage(isDev: boolean) {
|
|
if (_page) {
|
|
return _page;
|
|
}
|
|
const options = await getOptions(isDev);
|
|
const browser = await core.launch(options);
|
|
_page = await browser.newPage();
|
|
return _page;
|
|
}
|
|
|
|
export async function getScreenshot(
|
|
html: string,
|
|
type: FileType,
|
|
isDev: boolean
|
|
) {
|
|
const page = await getPage(isDev);
|
|
await page.setViewport({ width: 2048, height: 1170 });
|
|
await page.setContent(html);
|
|
const file = await page.screenshot({ type });
|
|
return file;
|
|
}
|