nuxt-og-image 0.0.3 → 0.0.5
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 +5 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -8
- package/dist/runtime/composables/defineOgImage.d.ts +5 -0
- package/dist/runtime/composables/defineOgImage.mjs +5 -7
- package/dist/runtime/nitro/html.d.ts +2 -0
- package/dist/runtime/nitro/html.mjs +2 -1
- package/dist/runtime/nitro/image.d.ts +8 -1
- package/dist/runtime/nitro/image.mjs +46 -2
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/runtime/browserService.d.ts +0 -5
- package/dist/runtime/browserService.mjs +0 -44
- package/dist/runtime/const.d.ts +0 -5
- package/dist/runtime/const.mjs +0 -5
package/dist/module.d.ts
CHANGED
|
@@ -41,6 +41,10 @@ interface ModuleOptions extends ScreenshotOptions {
|
|
|
41
41
|
*/
|
|
42
42
|
runtimeImages: boolean;
|
|
43
43
|
}
|
|
44
|
+
declare const HtmlRendererRoute = "__og_image";
|
|
45
|
+
declare const PayloadScriptId = "nuxt-og-image-payload";
|
|
46
|
+
declare const MetaOgImageContentPlaceholder = "__NUXT_OG_IMAGE_PLACEHOLDER__";
|
|
47
|
+
declare const LinkPrerenderId = "nuxt-og-image-screenshot-path";
|
|
44
48
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
45
49
|
|
|
46
|
-
export { ModuleOptions, _default as default };
|
|
50
|
+
export { HtmlRendererRoute, LinkPrerenderId, MetaOgImageContentPlaceholder, ModuleOptions, PayloadScriptId, _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mkdir, writeFile, readFile, rm } from 'node:fs/promises';
|
|
2
|
-
import { defineNuxtModule, createResolver, addTemplate, addServerHandler, addImports, addComponent } from '@nuxt/kit';
|
|
2
|
+
import { defineNuxtModule, createResolver, addTemplate, getNuxtVersion, addServerHandler, addImports, addComponent } from '@nuxt/kit';
|
|
3
3
|
import { execa } from 'execa';
|
|
4
4
|
import { hash } from 'ohash';
|
|
5
5
|
import chalk from 'chalk';
|
|
@@ -57,7 +57,6 @@ const HtmlRendererRoute = "__og_image";
|
|
|
57
57
|
const PayloadScriptId = "nuxt-og-image-payload";
|
|
58
58
|
const MetaOgImageContentPlaceholder = "__NUXT_OG_IMAGE_PLACEHOLDER__";
|
|
59
59
|
const LinkPrerenderId = "nuxt-og-image-screenshot-path";
|
|
60
|
-
|
|
61
60
|
const module = defineNuxtModule({
|
|
62
61
|
meta: {
|
|
63
62
|
name: "nuxt-og-image",
|
|
@@ -95,13 +94,15 @@ declare module 'nitropack' {
|
|
|
95
94
|
nuxt.hooks.hook("prepare:types", ({ references }) => {
|
|
96
95
|
references.push({ path: resolve(nuxt.options.buildDir, "nuxt-og-image.d.ts") });
|
|
97
96
|
});
|
|
98
|
-
|
|
99
|
-
handler: resolve("./runtime/nitro/html")
|
|
100
|
-
});
|
|
101
|
-
if (config.runtimeImages) {
|
|
97
|
+
if (getNuxtVersion(nuxt) !== "3.0.0") {
|
|
102
98
|
addServerHandler({
|
|
103
|
-
handler: resolve("./runtime/nitro/
|
|
99
|
+
handler: resolve("./runtime/nitro/html")
|
|
104
100
|
});
|
|
101
|
+
if (config.runtimeImages) {
|
|
102
|
+
addServerHandler({
|
|
103
|
+
handler: resolve("./runtime/nitro/image")
|
|
104
|
+
});
|
|
105
|
+
}
|
|
105
106
|
}
|
|
106
107
|
addImports({
|
|
107
108
|
name: "defineOgImage",
|
|
@@ -207,4 +208,4 @@ declare module 'nitropack' {
|
|
|
207
208
|
}
|
|
208
209
|
});
|
|
209
210
|
|
|
210
|
-
export { module as default };
|
|
211
|
+
export { HtmlRendererRoute, LinkPrerenderId, MetaOgImageContentPlaceholder, PayloadScriptId, module as default };
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export declare const HtmlRendererRoute = "__og_image";
|
|
2
|
+
export declare const RuntimeImageSuffix = "og-image.png";
|
|
3
|
+
export declare const PayloadScriptId = "nuxt-og-image-payload";
|
|
4
|
+
export declare const MetaOgImageContentPlaceholder = "__NUXT_OG_IMAGE_PLACEHOLDER__";
|
|
5
|
+
export declare const LinkPrerenderId = "nuxt-og-image-screenshot-path";
|
|
1
6
|
export interface OgImagePayload {
|
|
2
7
|
runtime: boolean;
|
|
3
8
|
title: string;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { useServerHead } from "@vueuse/head";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
RuntimeImageSuffix
|
|
8
|
-
} from "../const";
|
|
2
|
+
export const HtmlRendererRoute = "__og_image";
|
|
3
|
+
export const RuntimeImageSuffix = "og-image.png";
|
|
4
|
+
export const PayloadScriptId = "nuxt-og-image-payload";
|
|
5
|
+
export const MetaOgImageContentPlaceholder = "__NUXT_OG_IMAGE_PLACEHOLDER__";
|
|
6
|
+
export const LinkPrerenderId = "nuxt-og-image-screenshot-path";
|
|
9
7
|
export function defineOgImage(options) {
|
|
10
8
|
if (process.server) {
|
|
11
9
|
const router = useRouter();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const HtmlRendererRoute = "__og_image";
|
|
2
|
+
export declare const PayloadScriptId = "nuxt-og-image-payload";
|
|
1
3
|
export declare const extractOgPayload: (html: string) => any;
|
|
2
4
|
export declare const inferOgPayload: (html: string) => Record<string, any>;
|
|
3
5
|
declare const _default: import("h3").EventHandler<string | undefined>;
|
|
@@ -2,7 +2,8 @@ import { withQuery } from "ufo";
|
|
|
2
2
|
import { renderSSRHead } from "@unhead/ssr";
|
|
3
3
|
import { createHeadCore } from "@unhead/vue";
|
|
4
4
|
import { defineEventHandler, getQuery } from "h3";
|
|
5
|
-
|
|
5
|
+
export const HtmlRendererRoute = "__og_image";
|
|
6
|
+
export const PayloadScriptId = "nuxt-og-image-payload";
|
|
6
7
|
export const extractOgPayload = (html) => {
|
|
7
8
|
const payload = html.match(new RegExp(`<script id="${PayloadScriptId}" type="application/json">(.+?)<\/script>`))?.[1];
|
|
8
9
|
if (payload) {
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Browser } from 'playwright';
|
|
3
|
+
import type { ScreenshotOptions } from '../../types';
|
|
4
|
+
export declare const HtmlRendererRoute = "__og_image";
|
|
5
|
+
export declare const RuntimeImageSuffix = "og-image.png";
|
|
6
|
+
export declare function createBrowser(): Promise<Browser>;
|
|
7
|
+
export declare function screenshot(browser: Browser, url: string, options: ScreenshotOptions): Promise<Buffer>;
|
|
8
|
+
declare const _default: import("h3").EventHandler<Buffer | undefined>;
|
|
2
9
|
export default _default;
|
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
import { defineEventHandler, getRequestHeader, setHeader } from "h3";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export const HtmlRendererRoute = "__og_image";
|
|
3
|
+
export const RuntimeImageSuffix = "og-image.png";
|
|
4
|
+
async function createLambdaBrowser() {
|
|
5
|
+
try {
|
|
6
|
+
const playwright = await import("playwright-core");
|
|
7
|
+
const awsChrome = await import("chrome-aws-lambda");
|
|
8
|
+
return await playwright.chromium.launch({
|
|
9
|
+
args: awsChrome.args,
|
|
10
|
+
executablePath: await awsChrome.executablePath,
|
|
11
|
+
headless: awsChrome.headless
|
|
12
|
+
});
|
|
13
|
+
} catch (e) {
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
export async function createBrowser() {
|
|
18
|
+
const lambdaBrowser = await createLambdaBrowser();
|
|
19
|
+
if (lambdaBrowser)
|
|
20
|
+
return lambdaBrowser;
|
|
21
|
+
const playwright = await import("playwright");
|
|
22
|
+
return await playwright.chromium.launch({
|
|
23
|
+
chromiumSandbox: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export async function screenshot(browser, url, options) {
|
|
27
|
+
const page = await browser.newPage({
|
|
28
|
+
colorScheme: options.colorScheme
|
|
29
|
+
});
|
|
30
|
+
await page.setViewportSize({
|
|
31
|
+
width: options.width,
|
|
32
|
+
height: options.height
|
|
33
|
+
});
|
|
34
|
+
await page.goto(url, {
|
|
35
|
+
timeout: 1e4,
|
|
36
|
+
waitUntil: "networkidle"
|
|
37
|
+
});
|
|
38
|
+
if (options.mask) {
|
|
39
|
+
await page.evaluate((mask) => {
|
|
40
|
+
for (const el of document.querySelectorAll(mask))
|
|
41
|
+
el.style.display = "none";
|
|
42
|
+
}, options.mask);
|
|
43
|
+
}
|
|
44
|
+
if (options.selector)
|
|
45
|
+
await page.locator(options.selector).screenshot();
|
|
46
|
+
return await page.screenshot();
|
|
47
|
+
}
|
|
4
48
|
export default defineEventHandler(async (e) => {
|
|
5
49
|
if (!e.path?.endsWith(RuntimeImageSuffix))
|
|
6
50
|
return;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { Browser } from 'playwright';
|
|
3
|
-
import type { ScreenshotOptions } from './types';
|
|
4
|
-
export declare function createBrowser(): Promise<Browser>;
|
|
5
|
-
export declare function screenshot(browser: Browser, url: string, options: ScreenshotOptions): Promise<Buffer>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
async function createLambdaBrowser() {
|
|
2
|
-
try {
|
|
3
|
-
const playwright = await import("playwright-core");
|
|
4
|
-
const awsChrome = await import("chrome-aws-lambda");
|
|
5
|
-
return await playwright.chromium.launch({
|
|
6
|
-
args: awsChrome.args,
|
|
7
|
-
executablePath: await awsChrome.executablePath,
|
|
8
|
-
headless: awsChrome.headless
|
|
9
|
-
});
|
|
10
|
-
} catch (e) {
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
export async function createBrowser() {
|
|
15
|
-
const lambdaBrowser = await createLambdaBrowser();
|
|
16
|
-
if (lambdaBrowser)
|
|
17
|
-
return lambdaBrowser;
|
|
18
|
-
const playwright = await import("playwright");
|
|
19
|
-
return await playwright.chromium.launch({
|
|
20
|
-
chromiumSandbox: true
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
export async function screenshot(browser, url, options) {
|
|
24
|
-
const page = await browser.newPage({
|
|
25
|
-
colorScheme: options.colorScheme
|
|
26
|
-
});
|
|
27
|
-
await page.setViewportSize({
|
|
28
|
-
width: options.width,
|
|
29
|
-
height: options.height
|
|
30
|
-
});
|
|
31
|
-
await page.goto(url, {
|
|
32
|
-
timeout: 1e4,
|
|
33
|
-
waitUntil: "networkidle"
|
|
34
|
-
});
|
|
35
|
-
if (options.mask) {
|
|
36
|
-
await page.evaluate((mask) => {
|
|
37
|
-
for (const el of document.querySelectorAll(mask))
|
|
38
|
-
el.style.display = "none";
|
|
39
|
-
}, options.mask);
|
|
40
|
-
}
|
|
41
|
-
if (options.selector)
|
|
42
|
-
await page.locator(options.selector).screenshot();
|
|
43
|
-
return await page.screenshot();
|
|
44
|
-
}
|
package/dist/runtime/const.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare const HtmlRendererRoute = "__og_image";
|
|
2
|
-
export declare const RuntimeImageSuffix = "og-image.png";
|
|
3
|
-
export declare const PayloadScriptId = "nuxt-og-image-payload";
|
|
4
|
-
export declare const MetaOgImageContentPlaceholder = "__NUXT_OG_IMAGE_PLACEHOLDER__";
|
|
5
|
-
export declare const LinkPrerenderId = "nuxt-og-image-screenshot-path";
|
package/dist/runtime/const.mjs
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export const HtmlRendererRoute = "__og_image";
|
|
2
|
-
export const RuntimeImageSuffix = "og-image.png";
|
|
3
|
-
export const PayloadScriptId = "nuxt-og-image-payload";
|
|
4
|
-
export const MetaOgImageContentPlaceholder = "__NUXT_OG_IMAGE_PLACEHOLDER__";
|
|
5
|
-
export const LinkPrerenderId = "nuxt-og-image-screenshot-path";
|