@tryghost/mg-substack 0.5.1 → 0.6.1

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/README.md CHANGED
@@ -34,6 +34,10 @@ A more complex command for a Substack migration looks like this:
34
34
  migrate substack --pathToZip /path/to/my-export.zip --url https://example.com --email 'person@example.com' --drafts false
35
35
  ```
36
36
 
37
+ ```sh
38
+ migrate substack --pathToZip /path/to/my-export.zip --url https://example.com --posts false --pages false --podcasts false --threads true
39
+ ```
40
+
37
41
  It's possible to pass more options, in order to achieve a better migration file for Ghost:
38
42
 
39
43
  - **`--pathToZip`** (required)
@@ -70,12 +74,18 @@ It's possible to pass more options, in order to achieve a better migration file
70
74
  - **`--addAccessTag`**
71
75
  - Add #substack-{access} tag to migrated content (public, paid, etc)
72
76
  - bool - default: `true`
77
+ - **`--posts`**
78
+ - Import posts
79
+ - bool - default: `true`
73
80
  - **`--drafts`**
74
81
  - Import draft posts
75
82
  - bool - default: `true`
76
83
  - **`--pages`**
77
84
  - Import pages
78
85
  - bool - default: `true`
86
+ - **`--podcasts`**
87
+ - Import podcasts
88
+ - bool - default: `true`
79
89
  - **`--threads`**
80
90
  - Import threads
81
91
  - bool - default: `false`
package/lib/mapper.js CHANGED
@@ -140,6 +140,11 @@ export default async (input, options) => {
140
140
  // Reassign the CSV array to input var
141
141
  input = input.meta;
142
142
 
143
+ if (!options.posts) {
144
+ debug(`Ignoring posts`);
145
+ input = input.filter(data => data.type.toLowerCase() !== `newsletter`);
146
+ }
147
+
143
148
  if (!options.drafts) {
144
149
  debug(`Ignoring drafts`);
145
150
  input = input.filter(data => data.is_published.toLowerCase() === `true`);
@@ -155,6 +160,11 @@ export default async (input, options) => {
155
160
  input = input.filter(data => data.type.toLowerCase() !== `thread`);
156
161
  }
157
162
 
163
+ if (!options.podcasts) {
164
+ debug(`Ignoring podcasts`);
165
+ input = input.filter(data => data.type.toLowerCase() !== `podcast`);
166
+ }
167
+
158
168
  if (options.postsBefore && options.postsAfter) {
159
169
  const startDate = parseISO(formatISO(new Date(options.postsAfter)));
160
170
  const endDate = add(parseISO(formatISO(new Date(options.postsBefore))), {
package/lib/process.js CHANGED
@@ -36,7 +36,9 @@ const readFiles = async (files, postsDir) => {
36
36
  };
37
37
 
38
38
  const largeImageUrl = (src) => {
39
- return src.replace(/w_[0-9]{2,5},h_[0-9]{2,5}/, 'w_2000,h_2000');
39
+ src = src.replace(/w_[0-9]{2,5},h_[0-9]{2,5}/, 'w_2000,h_2000');
40
+ src = src.replace(',c_fill,', ',');
41
+ return src;
40
42
  };
41
43
 
42
44
  const getUnsizedImageName = (str) => {
@@ -168,8 +170,6 @@ const processContent = (post, siteUrl, options) => {
168
170
  let ogImgSrc = post.data.og_image;
169
171
  let unsizedOgSrc = getUnsizedImageName(ogImgSrc);
170
172
 
171
- // console.log({unsizedFirstSrc, unsizedOgSrc});
172
-
173
173
  if (unsizedFirstSrc === unsizedOgSrc) {
174
174
  if ($(firstElement).find('figcaption').length) {
175
175
  post.data.feature_image_caption = $(firstElement).find('figcaption').html();
@@ -204,21 +204,33 @@ const processContent = (post, siteUrl, options) => {
204
204
  }
205
205
  }
206
206
 
207
- // If we have a podcast URL, embed an audio card at the start of the document
208
- if (substackPodcastURL) {
209
- debug(`Post ${post.data.slug} has podcast episode`);
210
- let cardOpts = {
211
- env: {dom: new SimpleDom.Document()},
212
- payload: {
213
- src: substackPodcastURL,
214
- title: post.data.title
215
- }
216
- };
207
+ // If we have a podcast URL `posts.csv`, embed an audio card at the start of the document
208
+ // Else, if we have scraped a podcast URL, embed that instead
209
+ if (substackPodcastURL || post.data?.podcast_audio_src) {
210
+ let audioSrc = '';
211
+
212
+ if (substackPodcastURL) {
213
+ debug(`Post ${post.data.slug} has podcast episode from CSV`);
214
+ audioSrc = substackPodcastURL;
215
+ } else if (post.data?.podcast_audio_src) {
216
+ debug(`Post ${post.data.slug} has podcast episode from scrape`);
217
+ audioSrc = post.data.podcast_audio_src;
218
+ }
217
219
 
218
- const buildCard = audioCard.render(cardOpts);
219
- const cardHTML = buildCard.nodeValue;
220
+ if (audioSrc && audioSrc.length > 0) {
221
+ let cardOpts = {
222
+ env: {dom: new SimpleDom.Document()},
223
+ payload: {
224
+ src: audioSrc,
225
+ title: post.data.title
226
+ }
227
+ };
220
228
 
221
- $html('.migrate-substack-wrapper').prepend(cardHTML);
229
+ const buildCard = audioCard.render(cardOpts);
230
+ const cardHTML = buildCard.nodeValue;
231
+
232
+ $html('.migrate-substack-wrapper').prepend(cardHTML);
233
+ }
222
234
  }
223
235
 
224
236
  $html('div.tweet').each((i, el) => {
@@ -712,5 +724,6 @@ export default async (input, ctx) => {
712
724
 
713
725
  export {
714
726
  processContent,
715
- getImageDimensions
727
+ getImageDimensions,
728
+ largeImageUrl
716
729
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -20,23 +20,23 @@
20
20
  "access": "public"
21
21
  },
22
22
  "devDependencies": {
23
- "eslint": "8.56.0",
23
+ "eslint": "8.57.0",
24
24
  "jest": "29.7.0",
25
25
  "jest-extended": "4.0.2"
26
26
  },
27
27
  "dependencies": {
28
28
  "@tryghost/debug": "0.1.27",
29
- "@tryghost/errors": "1.3.0",
30
- "@tryghost/kg-default-cards": "10.0.2",
31
- "@tryghost/mg-fs-utils": "^0.13.0",
29
+ "@tryghost/errors": "1.3.1",
30
+ "@tryghost/kg-default-cards": "10.0.3",
31
+ "@tryghost/mg-fs-utils": "^0.13.2",
32
32
  "@tryghost/string": "0.2.11",
33
33
  "cheerio": "1.0.0-rc.12",
34
34
  "date-fns": "2.30.0",
35
35
  "he": "1.2.0",
36
- "html-entities": "2.4.0",
36
+ "html-entities": "2.5.2",
37
37
  "lodash": "4.17.21",
38
38
  "simple-dom": "1.4.0",
39
39
  "srcset": "5.0.1"
40
40
  },
41
- "gitHead": "db762af916ae75789b139f59220b621ec9d732c7"
41
+ "gitHead": "6d66ced5547ace4095b32d0662b158b119a44fa9"
42
42
  }