astro-selfie
Advanced tools
Comparing version
@@ -9,3 +9,2 @@ import path from 'node:path'; | ||
import { chromium } from 'playwright'; | ||
import makeDir from 'make-dir'; | ||
export default function selfie() { | ||
@@ -23,3 +22,3 @@ let publicDir; | ||
const screenshotsDir = new URL('og', publicDir); | ||
await makeDir(fileURLToPath(screenshotsDir)); | ||
await fs.mkdir(fileURLToPath(screenshotsDir), { recursive: true }); | ||
const port = await getPort(); | ||
@@ -48,6 +47,6 @@ const baseUrl = new URL(`http://localhost:${port}`); | ||
await page.goto(url.href); | ||
await page.evaluate('document.body.setAttribute("data-astro-selfie", "true")'); | ||
await page.evaluate('document.body.dataset.astroSelfie = true;'); | ||
const screenshot = await page.screenshot({ type: 'png' }); | ||
const screenshotPath = path.join(fileURLToPath(screenshotsDir), pathname === '' ? 'index.png' : `${pathname}.png`); | ||
await makeDir(path.dirname(screenshotPath)); | ||
await fs.mkdir(path.dirname(screenshotPath), { recursive: true }); | ||
await fs.writeFile(screenshotPath, screenshot); | ||
@@ -54,0 +53,0 @@ } |
{ | ||
"name": "astro-selfie", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Astro integration to generate page screenshots to show as Open Graph images", | ||
@@ -34,3 +34,2 @@ "license": "ISC", | ||
"get-port": "^7.0.0", | ||
"make-dir": "^3.1.0", | ||
"micro": "^10.0.1", | ||
@@ -37,0 +36,0 @@ "playwright": "^1.34.3", |
@@ -51,6 +51,4 @@ # astro-selfie [](https://github.com/vadimdemedes/astro-selfie/actions/workflows/test.yml) | ||
--- | ||
<meta | ||
property="og:image" | ||
content={screenshotUrl.href} | ||
/> | ||
<meta property="og:image" content={screenshotUrl.href} /> | ||
``` | ||
@@ -57,0 +55,0 @@ |
4
-20%6503
-0.41%71
-1.39%92
-2.13%- Removed
- Removed
- Removed