nuxt-og-image 2.0.0-beta.7 → 2.0.0-beta.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/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/{IconCSS.a041aca0.js → IconCSS.e4ca33fe.js} +1 -1
- package/dist/client/_nuxt/{ImageLoader.9bf39d71.js → ImageLoader.b3a6a884.js} +1 -1
- package/dist/client/_nuxt/entry.0bddba71.js +5 -0
- package/dist/client/_nuxt/entry.b37a20ad.css +1 -0
- package/dist/client/_nuxt/{error-404.1ff52902.js → error-404.f5dc80fe.js} +1 -1
- package/dist/client/_nuxt/{error-500.f7d30da5.js → error-500.a1082086.js} +1 -1
- package/dist/client/_nuxt/{error-component.cf7543e5.js → error-component.a28c293c.js} +2 -2
- package/dist/client/_nuxt/{index.3f356409.js → index.7dc20983.js} +1 -1
- package/dist/client/_nuxt/{options.56a3e5f9.js → options.97e2328c.js} +1 -1
- package/dist/client/_nuxt/{png.37f3e77b.js → png.50aa137a.js} +1 -1
- package/dist/client/_nuxt/{shiki.3a930bb8.js → shiki.665f08b3.js} +1 -1
- package/dist/client/_nuxt/{svg.186c6bd1.js → svg.d633e908.js} +1 -1
- package/dist/client/_nuxt/{vnodes.a799f183.js → vnodes.63ee1c3b.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/options/index.html +2 -2
- package/dist/client/png/index.html +2 -2
- package/dist/client/svg/index.html +2 -2
- package/dist/client/vnodes/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +24 -20
- package/dist/runtime/browserUtil.mjs +5 -2
- package/dist/runtime/nitro/middleware/playground.mjs +4 -3
- package/dist/runtime/nitro/renderers/browser.mjs +3 -1
- package/dist/runtime/nitro/routes/html.mjs +11 -8
- package/dist/runtime/nitro/routes/options.mjs +4 -2
- package/dist/runtime/nitro/routes/svg.mjs +3 -1
- package/dist/runtime/nitro/routes/vnode.mjs +3 -1
- package/dist/runtime/nitro/utils.d.ts +1 -1
- package/dist/runtime/nitro/utils.mjs +6 -5
- package/package.json +14 -13
- package/dist/client/_nuxt/entry.74018bda.js +0 -5
- package/dist/client/_nuxt/entry.7a8c1ab2.css +0 -1
package/dist/module.mjs
CHANGED
|
@@ -4,12 +4,13 @@ import { execa } from 'execa';
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import defu from 'defu';
|
|
6
6
|
import { toRouteMatcher, createRouter } from 'radix3';
|
|
7
|
-
import { joinURL } from 'ufo';
|
|
7
|
+
import { withBase, joinURL } from 'ufo';
|
|
8
8
|
import { resolve, relative } from 'pathe';
|
|
9
9
|
import { tinyws } from 'tinyws';
|
|
10
10
|
import sirv from 'sirv';
|
|
11
11
|
import { pathExists, copy, mkdirp } from 'fs-extra';
|
|
12
12
|
import { provider } from 'std-env';
|
|
13
|
+
import { $fetch } from 'ofetch';
|
|
13
14
|
import playwrightCore from 'playwright-core';
|
|
14
15
|
import { existsSync } from 'node:fs';
|
|
15
16
|
import { createBirpcGroup } from 'birpc';
|
|
@@ -69,6 +70,9 @@ async function screenshot(browser, options) {
|
|
|
69
70
|
waitUntil: "networkidle"
|
|
70
71
|
});
|
|
71
72
|
}
|
|
73
|
+
const screenshotOptions = {
|
|
74
|
+
timeout: 1e4
|
|
75
|
+
};
|
|
72
76
|
if (options.delay)
|
|
73
77
|
await page.waitForTimeout(options.delay);
|
|
74
78
|
if (options.mask) {
|
|
@@ -78,8 +82,8 @@ async function screenshot(browser, options) {
|
|
|
78
82
|
}, options.mask);
|
|
79
83
|
}
|
|
80
84
|
if (options.selector)
|
|
81
|
-
return await page.locator(options.selector).screenshot();
|
|
82
|
-
return await page.screenshot();
|
|
85
|
+
return await page.locator(options.selector).screenshot(screenshotOptions);
|
|
86
|
+
return await page.screenshot(screenshotOptions);
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
function setupPlaygroundRPC(nuxt, config) {
|
|
@@ -113,7 +117,7 @@ function setupPlaygroundRPC(nuxt, config) {
|
|
|
113
117
|
const birpc = createBirpcGroup(serverFunctions, []);
|
|
114
118
|
nuxt.hook("builder:watch", (e, path) => {
|
|
115
119
|
if (e === "change")
|
|
116
|
-
birpc.
|
|
120
|
+
birpc.broadcast.refresh.asEvent(path);
|
|
117
121
|
});
|
|
118
122
|
const middleware = async (req, res) => {
|
|
119
123
|
if (req.ws) {
|
|
@@ -446,21 +450,6 @@ export async function useProvider(provider) {
|
|
|
446
450
|
await nuxt.callHook("og-image:prerenderScreenshots", screenshotQueue);
|
|
447
451
|
if (screenshotQueue.length === 0)
|
|
448
452
|
return;
|
|
449
|
-
for (const entry of screenshotQueue) {
|
|
450
|
-
if (entry.route && Object.keys(entry).length === 1) {
|
|
451
|
-
const html = await $fetch(entry.route);
|
|
452
|
-
const extractedOptions = extractOgImageOptions(html);
|
|
453
|
-
const routeRules = defu({}, ..._routeRulesMatcher.matchAll(entry.route).reverse());
|
|
454
|
-
Object.assign(entry, {
|
|
455
|
-
// @ts-expect-error runtime
|
|
456
|
-
path: extractedOptions.component ? `/api/og-image-html?path=${entry.route}` : entry.route,
|
|
457
|
-
...extractedOptions,
|
|
458
|
-
...routeRules.ogImage || {}
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
if (entry.component)
|
|
462
|
-
entry.html = await $fetch(entry.path);
|
|
463
|
-
}
|
|
464
453
|
nitro.logger.info("Ensuring chromium install for og:image generation...");
|
|
465
454
|
const installChromeProcess = execa("npx", ["playwright", "install", "chromium"], {
|
|
466
455
|
stdio: "inherit"
|
|
@@ -487,6 +476,21 @@ export async function useProvider(provider) {
|
|
|
487
476
|
browser = await createBrowser();
|
|
488
477
|
if (browser) {
|
|
489
478
|
nitro.logger.info(`Prerendering ${screenshotQueue.length} og:image screenshots...`);
|
|
479
|
+
for (const entry of screenshotQueue) {
|
|
480
|
+
if (entry.route && Object.keys(entry).length === 1) {
|
|
481
|
+
const html = await $fetch(entry.route, { baseURL: withBase(nuxt.options.app.baseURL, host) });
|
|
482
|
+
const extractedOptions = extractOgImageOptions(html);
|
|
483
|
+
const routeRules = defu({}, ..._routeRulesMatcher.matchAll(entry.route).reverse());
|
|
484
|
+
Object.assign(entry, {
|
|
485
|
+
// @ts-expect-error runtime
|
|
486
|
+
path: extractedOptions.component ? `/api/og-image-html?path=${entry.route}` : entry.route,
|
|
487
|
+
...extractedOptions,
|
|
488
|
+
...routeRules.ogImage || {}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
if (entry.component)
|
|
492
|
+
entry.html = await $fetch(entry.path, { baseURL: withBase(nuxt.options.app.baseURL, host) });
|
|
493
|
+
}
|
|
490
494
|
for (const k in screenshotQueue) {
|
|
491
495
|
const entry = screenshotQueue[k];
|
|
492
496
|
const start = Date.now();
|
|
@@ -524,7 +528,7 @@ export async function useProvider(provider) {
|
|
|
524
528
|
}
|
|
525
529
|
screenshotQueue = [];
|
|
526
530
|
};
|
|
527
|
-
if (
|
|
531
|
+
if (nuxt.options._generate) {
|
|
528
532
|
nitro.hooks.hook("rollup:before", async () => {
|
|
529
533
|
await captureScreenshots();
|
|
530
534
|
});
|
|
@@ -21,6 +21,9 @@ export async function screenshot(browser, options) {
|
|
|
21
21
|
waitUntil: "networkidle"
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
const screenshotOptions = {
|
|
25
|
+
timeout: 1e4
|
|
26
|
+
};
|
|
24
27
|
if (options.delay)
|
|
25
28
|
await page.waitForTimeout(options.delay);
|
|
26
29
|
if (options.mask) {
|
|
@@ -30,6 +33,6 @@ export async function screenshot(browser, options) {
|
|
|
30
33
|
}, options.mask);
|
|
31
34
|
}
|
|
32
35
|
if (options.selector)
|
|
33
|
-
return await page.locator(options.selector).screenshot();
|
|
34
|
-
return await page.screenshot();
|
|
36
|
+
return await page.locator(options.selector).screenshot(screenshotOptions);
|
|
37
|
+
return await page.screenshot(screenshotOptions);
|
|
35
38
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { defineEventHandler } from "h3";
|
|
2
|
-
import { parseURL, withoutTrailingSlash } from "ufo";
|
|
2
|
+
import { parseURL, withBase, withoutTrailingSlash } from "ufo";
|
|
3
3
|
import { fetchOptions } from "../utils.mjs";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
5
|
export default defineEventHandler(async (e) => {
|
|
5
6
|
const path = withoutTrailingSlash(parseURL(e.path).pathname);
|
|
6
7
|
if (!path.endsWith("/__og_image__"))
|
|
7
8
|
return;
|
|
8
|
-
const basePath = path.replace("/__og_image__", "");
|
|
9
|
+
const basePath = withBase(path.replace("/__og_image__", ""), useRuntimeConfig().app.baseURL);
|
|
9
10
|
const options = await fetchOptions(e, basePath === "" ? "/" : basePath);
|
|
10
11
|
if (!options)
|
|
11
12
|
return `The route ${basePath} has not been set up for og:image generation.`;
|
|
@@ -22,5 +23,5 @@ export default defineEventHandler(async (e) => {
|
|
|
22
23
|
}
|
|
23
24
|
</style>
|
|
24
25
|
<title>OG Image Playground</title>
|
|
25
|
-
<iframe src="/__nuxt_og_image__/client
|
|
26
|
+
<iframe src="/__nuxt_og_image__/client?&path=${basePath}&base=${useRuntimeConfig().app.baseURL}"></iframe>`;
|
|
26
27
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { withBase } from "ufo";
|
|
1
2
|
import { screenshot } from "../../browserUtil.mjs";
|
|
2
3
|
import loadBrowser from "#nuxt-og-image/browser";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
5
|
export default {
|
|
4
6
|
name: "browser",
|
|
5
7
|
createSvg: async function createSvg() {
|
|
@@ -16,7 +18,7 @@ export default {
|
|
|
16
18
|
try {
|
|
17
19
|
return await screenshot(browser, {
|
|
18
20
|
...options,
|
|
19
|
-
host: url.origin,
|
|
21
|
+
host: withBase(useRuntimeConfig().app.baseURL, url.origin),
|
|
20
22
|
path: `/api/og-image-html?path=${url.pathname}`
|
|
21
23
|
});
|
|
22
24
|
} finally {
|
|
@@ -3,19 +3,22 @@ import { renderSSRHead } from "@unhead/ssr";
|
|
|
3
3
|
import { createHeadCore } from "@unhead/vue";
|
|
4
4
|
import { defineEventHandler, getQuery, sendRedirect } from "h3";
|
|
5
5
|
import { fetchOptions, renderIsland, useHostname } from "../utils.mjs";
|
|
6
|
-
import { useRuntimeConfig } from "#
|
|
6
|
+
import { useRuntimeConfig } from "#imports";
|
|
7
7
|
export default defineEventHandler(async (e) => {
|
|
8
8
|
const { fonts, defaults } = useRuntimeConfig()["nuxt-og-image"];
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const query = getQuery(e);
|
|
10
|
+
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
11
|
+
const scale = query.scale;
|
|
12
|
+
const mode = query.mode || "light";
|
|
12
13
|
let options;
|
|
13
|
-
if (
|
|
14
|
-
options = JSON.parse(
|
|
14
|
+
if (query.options)
|
|
15
|
+
options = JSON.parse(query.options);
|
|
15
16
|
if (!options)
|
|
16
17
|
options = await fetchOptions(e, path);
|
|
17
|
-
if (options.provider === "browser" && !options.component)
|
|
18
|
-
|
|
18
|
+
if (options.provider === "browser" && !options.component) {
|
|
19
|
+
const pathWithoutBase = path.replace(new RegExp(`^${useRuntimeConfig().app.baseURL}`), "");
|
|
20
|
+
return sendRedirect(e, withBase(pathWithoutBase, useHostname(e)));
|
|
21
|
+
}
|
|
19
22
|
const island = await renderIsland(options);
|
|
20
23
|
const head = createHeadCore();
|
|
21
24
|
head.push(island.head);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getHeaders, getQuery } from "h3";
|
|
2
|
+
import { withoutBase } from "ufo";
|
|
2
3
|
import { extractOgImageOptions, useHostname } from "../utils.mjs";
|
|
3
|
-
import { getRouteRules
|
|
4
|
+
import { getRouteRules } from "#internal/nitro";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
6
|
export default defineEventHandler(async (e) => {
|
|
5
7
|
const query = getQuery(e);
|
|
6
|
-
const path = query.path || "/";
|
|
8
|
+
const path = withoutBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
7
9
|
const fetchOptions = process.dev || process.env.prerender ? {
|
|
8
10
|
headers: getHeaders(e)
|
|
9
11
|
} : {
|
|
@@ -2,8 +2,10 @@ import { createError, defineEventHandler, getQuery, setHeader } from "h3";
|
|
|
2
2
|
import { withBase } from "ufo";
|
|
3
3
|
import { fetchOptions, useHostname } from "../utils.mjs";
|
|
4
4
|
import { useProvider } from "#nuxt-og-image/provider";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
6
|
export default defineEventHandler(async (e) => {
|
|
6
|
-
const
|
|
7
|
+
const query = getQuery(e);
|
|
8
|
+
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
7
9
|
const options = await fetchOptions(e, path);
|
|
8
10
|
setHeader(e, "Content-Type", "image/svg+xml");
|
|
9
11
|
const provider = await useProvider(options.provider);
|
|
@@ -2,8 +2,10 @@ import { createError, defineEventHandler, getQuery, setHeader } from "h3";
|
|
|
2
2
|
import { withBase } from "ufo";
|
|
3
3
|
import { fetchOptions, useHostname } from "../utils.mjs";
|
|
4
4
|
import { useProvider } from "#nuxt-og-image/provider";
|
|
5
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
6
|
export default defineEventHandler(async (e) => {
|
|
6
|
-
const
|
|
7
|
+
const query = getQuery(e);
|
|
8
|
+
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
7
9
|
const options = await fetchOptions(e, path);
|
|
8
10
|
setHeader(e, "Content-Type", "application/json");
|
|
9
11
|
const provider = await useProvider(options.provider);
|
|
@@ -11,7 +11,7 @@ export declare function renderIsland(payload: OgImageOptions): Promise<{
|
|
|
11
11
|
html: string;
|
|
12
12
|
head: any;
|
|
13
13
|
}>;
|
|
14
|
-
export declare function useHostname(e: H3Event):
|
|
14
|
+
export declare function useHostname(e: H3Event): string;
|
|
15
15
|
export declare function readPublicAsset(file: string, encoding?: BufferEncoding): Promise<string | Buffer | undefined>;
|
|
16
16
|
export declare function readPublicAssetBase64(file: string): Promise<string | undefined>;
|
|
17
17
|
export * from './utils-pure';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, promises as fsp } from "node:fs";
|
|
2
2
|
import { getHeaders, getQuery, getRequestHeader } from "h3";
|
|
3
3
|
import { join } from "pathe";
|
|
4
|
+
import { withBase } from "ufo";
|
|
4
5
|
import { useRuntimeConfig } from "#internal/nitro";
|
|
5
6
|
export function wasmLoader(key, fallback, baseUrl) {
|
|
6
7
|
let promise;
|
|
@@ -60,18 +61,18 @@ export function renderIsland(payload) {
|
|
|
60
61
|
}
|
|
61
62
|
export function useHostname(e) {
|
|
62
63
|
const config = useRuntimeConfig()["nuxt-og-image"];
|
|
64
|
+
const base = useRuntimeConfig().app.baseURL;
|
|
63
65
|
if (!process.dev && config.siteUrl)
|
|
64
|
-
return config.siteUrl;
|
|
66
|
+
return withBase(base, config.siteUrl);
|
|
65
67
|
const host = getRequestHeader(e, "host") || process.env.NITRO_HOST || process.env.HOST || "localhost";
|
|
66
68
|
const protocol = getRequestHeader(e, "x-forwarded-proto") || "http";
|
|
67
69
|
const useHttp = process.env.NODE_ENV === "development" || host.includes("127.0.0.1") || host.includes("localhost") || protocol === "http";
|
|
68
70
|
const port = host.includes(":") ? host.split(":").pop() : process.env.NITRO_PORT || process.env.PORT;
|
|
69
|
-
|
|
70
|
-
return `http${useHttp ? "" : "s"}://${host.includes(":") ? host.split(":")[0] : host}${port ? `:${port}` : ""}${base}`;
|
|
71
|
+
return withBase(base, `http${useHttp ? "" : "s"}://${host.includes(":") ? host.split(":")[0] : host}${port ? `:${port}` : ""}`);
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
+
function r(base, key) {
|
|
73
74
|
return join(base, key.replace(/:/g, "/"));
|
|
74
|
-
}
|
|
75
|
+
}
|
|
75
76
|
export async function readPublicAsset(file, encoding) {
|
|
76
77
|
const { assetDirs } = useRuntimeConfig()["nuxt-og-image"];
|
|
77
78
|
for (const assetDir of assetDirs) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
5
|
-
"packageManager": "pnpm@
|
|
4
|
+
"version": "2.0.0-beta.8",
|
|
5
|
+
"packageManager": "pnpm@8.1.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
8
8
|
"homepage": "https://github.com/harlan-zw/nuxt-og-image#readme",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@nuxt/kit": "3.3.
|
|
29
|
+
"@nuxt/kit": "3.3.2",
|
|
30
30
|
"@types/fs-extra": "^11.0.1",
|
|
31
31
|
"birpc": "^0.2.10",
|
|
32
32
|
"chalk": "^5.2.0",
|
|
@@ -37,10 +37,11 @@
|
|
|
37
37
|
"flatted": "^3.2.7",
|
|
38
38
|
"fs-extra": "^11.1.1",
|
|
39
39
|
"launch-editor": "^2.6.0",
|
|
40
|
+
"ofetch": "^1.0.1",
|
|
40
41
|
"ohash": "^1.0.0",
|
|
41
42
|
"pathe": "^1.1.0",
|
|
42
|
-
"playwright-core": "^1.
|
|
43
|
-
"radix3": "^1.0.
|
|
43
|
+
"playwright-core": "^1.32.1",
|
|
44
|
+
"radix3": "^1.0.1",
|
|
44
45
|
"satori": "0.4.4",
|
|
45
46
|
"satori-html": "^0.3.2",
|
|
46
47
|
"sirv": "^2.0.2",
|
|
@@ -53,18 +54,18 @@
|
|
|
53
54
|
"yoga-wasm-web": "^0.3.3"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@antfu/eslint-config": "^0.
|
|
57
|
-
"@nuxt/devtools-edge": "0.
|
|
57
|
+
"@antfu/eslint-config": "^0.38.2",
|
|
58
|
+
"@nuxt/devtools-edge": "0.3.1-28002813.ab4e03d",
|
|
58
59
|
"@nuxt/module-builder": "^0.2.1",
|
|
59
|
-
"@nuxt/test-utils": "3.3.
|
|
60
|
+
"@nuxt/test-utils": "3.3.2",
|
|
60
61
|
"@nuxtjs/eslint-config-typescript": "^12.0.0",
|
|
61
62
|
"@types/ws": "^8.5.4",
|
|
62
|
-
"bumpp": "^9.
|
|
63
|
-
"eslint": "8.
|
|
63
|
+
"bumpp": "^9.1.0",
|
|
64
|
+
"eslint": "8.37.0",
|
|
64
65
|
"jest-image-snapshot": "^6.1.0",
|
|
65
|
-
"nuxt": "^3.3.
|
|
66
|
-
"puppeteer": "^19.
|
|
67
|
-
"vitest": "^0.29.
|
|
66
|
+
"nuxt": "^3.3.2",
|
|
67
|
+
"puppeteer": "^19.8.2",
|
|
68
|
+
"vitest": "^0.29.8"
|
|
68
69
|
},
|
|
69
70
|
"scripts": {
|
|
70
71
|
"build": "pnpm dev:prepare && pnpm build:module && pnpm build:client",
|