nuxt-og-image 1.4.22 → 1.5.0

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
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "compatibility": {
4
- "nuxt": "^3.1.0",
4
+ "nuxt": "^3.2.0",
5
5
  "bridge": false
6
6
  },
7
7
  "configKey": "ogImage",
8
- "version": "1.4.22"
8
+ "version": "1.5.0"
9
9
  }
package/dist/module.mjs CHANGED
@@ -11,7 +11,7 @@ import sirv from 'sirv';
11
11
  import { pathExists, copy, mkdirp } from 'fs-extra';
12
12
  import { isCI, provider } from 'std-env';
13
13
  import playwrightCore from 'playwright-core';
14
- import { existsSync } from 'fs';
14
+ import { existsSync } from 'node:fs';
15
15
  import { createBirpcGroup } from 'birpc';
16
16
  import { stringify, parse } from 'flatted';
17
17
 
@@ -216,7 +216,7 @@ const module = defineNuxtModule({
216
216
  meta: {
217
217
  name: "nuxt-og-image",
218
218
  compatibility: {
219
- nuxt: "^3.1.0",
219
+ nuxt: "^3.2.0",
220
220
  bridge: false
221
221
  },
222
222
  configKey: "ogImage"
@@ -440,18 +440,18 @@ export async function useProvider(provider) {
440
440
  const captureScreenshots = async () => {
441
441
  if (screenshotQueue.length === 0)
442
442
  return;
443
- if (isCI) {
444
- nitro.logger.info("Ensuring chromium install for og:image generation...");
445
- const installChromeProcess = execa("npx", ["playwright", "install", "chromium"]);
446
- installChromeProcess.stderr?.pipe(process.stderr);
447
- await new Promise((resolve2) => {
448
- installChromeProcess.on("exit", (e) => {
449
- if (e !== 0)
450
- nitro.logger.error("Failed to install Playwright dependency for og:image generation. Trying anyway...");
451
- resolve2(true);
452
- });
443
+ nitro.logger.info("Ensuring chromium install for og:image generation...");
444
+ const installChromeProcess = execa("npx", ["playwright", "install", "chromium"], {
445
+ stdio: "inherit"
446
+ });
447
+ installChromeProcess.stderr?.pipe(process.stderr);
448
+ await new Promise((resolve2) => {
449
+ installChromeProcess.on("exit", (e) => {
450
+ if (e !== 0)
451
+ nitro.logger.error("Failed to install Playwright dependency for og:image generation. Trying anyway...");
452
+ resolve2(true);
453
453
  });
454
- }
454
+ });
455
455
  const previewProcess = execa("npx", ["serve", nitro.options.output.publicDir]);
456
456
  let browser = null;
457
457
  try {
@@ -69,8 +69,10 @@ export function defineOgImage(options = {}) {
69
69
  {
70
70
  id: "nuxt-og-image-options",
71
71
  type: "application/json",
72
- children: () => {
73
- const payload = {};
72
+ innerHTML: () => {
73
+ const payload = {
74
+ title: "%s"
75
+ };
74
76
  Object.entries(options).forEach(([key, val]) => {
75
77
  payload[key.replace(/-([a-z])/g, (g) => g[1].toUpperCase())] = val;
76
78
  });
@@ -1,4 +1,5 @@
1
1
  import { createError, defineEventHandler, getQuery } from "h3";
2
+ import { useHostname } from "../utils.mjs";
2
3
  import { getRouteRules } from "#internal/nitro";
3
4
  import { defaults } from "#nuxt-og-image/config";
4
5
  export function extractOgImageOptions(html) {
@@ -7,11 +8,6 @@ export function extractOgImageOptions(html) {
7
8
  }
8
9
  export const inferOgImageOptions = (html) => {
9
10
  const options = {};
10
- const title = html.match(/<meta property="og:title" content="(.*?)">/)?.[1];
11
- if (title)
12
- options.title = title;
13
- else
14
- options.title = html.match(/<title>(.*?)<\/title>/)?.[1];
15
11
  const description = html.match(/<meta property="og:description" content="(.*?)">/)?.[1];
16
12
  if (description)
17
13
  options.description = description;
@@ -22,7 +18,12 @@ export const inferOgImageOptions = (html) => {
22
18
  export default defineEventHandler(async (e) => {
23
19
  const query = getQuery(e);
24
20
  const path = query.path || "/";
25
- const html = await globalThis.$fetch(path);
21
+ const fetchOptions = process.dev || process.env.prerender ? {} : {
22
+ baseURL: useHostname(e)
23
+ };
24
+ const html = await globalThis.$fetch(path, {
25
+ ...fetchOptions
26
+ });
26
27
  const extractedPayload = extractOgImageOptions(html);
27
28
  if (!extractedPayload) {
28
29
  throw createError({
@@ -1,7 +1,8 @@
1
- import { existsSync, promises as fsp } from "fs";
1
+ import { existsSync, promises as fsp } from "node:fs";
2
2
  import { getQuery, getRequestHeader } from "h3";
3
3
  import { join } from "pathe";
4
4
  import { assetDirs } from "#nuxt-og-image/config";
5
+ import { useRuntimeConfig } from "#internal/nitro";
5
6
  export function wasmLoader(key, fallback, baseUrl) {
6
7
  let promise;
7
8
  let loaded = false;
@@ -36,11 +37,15 @@ export function wasmLoader(key, fallback, baseUrl) {
36
37
  };
37
38
  }
38
39
  export function fetchOptions(e, path) {
40
+ const fetchOptions2 = process.dev || process.env.prerender ? {} : {
41
+ baseURL: useHostname(e)
42
+ };
39
43
  return globalThis.$fetch("/api/og-image-options", {
40
44
  query: {
41
45
  ...getQuery(e),
42
46
  path
43
- }
47
+ },
48
+ ...fetchOptions2
44
49
  });
45
50
  }
46
51
  export function base64ToArrayBuffer(base64) {
@@ -58,10 +63,12 @@ export function renderIsland(payload) {
58
63
  });
59
64
  }
60
65
  export function useHostname(e) {
61
- const host = getRequestHeader(e, "host") || "localhost:3000";
66
+ const host = getRequestHeader(e, "host") || process.env.NITRO_HOST || process.env.HOST || "localhost";
62
67
  const protocol = getRequestHeader(e, "x-forwarded-proto") || "http";
63
68
  const useHttp = process.env.NODE_ENV === "development" || host.includes("127.0.0.1") || host.includes("localhost") || protocol === "http";
64
- return `http${useHttp ? "" : "s"}://${host}`;
69
+ const port = process.env.NITRO_PORT || process.env.PORT;
70
+ const base = useRuntimeConfig().app.baseURL;
71
+ return `http${useHttp ? "" : "s"}://${host}${port ? `:${port}` : ""}${base}`;
65
72
  }
66
73
  const r = (base, key) => {
67
74
  return join(base, key.replace(/:/g, "/"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "1.4.22",
4
+ "version": "1.5.0",
5
5
  "packageManager": "pnpm@7.8.0",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -39,9 +39,9 @@
39
39
  "launch-editor": "^2.6.0",
40
40
  "ohash": "^1.0.0",
41
41
  "pathe": "^1.1.0",
42
- "playwright-core": "^1.31.1",
42
+ "playwright-core": "^1.31.2",
43
43
  "radix3": "^1.0.0",
44
- "satori": "0.4.0",
44
+ "satori": "0.4.1",
45
45
  "satori-html": "^0.3.2",
46
46
  "sirv": "^2.0.2",
47
47
  "std-env": "^3.3.2",
@@ -53,8 +53,8 @@
53
53
  "yoga-wasm-web": "^0.3.2"
54
54
  },
55
55
  "devDependencies": {
56
- "@antfu/eslint-config": "^0.35.3",
57
- "@nuxt/devtools-edge": "0.2.5-27960426.f03ce21",
56
+ "@antfu/eslint-config": "^0.36.0",
57
+ "@nuxt/devtools-edge": "0.2.5-27969823.df4a35f",
58
58
  "@nuxt/module-builder": "^0.2.1",
59
59
  "@nuxt/test-utils": "3.2.3",
60
60
  "@nuxtjs/eslint-config-typescript": "^12.0.0",
@@ -62,7 +62,7 @@
62
62
  "bumpp": "^9.0.0",
63
63
  "eslint": "8.35.0",
64
64
  "nuxt": "^3.2.3",
65
- "puppeteer": "^19.7.2",
65
+ "puppeteer": "^19.7.3",
66
66
  "vitest": "^0.29.2"
67
67
  },
68
68
  "scripts": {