nuxt-og-image 0.0.1 → 0.0.2

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.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "bridge": false
6
6
  },
7
7
  "configKey": "ogImage",
8
- "version": "0.0.1"
8
+ "version": "0.0.2"
9
9
  }
@@ -0,0 +1,5 @@
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>;
@@ -0,0 +1,44 @@
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
+ }
@@ -5,7 +5,7 @@ import {
5
5
  MetaOgImageContentPlaceholder,
6
6
  PayloadScriptId,
7
7
  RuntimeImageSuffix
8
- } from "../../const";
8
+ } from "../const";
9
9
  export function defineOgImage(options) {
10
10
  if (process.server) {
11
11
  const router = useRouter();
@@ -0,0 +1,5 @@
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";
@@ -0,0 +1,5 @@
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";
@@ -2,7 +2,7 @@ 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
- import { HtmlRendererRoute, PayloadScriptId } from "../../const";
5
+ import { HtmlRendererRoute, PayloadScriptId } from "../const.mjs";
6
6
  export const extractOgPayload = (html) => {
7
7
  const payload = html.match(new RegExp(`<script id="${PayloadScriptId}" type="application/json">(.+?)<\/script>`))?.[1];
8
8
  if (payload) {
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
- declare const _default: import("h3").EventHandler<Buffer | undefined>;
1
+ declare const _default: import("h3").EventHandler<any>;
3
2
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { defineEventHandler, getRequestHeader, setHeader } from "h3";
2
- import { HtmlRendererRoute, RuntimeImageSuffix } from "../../const";
2
+ import { HtmlRendererRoute, RuntimeImageSuffix } from "../const.mjs";
3
3
  import { createBrowser, screenshot } from "../../browserService";
4
4
  export default defineEventHandler(async (e) => {
5
5
  if (!e.path?.endsWith(RuntimeImageSuffix))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "packageManager": "pnpm@7.8.0",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",