nuxt-og-image 2.0.0-beta.5 → 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.5"
8
+ "version": "2.0.0-beta.7"
9
9
  }
package/dist/module.mjs CHANGED
@@ -164,11 +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(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/");
171
- }
174
+ if (typeof value === "string")
175
+ obj[key] = decodeHtml(value);
172
176
  });
173
177
  return obj;
174
178
  }
@@ -192,7 +196,7 @@ function extractOgImageOptions(html) {
192
196
  else
193
197
  options.description = html.match(/<meta name="description" content="(.*?)">/)?.[1];
194
198
  }
195
- return decodeHtmlEntities(options);
199
+ return decodeObjectHtmlEntities(options);
196
200
  }
197
201
  return false;
198
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,8 +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(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/");
5
- }
8
+ if (typeof value === "string")
9
+ obj[key] = decodeHtml(value);
6
10
  });
7
11
  return obj;
8
12
  }
@@ -26,7 +30,7 @@ export function extractOgImageOptions(html) {
26
30
  else
27
31
  options.description = html.match(/<meta name="description" content="(.*?)">/)?.[1];
28
32
  }
29
- return decodeHtmlEntities(options);
33
+ return decodeObjectHtmlEntities(options);
30
34
  }
31
35
  return false;
32
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.5",
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",