@tryghost/mg-substack 0.2.3 → 0.2.5

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.
Files changed (2) hide show
  1. package/lib/process.js +10 -2
  2. package/package.json +6 -5
package/lib/process.js CHANGED
@@ -5,6 +5,7 @@ import $ from 'cheerio';
5
5
  import errors from '@tryghost/errors';
6
6
  import SimpleDom from 'simple-dom';
7
7
  import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';
8
+ import {decode} from 'html-entities';
8
9
 
9
10
  const getFiles = async (filePath) => {
10
11
  let filenames = await fs.readdir(filePath);
@@ -69,7 +70,7 @@ const processContent = (post, siteUrl, options) => {
69
70
  if (responseData?.og_image) {
70
71
  let firstElement = $html('body *').first();
71
72
 
72
- if (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img' || $(firstElement).find('img').length) {
73
+ if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
73
74
  let theElementItself = (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img') ? firstElement : $(firstElement).find('img');
74
75
  let firstImgSrc = $(theElementItself).attr('src');
75
76
 
@@ -282,7 +283,14 @@ const processContent = (post, siteUrl, options) => {
282
283
  }
283
284
 
284
285
  $html('.embedded-post-wrap').each((i, div) => {
285
- let bookmarkJSON = JSON.parse($(div).attr('data-attrs').replace(/"/gm, '"'));
286
+ const attrs = $(div).attr('data-attrs') || false;
287
+
288
+ if (!attrs) {
289
+ return;
290
+ }
291
+
292
+ // CASE: Some embedded posts are double-encoded, so we need to decode twice
293
+ let bookmarkJSON = JSON.parse(decode(decode(attrs)));
286
294
 
287
295
  let bookmarkLink = bookmarkJSON.url;
288
296
  let bookmarkPubName = bookmarkJSON.publication_name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -20,18 +20,19 @@
20
20
  "access": "public"
21
21
  },
22
22
  "devDependencies": {
23
- "eslint": "8.25.0",
24
- "jest": "29.2.1",
23
+ "eslint": "8.26.0",
24
+ "jest": "29.2.2",
25
25
  "jest-extended": "3.1.0"
26
26
  },
27
27
  "dependencies": {
28
28
  "@tryghost/errors": "1.2.18",
29
29
  "@tryghost/kg-default-cards": "5.18.5",
30
- "@tryghost/mg-fs-utils": "^0.10.3",
30
+ "@tryghost/mg-fs-utils": "^0.11.0",
31
31
  "@tryghost/string": "0.2.1",
32
32
  "date-fns": "2.29.3",
33
+ "html-entities": "2.3.3",
33
34
  "lodash": "4.17.21",
34
35
  "simple-dom": "1.4.0"
35
36
  },
36
- "gitHead": "001ab9a8a73dd714fb15220efbe8add099780d11"
37
+ "gitHead": "49293c6abb8c3d32ff2d7c97b90fbea25fe4a4ef"
37
38
  }