nuxt-og-image 2.0.0-beta.6 → 2.0.0-beta.7

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": "2.0.0-beta.6"
8
+ "version": "2.0.0-beta.7"
9
9
  }
package/dist/module.mjs CHANGED
@@ -164,13 +164,15 @@ function getBodyJson(req) {
164
164
  });
165
165
  }
166
166
 
167
- function decodeHtmlEntities(obj) {
167
+ function decodeHtml(html) {
168
+ return html.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&cent;/g, "\xA2").replace(/&pound;/g, "\xA3").replace(/&yen;/g, "\xA5").replace(/&euro;/g, "\u20AC").replace(/&copy;/g, "\xA9").replace(/&reg;/g, "\xAE").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/").replace(/&#([0-9]+);/g, (full, int) => {
169
+ return String.fromCharCode(parseInt(int));
170
+ });
171
+ }
172
+ function decodeObjectHtmlEntities(obj) {
168
173
  Object.entries(obj).forEach(([key, value]) => {
169
- if (typeof value === "string") {
170
- obj[key] = value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&cent;/g, "\xA2").replace(/&pound;/g, "\xA3").replace(/&yen;/g, "\xA5").replace(/&euro;/g, "\u20AC").replace(/&copy;/g, "\xA9").replace(/&reg;/g, "\xAE").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/").replace(/&#([0-9]+);/g, (full, int) => {
171
- return String.fromCharCode(parseInt(int));
172
- });
173
- }
174
+ if (typeof value === "string")
175
+ obj[key] = decodeHtml(value);
174
176
  });
175
177
  return obj;
176
178
  }
@@ -194,7 +196,7 @@ function extractOgImageOptions(html) {
194
196
  else
195
197
  options.description = html.match(/<meta name="description" content="(.*?)">/)?.[1];
196
198
  }
197
- return decodeHtmlEntities(options);
199
+ return decodeObjectHtmlEntities(options);
198
200
  }
199
201
  return false;
200
202
  }
@@ -1,9 +1,10 @@
1
1
  import { defineSatoriTransformer } from "../utils.mjs";
2
+ import { decodeHtml } from "../../../utils-pure.mjs";
2
3
  export default defineSatoriTransformer(() => {
3
4
  return {
4
5
  filter: (node) => typeof node.props?.children === "string",
5
6
  transform: async (node) => {
6
- node.props.children = node.props.children.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/");
7
+ node.props.children = decodeHtml(node.props.children);
7
8
  }
8
9
  };
9
10
  });
@@ -1,2 +1,3 @@
1
+ export declare function decodeHtml(html: string): string;
1
2
  export declare function extractOgImageOptions(html: string): false | Record<string, any>;
2
3
  export declare function stripOgImageOptions(html: string): string;
@@ -1,10 +1,12 @@
1
- function decodeHtmlEntities(obj) {
1
+ export function decodeHtml(html) {
2
+ return html.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&cent;/g, "\xA2").replace(/&pound;/g, "\xA3").replace(/&yen;/g, "\xA5").replace(/&euro;/g, "\u20AC").replace(/&copy;/g, "\xA9").replace(/&reg;/g, "\xAE").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/").replace(/&#([0-9]+);/g, (full, int) => {
3
+ return String.fromCharCode(parseInt(int));
4
+ });
5
+ }
6
+ function decodeObjectHtmlEntities(obj) {
2
7
  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(/&cent;/g, "\xA2").replace(/&pound;/g, "\xA3").replace(/&yen;/g, "\xA5").replace(/&euro;/g, "\u20AC").replace(/&copy;/g, "\xA9").replace(/&reg;/g, "\xAE").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/").replace(/&#([0-9]+);/g, (full, int) => {
5
- return String.fromCharCode(parseInt(int));
6
- });
7
- }
8
+ if (typeof value === "string")
9
+ obj[key] = decodeHtml(value);
8
10
  });
9
11
  return obj;
10
12
  }
@@ -28,7 +30,7 @@ export function extractOgImageOptions(html) {
28
30
  else
29
31
  options.description = html.match(/<meta name="description" content="(.*?)">/)?.[1];
30
32
  }
31
- return decodeHtmlEntities(options);
33
+ return decodeObjectHtmlEntities(options);
32
34
  }
33
35
  return false;
34
36
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.6",
4
+ "version": "2.0.0-beta.7",
5
5
  "packageManager": "pnpm@7.8.0",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",