-
-
Save niladam/67f9f06e9f4a44acb3842d40931d6385 to your computer and use it in GitHub Desktop.
Dynamic Social Sharing Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
const imagemin = require('imagemin'); | |
const imageminPngquant = require('imagemin-pngquant'); | |
// Get the URL and the slug segment from it | |
const url = process.argv[2]; | |
const segments = url.split('/'); | |
const slug = segments[segments.length-2]; | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto(url + 'sharing'); | |
await page.setViewport({ | |
width: 600, | |
height: 315, | |
deviceScaleFactor: 2 | |
}); | |
await page.screenshot({path: slug + '.png'}); | |
await browser.close(); | |
await imagemin([slug + '.png'], 'build', { | |
plugins: [ | |
imageminPngquant({quality: '75-90'}) | |
] | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment