@tryghost/mg-substack 0.7.4 → 0.7.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 +27 -23
  2. package/package.json +2 -2
package/lib/process.js CHANGED
@@ -36,10 +36,16 @@ const readFiles = async (files, postsDir) => {
36
36
  return postContent;
37
37
  };
38
38
 
39
- const largeImageUrl = (src) => {
40
- src = src.replace(/w_[0-9]{2,5},h_[0-9]{2,5}/, 'w_2000,h_2000');
41
- src = src.replace(',c_fill,', ',');
42
- return src;
39
+ const largeImageUrl = (path) => {
40
+ if (path.includes('https://substackcdn.com/image/fetch/')) {
41
+ path = decodeURIComponent(path.split('/').pop());
42
+ }
43
+
44
+ if (path.includes('https://bucketeer-')) {
45
+ path = path.replace(/https:\/\/.*.s3.amazonaws.com/gmi, 'https://substack-post-media.s3.amazonaws.com');
46
+ }
47
+
48
+ return path;
43
49
  };
44
50
 
45
51
  const getUnsizedImageName = (str) => {
@@ -117,22 +123,6 @@ const processContent = (post, siteUrl, options) => {
117
123
  $(el).replaceWith('<!--members-only-->');
118
124
  });
119
125
 
120
- // Convert bucketeer image paths
121
- $html('a[href^="https://bucketeer-"], img[src^="https://bucketeer-"]').each((i, el) => {
122
- const href = $(el).attr('href') ?? false;
123
- const src = $(el).attr('src') ?? false;
124
-
125
- const prependString = 'https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/';
126
-
127
- if (href) {
128
- $(el).attr('href', `${prependString}${encodeURI(href)}`);
129
- }
130
-
131
- if (src) {
132
- $(el).attr('src', `${prependString}${encodeURI(src)}`);
133
- }
134
- });
135
-
136
126
  // Empty text elements are commonplace and are not needed
137
127
  $html('p').each((i, el) => {
138
128
  let content = $(el).html().trim();
@@ -149,7 +139,7 @@ const processContent = (post, siteUrl, options) => {
149
139
  let cardOpts = {
150
140
  env: {dom: new SimpleDom.Document()},
151
141
  payload: {
152
- src: attrsObj.src,
142
+ src: largeImageUrl(attrsObj.src),
153
143
  alt: attrsObj.title,
154
144
  caption: attrsObj.title
155
145
  }
@@ -305,7 +295,7 @@ const processContent = (post, siteUrl, options) => {
305
295
 
306
296
  items.push({
307
297
  fileName: basename(item.src),
308
- src: item.src,
298
+ src: largeImageUrl(item.src),
309
299
  width: (dimensions) ? dimensions.width : '100',
310
300
  height: (dimensions) ? dimensions.height : '100'
311
301
  });
@@ -446,7 +436,7 @@ const processContent = (post, siteUrl, options) => {
446
436
  url: postUrl,
447
437
  title: postTitle,
448
438
  description: postCaption,
449
- icon: postIcon,
439
+ icon: largeImageUrl(postIcon),
450
440
  thumbnail: postImage,
451
441
  publisher: postPubName,
452
442
  author: postAuthor
@@ -653,6 +643,20 @@ const processContent = (post, siteUrl, options) => {
653
643
  $(el).replaceWith($figure);
654
644
  });
655
645
 
646
+ // For each image and link, alter the path to remove cropping & sizing for image paths
647
+ $html('img[src], a[href]').each((i, el) => {
648
+ const src = $(el).attr('src');
649
+ const href = $(el).attr('href');
650
+
651
+ if (src) {
652
+ $(el).attr('src', largeImageUrl(src));
653
+ }
654
+
655
+ if (href) {
656
+ $(el).attr('href', largeImageUrl(href));
657
+ }
658
+ });
659
+
656
660
  // convert HTML back to a string
657
661
  html = $html('.migrate-substack-wrapper').html();
658
662
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -37,5 +37,5 @@
37
37
  "simple-dom": "1.4.0",
38
38
  "srcset": "5.0.1"
39
39
  },
40
- "gitHead": "f0a0ccbcebbcb12911381dd182782a084e3c82fb"
40
+ "gitHead": "b1dc78a40763f430c0d33ba0b9c54989d7d645b4"
41
41
  }