Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 16, 2023
1 parent e874d6d commit 77ebd60
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions website/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import assert from 'node:assert'
import {promises as fs} from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import {fileURLToPath} from 'node:url'
import pAll from 'p-all'
Expand Down Expand Up @@ -362,44 +361,27 @@ await pAll(
await fs.unlink(output)
} catch {}

const filePath = fileURLToPath(output)
const page = await browser.newPage()

await page.setBypassCSP(true)
await page.setJavaScriptEnabled(true)

await page.setViewport({
// This is doubled in the actual file dimensions.
width: 1200,
height: 628,
deviceScaleFactor: 2
})

// This is doubled in the actual file dimensions.
await page.setViewport({deviceScaleFactor: 2, height: 628, width: 1200})
await page.emulateMediaFeatures([
{name: 'prefers-color-scheme', value: 'light'}
])
await page.setContent(file.value)

await page.setContent(file.value, {
// The Puppeteer default of 30 is too short.
timeout: 60 * 1000,
waitUntil: 'networkidle2'
})

console.log('cature:', filePath)
const screenshot = await page.screenshot({omitBackground: false})

await fs.mkdir(path.dirname(filePath), {recursive: true})
const screenshot = await page.screenshot()

await fs.writeFile(filePath, screenshot, {flag: 'wx'})
await fs.writeFile(output, screenshot)

console.log('catured:', filePath)
await page.close()

console.log('OG image `%s`', info.meta.title)
}),
{concurrency: 1}
)

console.log('closing browser')
await browser.close()

console.log('✔ OG images')

0 comments on commit 77ebd60

Please sign in to comment.