@tryghost/mg-substack 1.8.0 → 1.10.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
@@ -147,8 +147,8 @@ pnpm dev substack <pathToZip>
147
147
 
148
148
  ## Test
149
149
 
150
- - `pnpm lint` run just eslint
151
- - `pnpm test` run lint and tests
150
+ - `pnpm test` runs the package tests
151
+ - Linting and formatting are run from the repo root (`pnpm lint`, `pnpm format`)
152
152
 
153
153
 
154
154
  # Copyright & License
package/index.js CHANGED
@@ -5,7 +5,7 @@ import process from './lib/process.js';
5
5
 
6
6
  const parseString = fsUtils.csv.parseString;
7
7
 
8
- const ingest = async (ctx) => {
8
+ const ingest = async ctx => {
9
9
  // Extract the ZIP file
10
10
  let zipContent = readZip(ctx.options.pathToZip);
11
11
 
@@ -26,6 +26,4 @@ export default {
26
26
  process
27
27
  };
28
28
 
29
- export {
30
- contentStats
31
- };
29
+ export {contentStats};
package/lib/mapper.js CHANGED
@@ -13,7 +13,7 @@ const mapConfig = (data, options) => {
13
13
 
14
14
  const typeSlug = slugify(data.type);
15
15
 
16
- const contentType = (typeSlug === 'page') ? 'page' : 'post';
16
+ const contentType = typeSlug === 'page' ? 'page' : 'post';
17
17
 
18
18
  const mappedData = {
19
19
  url: `${url}/p/${slug}`,
@@ -27,7 +27,7 @@ const mapConfig = (data, options) => {
27
27
  updated_at: data.post_date || dateNow,
28
28
  created_at: data.post_date || dateNow,
29
29
  title: data.title || slug,
30
- custom_excerpt: (data.subtitle) ? he.decode(data.subtitle) : null,
30
+ custom_excerpt: data.subtitle ? he.decode(data.subtitle) : null,
31
31
  type: contentType,
32
32
  html: data.html || null,
33
33
  status: data.is_published.toLowerCase() === `true` ? 'published' : 'draft',
@@ -44,9 +44,7 @@ const mapConfig = (data, options) => {
44
44
  data: {
45
45
  email: email,
46
46
  slug: authorSlug,
47
- roles: [
48
- 'Contributor'
49
- ]
47
+ roles: ['Contributor']
50
48
  }
51
49
  };
52
50
  }
@@ -74,14 +72,29 @@ export default async (input, options) => {
74
72
 
75
73
  // Drive from HTML files we have, pulling in CSV metadata for each
76
74
  const csvMeta = input.meta;
77
- input = input.posts.map((htmlPost) => {
78
- const postId = htmlPost.name.replace(/\.html$/, '');
79
- const meta = csvMeta.find(item => item.post_id === postId);
80
- if (meta) {
81
- meta.html = htmlPost.html;
82
- }
83
- return meta;
84
- }).filter(Boolean);
75
+ const htmlPosts = input.posts;
76
+ input = htmlPosts
77
+ .map(htmlPost => {
78
+ const postId = htmlPost.name.replace(/\.html$/, '');
79
+ const meta = csvMeta.find(item => item.post_id === postId);
80
+ if (meta) {
81
+ meta.html = htmlPost.html;
82
+ }
83
+ return meta;
84
+ })
85
+ .filter(Boolean);
86
+
87
+ // The migration is driven from the HTML files in the export, so any post listed
88
+ // in the CSV without a matching HTML file is skipped - often the most recent
89
+ // posts, whose HTML can be missing from a Substack export. Warn (without stopping
90
+ // the migration) so these dropped posts aren't a silent surprise.
91
+ const skippedPostCount = csvMeta.length - input.length;
92
+ if (skippedPostCount > 0) {
93
+ // eslint-disable-next-line no-console
94
+ console.warn(
95
+ `Warning: ${skippedPostCount} of ${csvMeta.length} posts in the CSV have no matching HTML file in the export and will be skipped (${htmlPosts.length} HTML files found).`
96
+ );
97
+ }
85
98
 
86
99
  // Preserve consistent ordering (chronological, with numeric ID as tiebreaker)
87
100
  input.sort((a, b) => {
@@ -122,8 +135,8 @@ export default async (input, options) => {
122
135
  const endDate = new Date(new Date(options.postsBefore).setDate(new Date(options.postsBefore).getDate() + 1));
123
136
  debug(`Getting posts between ${startDate} and ${endDate}`);
124
137
 
125
- await input.forEach((data) => {
126
- if ((new Date(data.post_date) > startDate) && (new Date(data.post_date) < endDate)) {
138
+ await input.forEach(data => {
139
+ if (new Date(data.post_date) > startDate && new Date(data.post_date) < endDate) {
127
140
  output.posts.push(mapConfig(data, options));
128
141
  }
129
142
  });
@@ -131,8 +144,8 @@ export default async (input, options) => {
131
144
  const startDate = new Date(options.postsAfter);
132
145
  debug(`Getting posts after ${startDate}`);
133
146
 
134
- await input.forEach((data) => {
135
- if ((new Date(data.post_date) > startDate)) {
147
+ await input.forEach(data => {
148
+ if (new Date(data.post_date) > startDate) {
136
149
  output.posts.push(mapConfig(data, options));
137
150
  }
138
151
  });
@@ -140,14 +153,14 @@ export default async (input, options) => {
140
153
  const endDate = new Date(new Date(options.postsBefore).setDate(new Date(options.postsBefore).getDate() + 1));
141
154
  debug(`Getting posts until ${endDate}`);
142
155
 
143
- await input.forEach((data) => {
156
+ await input.forEach(data => {
144
157
  if (new Date(data.post_date) < endDate) {
145
158
  output.posts.push(mapConfig(data, options));
146
159
  }
147
160
  });
148
161
  } else {
149
162
  debug(`Getting all posts`);
150
- await input.forEach((data) => {
163
+ await input.forEach(data => {
151
164
  output.posts.push(mapConfig(data, options));
152
165
  });
153
166
  }
package/lib/process.js CHANGED
@@ -22,13 +22,13 @@ const galleryCard = cardUtils.getCard('gallery');
22
22
  const bookmarkCard = cardUtils.getCard('bookmark');
23
23
  const fileCard = cardUtils.getCard('file');
24
24
 
25
- const getFiles = async (filePath) => {
25
+ const getFiles = async filePath => {
26
26
  let filenames = await fs.readdir(filePath);
27
27
 
28
28
  return filenames.filter(filename => filename.match(/\.html/));
29
29
  };
30
30
 
31
- const readContent = async (filePath) => {
31
+ const readContent = async filePath => {
32
32
  return fs.readFile(filePath, 'utf-8');
33
33
  };
34
34
 
@@ -43,7 +43,7 @@ const readFiles = async (files, postsDir) => {
43
43
  return postContent;
44
44
  };
45
45
 
46
- const largeImageUrl = (path) => {
46
+ const largeImageUrl = path => {
47
47
  const substackCdnUrl = URL.parse(path);
48
48
  if (substackCdnUrl?.hostname === 'substackcdn.com' && substackCdnUrl.pathname.startsWith('/image/fetch/')) {
49
49
  path = decodeURIComponent(path.split('/').pop());
@@ -51,26 +51,33 @@ const largeImageUrl = (path) => {
51
51
 
52
52
  const bucketeerUrl = URL.parse(path);
53
53
  if (bucketeerUrl?.hostname.startsWith('bucketeer-')) {
54
- path = path.replace(/https:\/\/.*\.s3\.amazonaws\.com/gmi, 'https://substack-post-media.s3.amazonaws.com');
54
+ path = path.replace(/https:\/\/[^/]*\.s3\.amazonaws\.com/gim, 'https://substack-post-media.s3.amazonaws.com');
55
55
  }
56
56
 
57
57
  return path;
58
58
  };
59
59
 
60
- const getUnsizedImageName = (str) => {
61
- const noSizeRegex = /(.*)(_[0-9]{1,4}x[0-9]{1,4}.[a-z]{2,4})/gmi;
60
+ const getUnsizedImageName = str => {
61
+ // Match the size suffix (e.g. `_1200x800.jpg`) directly rather than with a
62
+ // leading `(.*)` capture, which is vulnerable to polynomial backtracking.
63
+ const sizeSuffixRegex = /_[0-9]{1,4}x[0-9]{1,4}.[a-z]{2,4}/gi;
62
64
  let srcParts = str.split(/\/|%2F/);
63
65
  let last = srcParts.slice(-1)[0];
64
- let matches = noSizeRegex.exec(last);
65
66
 
66
- if (matches) {
67
- return matches[1];
67
+ // Greedy `(.*)` settled on the last occurrence, so mirror that here
68
+ let lastMatch = null;
69
+ for (const match of last.matchAll(sizeSuffixRegex)) {
70
+ lastMatch = match;
71
+ }
72
+
73
+ if (lastMatch) {
74
+ return last.slice(0, lastMatch.index);
68
75
  } else {
69
76
  return str;
70
77
  }
71
78
  };
72
79
 
73
- const getImageDimensions = (str) => {
80
+ const getImageDimensions = str => {
74
81
  const imageSizeRegexp = /_([0-9]{2,5})x([0-9]{2,5}).[a-zA-Z]{2,4}/;
75
82
  const matches = str.match(imageSizeRegexp);
76
83
 
@@ -84,7 +91,7 @@ const getImageDimensions = (str) => {
84
91
  }
85
92
  };
86
93
 
87
- const largestSrc = (imageElem) => {
94
+ const largestSrc = imageElem => {
88
95
  const src = attr(imageElem, 'src');
89
96
  const srcset = attr(imageElem, 'srcset');
90
97
 
@@ -125,12 +132,12 @@ const processContent = (post, siteUrl, options) => {
125
132
  const parsed = parseFragment(`<div class="migrate-substack-wrapper">${html}</div>`);
126
133
 
127
134
  // Change paywall card to comment
128
- parsed.$('.paywall-jump').forEach((el) => {
135
+ parsed.$('.paywall-jump').forEach(el => {
129
136
  replaceWith(el, '<!--members-only-->');
130
137
  });
131
138
 
132
139
  // Empty text elements are commonplace and are not needed
133
- parsed.$('p').forEach((el) => {
140
+ parsed.$('p').forEach(el => {
134
141
  let content = serializeChildren(el).trim();
135
142
 
136
143
  if (content.length === 0) {
@@ -138,26 +145,28 @@ const processContent = (post, siteUrl, options) => {
138
145
  }
139
146
  });
140
147
 
141
- parsed.$('h1 strong, h2 strong, h3 strong, h4 strong, h5 strong, h6 strong, h1 b, h2 b, h3 b, h4 b, h5 b, h6 b').forEach((el) => {
142
- replaceWith(el, serializeChildren(el));
143
- });
148
+ parsed
149
+ .$('h1 strong, h2 strong, h3 strong, h4 strong, h5 strong, h6 strong, h1 b, h2 b, h3 b, h4 b, h5 b, h6 b')
150
+ .forEach(el => {
151
+ replaceWith(el, serializeChildren(el));
152
+ });
144
153
 
145
154
  // Wrap these in a HTML card so they can be handled by publishers as needed
146
- parsed.$('div.latex-rendered').forEach((el) => {
155
+ parsed.$('div.latex-rendered').forEach(el => {
147
156
  insertBefore(el, '<!--kg-card-begin: html-->');
148
157
  insertAfter(el, '<!--kg-card-end: html-->');
149
158
  });
150
159
 
151
160
  // We don't currently handle these, so remove them to clean up the document
152
- parsed.$('div.native-video-embed').forEach((el) => {
161
+ parsed.$('div.native-video-embed').forEach(el => {
153
162
  el.remove();
154
163
  });
155
164
 
156
- parsed.$('div.poll-embed').forEach((el) => {
165
+ parsed.$('div.poll-embed').forEach(el => {
157
166
  el.remove();
158
167
  });
159
168
 
160
- parsed.$('.image3').forEach((el) => {
169
+ parsed.$('.image3').forEach(el => {
161
170
  const attrs = attr(el, 'data-attrs');
162
171
  const attrsObj = JSON.parse(attrs);
163
172
 
@@ -197,7 +206,9 @@ const processContent = (post, siteUrl, options) => {
197
206
 
198
207
  if (unsizedFirstSrc === unsizedOgSrc) {
199
208
  if (parsed.$('figcaption', firstElement).length) {
200
- post.data.feature_image_caption = serializeChildren(parsed.$('figcaption', firstElement)[0]);
209
+ post.data.feature_image_caption = serializeChildren(
210
+ parsed.$('figcaption', firstElement)[0]
211
+ );
201
212
  }
202
213
 
203
214
  firstElement.remove();
@@ -225,7 +236,9 @@ const processContent = (post, siteUrl, options) => {
225
236
  post.data.feature_image = unsizedFirstSrc;
226
237
 
227
238
  if (parsed.$('figcaption', firstElement).length) {
228
- post.data.feature_image_caption = serializeChildren(parsed.$('figcaption', firstElement)[0]);
239
+ post.data.feature_image_caption = serializeChildren(
240
+ parsed.$('figcaption', firstElement)[0]
241
+ );
229
242
  }
230
243
 
231
244
  firstElement.remove();
@@ -265,7 +278,7 @@ const processContent = (post, siteUrl, options) => {
265
278
  }
266
279
  }
267
280
 
268
- parsed.$('div.tweet').forEach((el) => {
281
+ parsed.$('div.tweet').forEach(el => {
269
282
  let childAnchors = parsed.$(':scope > a', el);
270
283
  let src = attr(childAnchors[0], 'href');
271
284
  let parsedUrl = url.parse(src);
@@ -317,20 +330,20 @@ const processContent = (post, siteUrl, options) => {
317
330
  replaceWith(el, tweetHtml);
318
331
  });
319
332
 
320
- parsed.$('.image-gallery-embed').forEach((el) => {
333
+ parsed.$('.image-gallery-embed').forEach(el => {
321
334
  const attrs = attr(el, 'data-attrs');
322
335
  const attrsObj = JSON.parse(attrs);
323
336
 
324
337
  let items = [];
325
338
 
326
- attrsObj.gallery.images.forEach((item) => {
339
+ attrsObj.gallery.images.forEach(item => {
327
340
  const dimensions = getImageDimensions(item.src);
328
341
 
329
342
  items.push({
330
343
  fileName: basename(item.src),
331
344
  src: largeImageUrl(item.src),
332
- width: (dimensions) ? dimensions.width : '100',
333
- height: (dimensions) ? dimensions.height : '100'
345
+ width: dimensions ? dimensions.width : '100',
346
+ height: dimensions ? dimensions.height : '100'
334
347
  });
335
348
  });
336
349
 
@@ -352,17 +365,17 @@ const processContent = (post, siteUrl, options) => {
352
365
  replaceWith(el, serializer.serialize(galleryCard.render(cardOpts)));
353
366
  });
354
367
 
355
- parsed.$('[class*="ImageGallery-module__imageGallery"]').forEach((el) => {
368
+ parsed.$('[class*="ImageGallery-module__imageGallery"]').forEach(el => {
356
369
  const rows = parsed.$('[class*="ImageGallery-module__imageRow"]', el);
357
370
  const figcaptionEl = parsed.$('figcaption', el)[0];
358
371
  const caption = figcaptionEl ? serializeChildren(figcaptionEl) : null;
359
372
 
360
373
  let items = [];
361
374
 
362
- rows.forEach((row) => {
375
+ rows.forEach(row => {
363
376
  const pictures = parsed.$('picture', row);
364
377
 
365
- pictures.forEach((picture) => {
378
+ pictures.forEach(picture => {
366
379
  const img = parsed.$('img', picture)[0];
367
380
  const src = largestSrc(img);
368
381
  const dimensions = getImageDimensions(src);
@@ -370,8 +383,8 @@ const processContent = (post, siteUrl, options) => {
370
383
  items.push({
371
384
  fileName: basename(src),
372
385
  src: src,
373
- width: (dimensions) ? dimensions.width : '100',
374
- height: (dimensions) ? dimensions.height : '100'
386
+ width: dimensions ? dimensions.width : '100',
387
+ height: dimensions ? dimensions.height : '100'
375
388
  });
376
389
  });
377
390
  });
@@ -394,7 +407,7 @@ const processContent = (post, siteUrl, options) => {
394
407
  replaceWith(el, serializer.serialize(galleryCard.render(cardOpts)));
395
408
  });
396
409
 
397
- parsed.$('.captioned-image-container').forEach((div) => {
410
+ parsed.$('.captioned-image-container').forEach(div => {
398
411
  const imgAltEl = parsed.$('img[alt]', div)[0];
399
412
  const imgAlt = imgAltEl ? attr(imgAltEl, 'alt') : '';
400
413
  const linkEl = parsed.$('a.image-link', div)[0];
@@ -420,7 +433,7 @@ const processContent = (post, siteUrl, options) => {
420
433
  replaceWith(div, serializer.serialize(imageCard.render(cardOpts)));
421
434
  });
422
435
 
423
- parsed.$('.image-link').forEach((anchor) => {
436
+ parsed.$('.image-link').forEach(anchor => {
424
437
  const imgAltEl = parsed.$('img[alt]', anchor)[0];
425
438
  const imgAlt = imgAltEl ? attr(imgAltEl, 'alt') : '';
426
439
  const linkHref = attr(anchor, 'href');
@@ -444,7 +457,7 @@ const processContent = (post, siteUrl, options) => {
444
457
  replaceWith(anchor, serializer.serialize(imageCard.render(cardOpts)));
445
458
  });
446
459
 
447
- parsed.$('.file-embed-wrapper').forEach((el) => {
460
+ parsed.$('.file-embed-wrapper').forEach(el => {
448
461
  const fileSrcEl = parsed.$('.file-embed-button', el)[0];
449
462
  const fileSrc = attr(fileSrcEl, 'href');
450
463
  const fileTitleEl = parsed.$('.file-embed-details-h1', el)[0];
@@ -460,20 +473,20 @@ const processContent = (post, siteUrl, options) => {
460
473
  const unit = fileSizeMatch[2].toUpperCase();
461
474
 
462
475
  switch (unit) {
463
- case 'KB':
464
- fileSizeBytes = size * 1024;
465
- break;
466
- case 'MB':
467
- fileSizeBytes = size * 1024 * 1024;
468
- break;
469
- case 'GB':
470
- fileSizeBytes = size * 1024 * 1024 * 1024;
471
- break;
472
- case 'TB':
473
- fileSizeBytes = size * 1024 * 1024 * 1024 * 1024;
474
- break;
475
- default:
476
- fileSizeBytes = size;
476
+ case 'KB':
477
+ fileSizeBytes = size * 1024;
478
+ break;
479
+ case 'MB':
480
+ fileSizeBytes = size * 1024 * 1024;
481
+ break;
482
+ case 'GB':
483
+ fileSizeBytes = size * 1024 * 1024 * 1024;
484
+ break;
485
+ case 'TB':
486
+ fileSizeBytes = size * 1024 * 1024 * 1024 * 1024;
487
+ break;
488
+ default:
489
+ fileSizeBytes = size;
477
490
  }
478
491
  }
479
492
 
@@ -490,11 +503,11 @@ const processContent = (post, siteUrl, options) => {
490
503
  replaceWith(el, serializer.serialize(fileCard.render(cardOpts)));
491
504
  });
492
505
 
493
- parsed.$('.comment').forEach((el) => {
506
+ parsed.$('.comment').forEach(el => {
494
507
  el.remove();
495
508
  });
496
509
 
497
- parsed.$('.mention-wrap').forEach((el) => {
510
+ parsed.$('.mention-wrap').forEach(el => {
498
511
  const attrsRaw = attr(el, 'data-attrs');
499
512
 
500
513
  let attrs;
@@ -513,7 +526,7 @@ const processContent = (post, siteUrl, options) => {
513
526
  }
514
527
  });
515
528
 
516
- parsed.$('.digest-post-embed').forEach((el) => {
529
+ parsed.$('.digest-post-embed').forEach(el => {
517
530
  const attrsRaw = attr(el, 'data-attrs');
518
531
 
519
532
  let attrs;
@@ -555,11 +568,11 @@ const processContent = (post, siteUrl, options) => {
555
568
  replaceWith(el, bookmarkHtml);
556
569
  });
557
570
 
558
- parsed.$('a > style').forEach((style) => {
571
+ parsed.$('a > style').forEach(style => {
559
572
  style.remove();
560
573
  });
561
574
 
562
- parsed.$('ul, ol').forEach((list) => {
575
+ parsed.$('ul, ol').forEach(list => {
563
576
  if (parsed.$('img, div, figure, blockquote, .button-wrapper', list).length) {
564
577
  insertBefore(list, '<!--kg-card-begin: html-->');
565
578
  insertAfter(list, '<!--kg-card-end: html-->');
@@ -567,7 +580,7 @@ const processContent = (post, siteUrl, options) => {
567
580
  });
568
581
 
569
582
  // Remove Substack share buttons
570
- parsed.$('p.button-wrapper').forEach((button) => {
583
+ parsed.$('p.button-wrapper').forEach(button => {
571
584
  let shareLinks = parsed.$(':scope > a.button', button);
572
585
  if (shareLinks.length === 1 && siteUrl) {
573
586
  let shareLink = shareLinks[0];
@@ -589,10 +602,13 @@ const processContent = (post, siteUrl, options) => {
589
602
  });
590
603
 
591
604
  // Update button elements
592
- parsed.$('p.button-wrapper').forEach((button) => {
605
+ parsed.$('p.button-wrapper').forEach(button => {
593
606
  let buttons = parsed.$(':scope > a.button', button);
594
607
  if (buttons.length === 1 && siteUrl) {
595
- let siteRegex = new RegExp(`^(?:${escapeStringRegexp(siteUrl)}(?:\\/?)(?:p\\/)?)([a-zA-Z-_\\d]*)(?:\\/?)`, 'gi');
608
+ let siteRegex = new RegExp(
609
+ `^(?:${escapeStringRegexp(siteUrl)}(?:\\/?)(?:p\\/)?)([a-zA-Z-_\\d]*)(?:\\/?)`,
610
+ 'gi'
611
+ );
596
612
  let buttonLink = buttons[0];
597
613
  let buttonHref = attr(buttonLink, 'href');
598
614
  let buttonText = buttonLink.textContent;
@@ -624,13 +640,20 @@ const processContent = (post, siteUrl, options) => {
624
640
  }
625
641
  }
626
642
 
627
- replaceWith(button, `<div class="kg-card kg-button-card kg-align-center"><a href="${buttonHref}" class="kg-btn kg-btn-accent">${buttonText}</a></div>`);
643
+ const card = parsed.document.createElement('div');
644
+ card.className = 'kg-card kg-button-card kg-align-center';
645
+ const link = parsed.document.createElement('a');
646
+ link.className = 'kg-btn kg-btn-accent';
647
+ link.setAttribute('href', buttonHref);
648
+ link.textContent = buttonText;
649
+ card.appendChild(link);
650
+ replaceWith(button, card);
628
651
  }
629
652
  });
630
653
 
631
654
  // TODO: this should be a parser plugin
632
655
  // Wrap nested lists in HTML card
633
- parsed.$('ul li ul, ol li ol, ol li ul, ul li ol').forEach((nestedList) => {
656
+ parsed.$('ul li ul, ol li ol, ol li ul, ul li ol').forEach(nestedList => {
634
657
  const parentList = parents(nestedList, 'ul, ol')[0];
635
658
  if (parentList) {
636
659
  insertBefore(parentList, '<!--kg-card-begin: html-->');
@@ -641,7 +664,7 @@ const processContent = (post, siteUrl, options) => {
641
664
  // Handle footnotes
642
665
  let footnotesItems = [];
643
666
  let footnotesCount = 0;
644
- parsed.$('.footnote').forEach((el) => {
667
+ parsed.$('.footnote').forEach(el => {
645
668
  const footnoteAnchor = parsed.$('a', el)[0];
646
669
  let footnoteBodyAnchor = attr(footnoteAnchor, 'href');
647
670
 
@@ -653,7 +676,10 @@ const processContent = (post, siteUrl, options) => {
653
676
  const pElements = parsed.$('p', footnoteContent);
654
677
  const lastP = pElements[pElements.length - 1];
655
678
  if (lastP) {
656
- lastP.insertAdjacentHTML('beforeend', ` <a href="${footnoteBodyAnchor}" title="Jump back to footnote ${footnoteNumber} in the text.">↩</a>`);
679
+ lastP.insertAdjacentHTML(
680
+ 'beforeend',
681
+ ` <a href="${footnoteBodyAnchor}" title="Jump back to footnote ${footnoteNumber} in the text.">↩</a>`
682
+ );
657
683
  }
658
684
 
659
685
  footnotesItems.push(`<li id="${footnoteID}">${serializeChildren(footnoteContent)}</li>`);
@@ -669,7 +695,7 @@ const processContent = (post, siteUrl, options) => {
669
695
  }
670
696
 
671
697
  // Wrap content that has footnote anchors in HTML tags to retain the footnote jump anchor
672
- parsed.$('p, ul, ol').forEach((el) => {
698
+ parsed.$('p, ul, ol').forEach(el => {
673
699
  if (parsed.$('a.footnote-anchor', el).length > 0) {
674
700
  insertBefore(el, '<!--kg-card-begin: html-->');
675
701
  insertAfter(el, '<!--kg-card-end: html-->');
@@ -678,7 +704,7 @@ const processContent = (post, siteUrl, options) => {
678
704
 
679
705
  // Remove or replace subscribe links on the same domain
680
706
  if (options.noSubscribeButtons) {
681
- parsed.$('a').forEach((anchor) => {
707
+ parsed.$('a').forEach(anchor => {
682
708
  let href = attr(anchor, 'href');
683
709
  let linkRegex = new RegExp(`^(${escapeStringRegexp(siteUrl)})?(/subscribe)(.*)`, 'gi');
684
710
 
@@ -693,7 +719,7 @@ const processContent = (post, siteUrl, options) => {
693
719
  }
694
720
  });
695
721
  } else if (options.subscribeLink) {
696
- parsed.$('a').forEach((anchor) => {
722
+ parsed.$('a').forEach(anchor => {
697
723
  let href = attr(anchor, 'href');
698
724
  let linkRegex = new RegExp(`^(${escapeStringRegexp(siteUrl)})?(/subscribe)(.*)`, 'gi');
699
725
 
@@ -711,22 +737,29 @@ const processContent = (post, siteUrl, options) => {
711
737
 
712
738
  // Remove or replace signup forms with a Portal signup button
713
739
  if (options.noSubscribeButtons) {
714
- parsed.$('.subscription-widget-wrap, .subscription-widget-wrap-editor').forEach((div) => {
740
+ parsed.$('.subscription-widget-wrap, .subscription-widget-wrap-editor').forEach(div => {
715
741
  div.remove();
716
742
  });
717
743
  } else if (options.subscribeLink) {
718
- parsed.$('.subscription-widget-wrap, .subscription-widget-wrap-editor').forEach((div) => {
744
+ parsed.$('.subscription-widget-wrap, .subscription-widget-wrap-editor').forEach(div => {
719
745
  const hasForm = parsed.$('form', div);
720
746
 
721
747
  if (hasForm.length) {
722
748
  const submitEl = parsed.$('form input[type="submit"]', div)[0];
723
749
  const buttonText = submitEl ? attr(submitEl, 'value') : '';
724
- replaceWith(div, `<div class="kg-card kg-button-card kg-align-center"><a href="${options.subscribeLink}" class="kg-btn kg-btn-accent">${buttonText}</a></div>`);
750
+ const card = parsed.document.createElement('div');
751
+ card.className = 'kg-card kg-button-card kg-align-center';
752
+ const link = parsed.document.createElement('a');
753
+ link.className = 'kg-btn kg-btn-accent';
754
+ link.setAttribute('href', options.subscribeLink);
755
+ link.textContent = buttonText;
756
+ card.appendChild(link);
757
+ replaceWith(div, card);
725
758
  }
726
759
  });
727
760
  }
728
761
 
729
- parsed.$('.embedded-post-wrap').forEach((div) => {
762
+ parsed.$('.embedded-post-wrap').forEach(div => {
730
763
  const attrs = attr(div, 'data-attrs') || false;
731
764
 
732
765
  if (!attrs) {
@@ -747,7 +780,7 @@ const processContent = (post, siteUrl, options) => {
747
780
  replaceWith(div, `<!--kg-card-begin: html-->${embeddedHtml}<!--kg-card-end: html-->`);
748
781
  });
749
782
 
750
- parsed.$('div.instagram').forEach((el) => {
783
+ parsed.$('div.instagram').forEach(el => {
751
784
  const instagramLink = parsed.$('a.instagram-image', el)[0];
752
785
  let src = instagramLink ? attr(instagramLink, 'href') : '';
753
786
 
@@ -773,7 +806,7 @@ const processContent = (post, siteUrl, options) => {
773
806
  });
774
807
 
775
808
  // For each image and link, alter the path to remove cropping & sizing for image paths
776
- parsed.$('img[src], a[href]').forEach((el) => {
809
+ parsed.$('img[src], a[href]').forEach(el => {
777
810
  const src = attr(el, 'src');
778
811
  const href = attr(el, 'href');
779
812
 
@@ -880,11 +913,12 @@ export default async (input, ctx) => {
880
913
  let postFiles = await getFiles(postsDir);
881
914
  let postContent = await readFiles(postFiles, postsDir);
882
915
 
883
- input.posts.map((post) => { // eslint-disable-line array-callback-return
916
+ input.posts.map(post => {
917
+ // eslint-disable-line array-callback-return
884
918
  post.data.html = postContent[post.substackId];
885
919
  });
886
920
  } catch (error) {
887
- return new errors.InternalServerError({message: 'Couldn\'t read post files'});
921
+ return new errors.InternalServerError({message: "Couldn't read post files"});
888
922
  }
889
923
  }
890
924
 
@@ -901,8 +935,4 @@ export default async (input, ctx) => {
901
935
  return output;
902
936
  };
903
937
 
904
- export {
905
- processContent,
906
- getImageDimensions,
907
- largeImageUrl
908
- };
938
+ export {processContent, getImageDimensions, largeImageUrl};
package/lib/read-zip.js CHANGED
@@ -3,7 +3,7 @@ import {_base as debugFactory} from '@tryghost/debug';
3
3
 
4
4
  const debug = debugFactory('migrate:substack:read-zip');
5
5
 
6
- const contentStats = async (zipPath) => {
6
+ const contentStats = async zipPath => {
7
7
  const entries = await fsUtils.readZipEntries(zipPath);
8
8
 
9
9
  const posts = entries.filter(value => /posts\/.*\.html/.test(value)).length;
@@ -13,7 +13,7 @@ const contentStats = async (zipPath) => {
13
13
  };
14
14
  };
15
15
 
16
- export default (zipPath) => {
16
+ export default zipPath => {
17
17
  let content = {
18
18
  csv: null,
19
19
  posts: []
@@ -34,7 +34,7 @@ export default (zipPath) => {
34
34
  html: zipEntry.getData().toString('utf8')
35
35
  });
36
36
 
37
- // Get the posts.csv
37
+ // Get the posts.csv
38
38
  } else if (entryName === 'posts.csv' || entryName.endsWith('/posts.csv')) {
39
39
  debug(`Found posts CSV file ${entryName}`);
40
40
  content.csv = zipEntry.getData().toString('utf8');
@@ -44,6 +44,4 @@ export default (zipPath) => {
44
44
  return content;
45
45
  };
46
46
 
47
- export {
48
- contentStats
49
- };
47
+ export {contentStats};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/TryGhost/migrate.git",
@@ -17,25 +17,21 @@
17
17
  "publishConfig": {
18
18
  "access": "public"
19
19
  },
20
- "devDependencies": {
21
- "eslint": "8.57.1"
22
- },
20
+ "devDependencies": {},
23
21
  "dependencies": {
24
- "@tryghost/debug": "2.2.3",
25
- "@tryghost/errors": "3.2.4",
22
+ "@tryghost/debug": "2.3.6",
23
+ "@tryghost/errors": "3.3.6",
26
24
  "@tryghost/string": "0.3.5",
27
25
  "escape-string-regexp": "5.0.0",
28
26
  "he": "1.2.0",
29
27
  "html-entities": "2.6.0",
30
28
  "simple-dom": "1.4.0",
31
29
  "srcset": "5.0.3",
32
- "@tryghost/mg-fs-utils": "0.26.2",
33
- "@tryghost/mg-utils": "0.11.2"
30
+ "@tryghost/mg-fs-utils": "0.26.4",
31
+ "@tryghost/mg-utils": "0.11.4"
34
32
  },
35
33
  "scripts": {
36
34
  "dev": "echo \"Implement me!\"",
37
- "test": "node --test 'test/**/*.test.js'",
38
- "posttest": "pnpm lint",
39
- "lint": "eslint . --ext .js --cache"
35
+ "test": "node --test 'test/**/*.test.js'"
40
36
  }
41
37
  }