@tryghost/mg-substack 0.5.0 → 0.6.0

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
@@ -168,8 +168,6 @@ const processContent = (post, siteUrl, options) => {
168
168
  let ogImgSrc = post.data.og_image;
169
169
  let unsizedOgSrc = getUnsizedImageName(ogImgSrc);
170
170
 
171
- // console.log({unsizedFirstSrc, unsizedOgSrc});
172
-
173
171
  if (unsizedFirstSrc === unsizedOgSrc) {
174
172
  if ($(firstElement).find('figcaption').length) {
175
173
  post.data.feature_image_caption = $(firstElement).find('figcaption').html();
@@ -204,21 +202,33 @@ const processContent = (post, siteUrl, options) => {
204
202
  }
205
203
  }
206
204
 
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
- };
205
+ // If we have a podcast URL `posts.csv`, embed an audio card at the start of the document
206
+ // Else, if we have scraped a podcast URL, embed that instead
207
+ if (substackPodcastURL || post.data?.podcast_audio_src) {
208
+ let audioSrc = '';
209
+
210
+ if (substackPodcastURL) {
211
+ debug(`Post ${post.data.slug} has podcast episode from CSV`);
212
+ audioSrc = substackPodcastURL;
213
+ } else if (post.data?.podcast_audio_src) {
214
+ debug(`Post ${post.data.slug} has podcast episode from scrape`);
215
+ audioSrc = post.data.podcast_audio_src;
216
+ }
217
217
 
218
- const buildCard = audioCard.render(cardOpts);
219
- const cardHTML = buildCard.nodeValue;
218
+ if (audioSrc && audioSrc.length > 0) {
219
+ let cardOpts = {
220
+ env: {dom: new SimpleDom.Document()},
221
+ payload: {
222
+ src: audioSrc,
223
+ title: post.data.title
224
+ }
225
+ };
226
+
227
+ const buildCard = audioCard.render(cardOpts);
228
+ const cardHTML = buildCard.nodeValue;
220
229
 
221
- $html('.migrate-substack-wrapper').prepend(cardHTML);
230
+ $html('.migrate-substack-wrapper').prepend(cardHTML);
231
+ }
222
232
  }
223
233
 
224
234
  $html('div.tweet').each((i, el) => {
@@ -396,6 +406,82 @@ const processContent = (post, siteUrl, options) => {
396
406
  $(anchor).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
397
407
  });
398
408
 
409
+ $html('.digest-post-embed').each((i, el) => {
410
+ const attrsRaw = $(el).attr('data-attrs');
411
+ const attrs = JSON.parse(attrsRaw);
412
+
413
+ let theHtml = [];
414
+
415
+ if (attrs.section_name) {
416
+ theHtml.push(`<h6>${attrs.section_name}</h6>`);
417
+ }
418
+
419
+ if (attrs.title) {
420
+ theHtml.push(`<h3>`);
421
+
422
+ if (attrs.canonical_url) {
423
+ theHtml.push(`<a href="${attrs.canonical_url}">`);
424
+ }
425
+
426
+ theHtml.push(attrs.title);
427
+
428
+ if (attrs.canonical_url) {
429
+ theHtml.push(`</a>`);
430
+ }
431
+
432
+ theHtml.push(`</h3>`);
433
+ }
434
+
435
+ if (attrs.publishedBylines.length || attrs.post_date) {
436
+ theHtml.push(`<p>`);
437
+
438
+ if (attrs.publishedBylines) {
439
+ let bylines = [];
440
+
441
+ attrs.publishedBylines.forEach((byline) => {
442
+ bylines.push(byline.name);
443
+ });
444
+
445
+ theHtml.push(bylines.join(', '));
446
+ }
447
+
448
+ if (attrs.publishedBylines.length && attrs.post_date) {
449
+ theHtml.push(` &bull; `);
450
+ }
451
+
452
+ if (attrs.post_date) {
453
+ theHtml.push(new Date(attrs.post_date).toLocaleString('en-US', {month: 'short', day: 'numeric', year: 'numeric'}));
454
+ }
455
+
456
+ theHtml.push(`</p>`);
457
+ }
458
+
459
+ if (attrs.cover_image) {
460
+ if (attrs.canonical_url) {
461
+ theHtml.push(`<a href="${attrs.canonical_url}">`);
462
+ }
463
+
464
+ theHtml.push(`<img src="${attrs.cover_image}" alt="${attrs.cover_image_alt || ''}">`);
465
+
466
+ if (attrs.canonical_url) {
467
+ theHtml.push(`</a>`);
468
+ }
469
+ }
470
+
471
+ if (attrs.caption) {
472
+ theHtml.push(`<p>`);
473
+ theHtml.push(attrs.caption);
474
+
475
+ if (attrs.canonical_url) {
476
+ theHtml.push(`<br><br><a href="${attrs.canonical_url}">Read full story &rarr;</a>`);
477
+ }
478
+
479
+ theHtml.push(`</p>`);
480
+ }
481
+
482
+ $(el).replaceWith(theHtml.join(''));
483
+ });
484
+
399
485
  $html('a > style').each((i, style) => {
400
486
  $(style).remove();
401
487
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
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
  },
@@ -28,15 +28,15 @@
28
28
  "@tryghost/debug": "0.1.27",
29
29
  "@tryghost/errors": "1.3.0",
30
30
  "@tryghost/kg-default-cards": "10.0.2",
31
- "@tryghost/mg-fs-utils": "^0.13.0",
31
+ "@tryghost/mg-fs-utils": "^0.13.1",
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
- "srcset": "5.0.0"
39
+ "srcset": "5.0.1"
40
40
  },
41
- "gitHead": "d0c6f970f484101ab9b4dcf8ba95fa1398da4b79"
41
+ "gitHead": "11cc97db15efc3e19af16253cd53694cf72aa55d"
42
42
  }