nuxt-og-image 1.4.7 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +26 -14
- package/dist/runtime/browserUtil.d.ts +1 -1
- package/dist/runtime/browserUtil.mjs +16 -7
- package/dist/runtime/composables/defineOgImage.mjs +1 -0
- package/dist/runtime/nitro/renderers/browser.mjs +8 -2
- package/dist/runtime/nitro/routes/html.mjs +1 -1
- package/package.json +3 -3
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -46,18 +46,27 @@ async function createBrowser() {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
async function screenshot(browser,
|
|
49
|
+
async function screenshot(browser, options) {
|
|
50
50
|
const page = await browser.newPage({
|
|
51
51
|
colorScheme: options.colorScheme
|
|
52
52
|
});
|
|
53
53
|
await page.setViewportSize({
|
|
54
|
-
width: options.width,
|
|
55
|
-
height: options.height
|
|
56
|
-
});
|
|
57
|
-
await page.goto(url, {
|
|
58
|
-
timeout: 1e4,
|
|
59
|
-
waitUntil: "networkidle"
|
|
54
|
+
width: options.width || 1200,
|
|
55
|
+
height: options.height || 630
|
|
60
56
|
});
|
|
57
|
+
if (options.path.startsWith("html:")) {
|
|
58
|
+
await page.evaluate((html) => {
|
|
59
|
+
document.open("text/html");
|
|
60
|
+
document.write(html);
|
|
61
|
+
document.close();
|
|
62
|
+
}, options.path.substring(5));
|
|
63
|
+
await page.waitForLoadState("networkidle");
|
|
64
|
+
} else {
|
|
65
|
+
await page.goto(`${options.host}${options.path}`, {
|
|
66
|
+
timeout: 1e4,
|
|
67
|
+
waitUntil: "networkidle"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
61
70
|
if (options.delay)
|
|
62
71
|
await page.waitForTimeout(options.delay);
|
|
63
72
|
if (options.mask) {
|
|
@@ -407,14 +416,16 @@ export default function() {
|
|
|
407
416
|
const routeRules = defu({}, ..._routeRulesMatcher.matchAll(ctx.route).reverse());
|
|
408
417
|
if (!extractedOptions || routeRules.ogImage === false)
|
|
409
418
|
return;
|
|
410
|
-
const
|
|
411
|
-
path: ctx.route,
|
|
419
|
+
const entry = {
|
|
420
|
+
path: extractedOptions.component ? `/api/og-image-html?path=${ctx.route}` : ctx.route,
|
|
412
421
|
...extractedOptions,
|
|
413
422
|
...routeRules.ogImage || {},
|
|
414
423
|
ctx
|
|
415
424
|
};
|
|
416
|
-
if (
|
|
417
|
-
|
|
425
|
+
if (entry.component)
|
|
426
|
+
entry.path = `html:${await $fetch(entry.path)}`;
|
|
427
|
+
if ((nuxt.options._generate || entry.static) && entry.provider === "browser")
|
|
428
|
+
screenshotQueue.push(entry);
|
|
418
429
|
});
|
|
419
430
|
if (nuxt.options.dev)
|
|
420
431
|
return;
|
|
@@ -446,7 +457,7 @@ export default function() {
|
|
|
446
457
|
})).trim();
|
|
447
458
|
browser = await createBrowser();
|
|
448
459
|
if (browser) {
|
|
449
|
-
nitro.logger.info(`
|
|
460
|
+
nitro.logger.info(`Prerendering ${screenshotQueue.length} og:image screenshots...`);
|
|
450
461
|
for (const k in screenshotQueue) {
|
|
451
462
|
const entry = screenshotQueue[k];
|
|
452
463
|
const start = Date.now();
|
|
@@ -454,9 +465,10 @@ export default function() {
|
|
|
454
465
|
const dirname = joinURL(nitro.options.output.publicDir, `${entry.ctx.fileName.replace("index.html", "")}__og_image__/`);
|
|
455
466
|
const filename = joinURL(dirname, "/og.png");
|
|
456
467
|
try {
|
|
457
|
-
const imgBuffer = await screenshot(browser,
|
|
468
|
+
const imgBuffer = await screenshot(browser, {
|
|
458
469
|
...config.defaults || {},
|
|
459
|
-
...entry || {}
|
|
470
|
+
...entry || {},
|
|
471
|
+
host
|
|
460
472
|
});
|
|
461
473
|
try {
|
|
462
474
|
await mkdirp(dirname);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Browser } from 'playwright-core';
|
|
3
3
|
import type { ScreenshotOptions } from '../types';
|
|
4
|
-
export declare function screenshot(browser: Browser,
|
|
4
|
+
export declare function screenshot(browser: Browser, options: Partial<ScreenshotOptions> & Record<string, any>): Promise<Buffer>;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
export async function screenshot(browser,
|
|
1
|
+
export async function screenshot(browser, options) {
|
|
2
2
|
const page = await browser.newPage({
|
|
3
3
|
colorScheme: options.colorScheme
|
|
4
4
|
});
|
|
5
5
|
await page.setViewportSize({
|
|
6
|
-
width: options.width,
|
|
7
|
-
height: options.height
|
|
8
|
-
});
|
|
9
|
-
await page.goto(url, {
|
|
10
|
-
timeout: 1e4,
|
|
11
|
-
waitUntil: "networkidle"
|
|
6
|
+
width: options.width || 1200,
|
|
7
|
+
height: options.height || 630
|
|
12
8
|
});
|
|
9
|
+
if (options.path.startsWith("html:")) {
|
|
10
|
+
await page.evaluate((html) => {
|
|
11
|
+
document.open("text/html");
|
|
12
|
+
document.write(html);
|
|
13
|
+
document.close();
|
|
14
|
+
}, options.path.substring(5));
|
|
15
|
+
await page.waitForLoadState("networkidle");
|
|
16
|
+
} else {
|
|
17
|
+
await page.goto(`${options.host}${options.path}`, {
|
|
18
|
+
timeout: 1e4,
|
|
19
|
+
waitUntil: "networkidle"
|
|
20
|
+
});
|
|
21
|
+
}
|
|
13
22
|
if (options.delay)
|
|
14
23
|
await page.waitForTimeout(options.delay);
|
|
15
24
|
if (options.mask) {
|
|
@@ -9,10 +9,16 @@ export default {
|
|
|
9
9
|
throw new Error("Browser provider can't create VNodes.");
|
|
10
10
|
},
|
|
11
11
|
createPng: async function createPng(basePath, options) {
|
|
12
|
+
const url = new URL(basePath);
|
|
12
13
|
const createBrowser = await loadBrowser();
|
|
13
14
|
const browser = await createBrowser();
|
|
14
|
-
if (browser)
|
|
15
|
-
return screenshot(browser,
|
|
15
|
+
if (browser) {
|
|
16
|
+
return screenshot(browser, {
|
|
17
|
+
...options,
|
|
18
|
+
host: url.origin,
|
|
19
|
+
path: `/api/og-image-html?path=${url.pathname}`
|
|
20
|
+
});
|
|
21
|
+
}
|
|
16
22
|
return null;
|
|
17
23
|
}
|
|
18
24
|
};
|
|
@@ -13,7 +13,7 @@ export default defineEventHandler(async (e) => {
|
|
|
13
13
|
options = JSON.parse(getQuery(e).options);
|
|
14
14
|
if (!options)
|
|
15
15
|
options = await fetchOptions(e, path);
|
|
16
|
-
if (options.provider === "browser")
|
|
16
|
+
if (options.provider === "browser" && !options.component)
|
|
17
17
|
return sendRedirect(e, withBase(path, useHostname(e)));
|
|
18
18
|
const island = await renderIsland(options);
|
|
19
19
|
const head = createHeadCore();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.8",
|
|
5
5
|
"packageManager": "pnpm@7.8.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"pathe": "^1.1.0",
|
|
42
42
|
"playwright-core": "^1.30.0",
|
|
43
43
|
"radix3": "^1.0.0",
|
|
44
|
-
"satori": "
|
|
44
|
+
"satori": "0.2.0",
|
|
45
45
|
"satori-html": "^0.3.2",
|
|
46
46
|
"sirv": "^2.0.2",
|
|
47
47
|
"std-env": "^3.3.2",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@antfu/eslint-config": "^0.35.1",
|
|
56
|
-
"@nuxt/devtools-edge": "0.0.0-
|
|
56
|
+
"@nuxt/devtools-edge": "0.0.0-27928010.c91ffe5",
|
|
57
57
|
"@nuxt/module-builder": "^0.2.1",
|
|
58
58
|
"@nuxt/test-utils": "3.1.2",
|
|
59
59
|
"@nuxtjs/eslint-config-typescript": "^12.0.0",
|