@tryghost/mg-substack 0.3.14 → 0.3.16

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 +18 -6
  2. package/package.json +7 -7
package/lib/process.js CHANGED
@@ -34,6 +34,10 @@ const readFiles = async (files, postsDir) => {
34
34
  return postContent;
35
35
  };
36
36
 
37
+ const largeImageUrl = (src) => {
38
+ return src.replace(/w_[0-9]{2,5},h_[0-9]{2,5}/, 'w_2000,h_2000');
39
+ };
40
+
37
41
  const getUnsizedImageName = (str) => {
38
42
  const noSizeRegex = /(.*)(_[0-9]{1,4}x[0-9]{1,4}.[a-z]{2,4})/gmi;
39
43
  let srcParts = str.split(/\/|%2F/);
@@ -48,8 +52,12 @@ const getUnsizedImageName = (str) => {
48
52
  };
49
53
 
50
54
  const largestSrc = ($imageElem) => {
51
- const src = $imageElem.attr('src');
52
- const srcset = $imageElem.attr('srcset') || false;
55
+ const src = $imageElem.attr('src') ?? false;
56
+ const srcset = $imageElem.attr('srcset') ?? false;
57
+
58
+ if (!src || !src.length) {
59
+ return '';
60
+ }
53
61
 
54
62
  let srcToUse = src;
55
63
 
@@ -68,8 +76,8 @@ const largestSrc = ($imageElem) => {
68
76
  };
69
77
 
70
78
  const processContent = (post, siteUrl, options) => {
71
- const {substackPodcastURL, metaData} = post;
72
- const responseData = metaData?.responseData || {};
79
+ const {substackPodcastURL} = post;
80
+ const {useMetaImage} = options;
73
81
 
74
82
  let html = post.data?.html;
75
83
 
@@ -95,7 +103,11 @@ const processContent = (post, siteUrl, options) => {
95
103
  });
96
104
 
97
105
  // We use the `'og:image` as the feature image. If the first item in the content is an image and is the same as the `og:image`, remove it
98
- if (responseData?.og_image) {
106
+ if (post.data?.og_image) {
107
+ if (useMetaImage) {
108
+ post.data.feature_image = largeImageUrl(post.data.og_image);
109
+ }
110
+
99
111
  let firstElement = $html('body *').first();
100
112
 
101
113
  if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
@@ -105,7 +117,7 @@ const processContent = (post, siteUrl, options) => {
105
117
  if (firstImgSrc.length > 0) {
106
118
  let unsizedFirstSrc = getUnsizedImageName(firstImgSrc);
107
119
 
108
- let ogImgSrc = responseData.og_image;
120
+ let ogImgSrc = post.data.og_image;
109
121
  let unsizedOgSrc = getUnsizedImageName(ogImgSrc);
110
122
 
111
123
  if (unsizedFirstSrc === unsizedOgSrc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -20,21 +20,21 @@
20
20
  "access": "public"
21
21
  },
22
22
  "devDependencies": {
23
- "eslint": "8.40.0",
23
+ "eslint": "8.44.0",
24
24
  "jest": "29.5.0",
25
25
  "jest-extended": "3.2.4"
26
26
  },
27
27
  "dependencies": {
28
28
  "@tryghost/debug": "0.1.25",
29
- "@tryghost/errors": "1.2.24",
29
+ "@tryghost/errors": "1.2.25",
30
30
  "@tryghost/kg-default-cards": "9.1.0",
31
- "@tryghost/mg-fs-utils": "^0.12.12",
32
- "@tryghost/string": "0.2.6",
31
+ "@tryghost/mg-fs-utils": "^0.12.14",
32
+ "@tryghost/string": "0.2.7",
33
33
  "date-fns": "2.30.0",
34
- "html-entities": "2.3.3",
34
+ "html-entities": "2.4.0",
35
35
  "lodash": "4.17.21",
36
36
  "simple-dom": "1.4.0",
37
37
  "srcset": "5.0.0"
38
38
  },
39
- "gitHead": "36b15a65cacdbb4002c195b06a434cb9742349b6"
39
+ "gitHead": "858b985d1e54eaf41b3a53dbccdc074b57246f9c"
40
40
  }