nuxt-og-image 1.5.3 → 1.5.4

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": "1.5.3"
8
+ "version": "1.5.4"
9
9
  }
@@ -1,6 +1,5 @@
1
1
  import { createError, defineEventHandler, getHeaders, getQuery } from "h3";
2
- import { useHostname } from "../utils.mjs";
3
- import { extractOgImageOptions } from "../../../utils";
2
+ import { extractOgImageOptions, useHostname } from "../utils.mjs";
4
3
  import { getRouteRules } from "#internal/nitro";
5
4
  import { defaults } from "#nuxt-og-image/config";
6
5
  export default defineEventHandler(async (e) => {
@@ -0,0 +1,2 @@
1
+ export declare function extractOgImageOptions(html: string): false | Record<string, any>;
2
+ export declare function stripOgImageOptions(html: string): string;
@@ -0,0 +1,33 @@
1
+ function decodeHtmlEntities(obj) {
2
+ Object.entries(obj).forEach(([key, value]) => {
3
+ if (typeof value === "string") {
4
+ obj[key] = value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/");
5
+ }
6
+ });
7
+ return obj;
8
+ }
9
+ export function extractOgImageOptions(html) {
10
+ const htmlPayload = html.match(/<script id="nuxt-og-image-options" type="application\/json">(.+?)<\/script>/)?.[1];
11
+ if (!htmlPayload)
12
+ return false;
13
+ let options;
14
+ try {
15
+ options = JSON.parse(htmlPayload);
16
+ } catch (e) {
17
+ options = false;
18
+ if (process.dev)
19
+ console.warn("Failed to parse #nuxt-og-image-options", e, options);
20
+ }
21
+ if (options) {
22
+ const description = html.match(/<meta property="og:description" content="(.*?)">/)?.[1];
23
+ if (description)
24
+ options.description = description;
25
+ else
26
+ options.description = html.match(/<meta name="description" content="(.*?)">/)?.[1];
27
+ return decodeHtmlEntities(options);
28
+ }
29
+ return false;
30
+ }
31
+ export function stripOgImageOptions(html) {
32
+ return html.replace(/<script id="nuxt-og-image-options" type="application\/json">(.*?)<\/script>/, "");
33
+ }
@@ -14,3 +14,4 @@ export declare function renderIsland(payload: OgImageOptions): Promise<{
14
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
+ export * from './utils-pure';
@@ -89,3 +89,4 @@ export async function readPublicAssetBase64(file) {
89
89
  return `data:${type};base64,${base64}`;
90
90
  }
91
91
  }
92
+ export * from "./utils-pure.mjs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "1.5.3",
4
+ "version": "1.5.4",
5
5
  "packageManager": "pnpm@7.8.0",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",