|
|
@ -14,25 +14,28 @@ const slugify = (str: string) => |
|
|
|
.replace(/[^a-z0-9.]+/g, "-") |
|
|
|
.replace(/(^-|-$)/g, ""); |
|
|
|
|
|
|
|
if (Deno.args.length !== 2) { |
|
|
|
console.error("usage: generate-screenshot.ts name css-file"); |
|
|
|
Deno.exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
const screenshotFile = `${slugify(Deno.args[0])}.png`; |
|
|
|
const cssFile = Deno.args[1]; |
|
|
|
|
|
|
|
const saveScreenshot = async (src: string, dest: string) => { |
|
|
|
const browser = await puppeteer.launch(); |
|
|
|
// For whatever reason, I get screenshots 16 pixels wider than the requested
|
|
|
|
// viewport size.
|
|
|
|
const browser = await puppeteer.launch({ |
|
|
|
defaultViewport: { width: 1024 - 16, height: 1024, deviceScaleFactor: 1 } |
|
|
|
}); |
|
|
|
const page = await browser.newPage(); |
|
|
|
|
|
|
|
await page.setViewport({ width: 1024, height: 1024, deviceScaleFactor: 1 }); |
|
|
|
await page.goto(src); |
|
|
|
await page.screenshot({ fullPage: true, path: dest }); |
|
|
|
|
|
|
|
await browser.close(); |
|
|
|
}; |
|
|
|
|
|
|
|
if (Deno.args.length !== 2) { |
|
|
|
console.error("usage: generate-screenshot.ts name css-file"); |
|
|
|
Deno.exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
const screenshotFile = `${slugify(Deno.args[0])}.png`; |
|
|
|
const cssFile = Deno.args[1]; |
|
|
|
|
|
|
|
try { |
|
|
|
const htmlTemplate = await Deno.readTextFile(templateFile); |
|
|
|
const css = await Deno.readTextFile(cssFile); |
|
|
|