@tryghost/mg-substack 0.8.7 → 0.8.8

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2025 Ghost Foundation
3
+ Copyright (c) 2013-2026 Ghost Foundation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -149,4 +149,4 @@ yarn dev substack <pathToZip>
149
149
 
150
150
  # Copyright & License
151
151
 
152
- Copyright (c) 2013-2025 Ghost Foundation - Released under the [MIT license](LICENSE).
152
+ Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
package/lib/process.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {promises as fs} from 'node:fs';
2
2
  import {join, basename} from 'node:path';
3
3
  import url from 'node:url';
4
- import $ from 'cheerio';
4
+ import * as cheerio from 'cheerio';
5
5
  import errors from '@tryghost/errors';
6
6
  import SimpleDom from 'simple-dom';
7
7
  import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
@@ -116,42 +116,39 @@ const processContent = (post, siteUrl, options) => {
116
116
  }
117
117
 
118
118
  // As there is HTML, pass it to Cheerio inside a `<div class="migrate-substack-wrapper"></div>` element so we have a global wrapper to target later on
119
- const $html = $.load(`<div class="migrate-substack-wrapper">${html}</div>`, {
120
- decodeEntities: false,
121
- scriptingEnabled: false
122
- }, false); // This `false` is `isDocument`. If `true`, <html>, <head>, and <body> elements are introduced
119
+ const $html = cheerio.load(`<div class="migrate-substack-wrapper">${html}</div>`, {}, false);
123
120
 
124
121
  // Change paywall card to comment
125
122
  $html('.paywall-jump').each((i, el) => {
126
- $(el).replaceWith('<!--members-only-->');
123
+ $html(el).replaceWith('<!--members-only-->');
127
124
  });
128
125
 
129
126
  // Empty text elements are commonplace and are not needed
130
127
  $html('p').each((i, el) => {
131
- let content = $(el).html().trim();
128
+ let content = $html(el).html().trim();
132
129
 
133
130
  if (content.length === 0) {
134
- $(el).remove();
131
+ $html(el).remove();
135
132
  }
136
133
  });
137
134
 
138
135
  // Wrap these in a HTML card so they can be handled by publishers as needed
139
136
  $html('div.latex-rendered').each((i, el) => {
140
- $(el).before('<!--kg-card-begin: html-->');
141
- $(el).after('<!--kg-card-end: html-->');
137
+ $html(el).before('<!--kg-card-begin: html-->');
138
+ $html(el).after('<!--kg-card-end: html-->');
142
139
  });
143
140
 
144
141
  // We don't currently handle these, so remove them to clean up the document
145
142
  $html('div.native-video-embed').each((i, el) => {
146
- $(el).remove();
143
+ $html(el).remove();
147
144
  });
148
145
 
149
146
  $html('div.poll-embed').each((i, el) => {
150
- $(el).remove();
147
+ $html(el).remove();
151
148
  });
152
149
 
153
150
  $html('.image3').each((i, el) => {
154
- const attrs = $(el).attr('data-attrs');
151
+ const attrs = $html(el).attr('data-attrs');
155
152
  const attrsObj = JSON.parse(attrs);
156
153
 
157
154
  let cardOpts = {
@@ -163,7 +160,7 @@ const processContent = (post, siteUrl, options) => {
163
160
  }
164
161
  };
165
162
 
166
- $(el).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
163
+ $html(el).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
167
164
  });
168
165
 
169
166
  // 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
@@ -174,9 +171,9 @@ const processContent = (post, siteUrl, options) => {
174
171
 
175
172
  let firstElement = $html('.migrate-substack-wrapper *').first();
176
173
 
177
- if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
178
- let theElementItself = (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img') ? firstElement : $(firstElement).find('img');
179
- let firstImgSrc = $(theElementItself).attr('src');
174
+ if (firstElement.tagName === 'img' || ($html(firstElement).get(0) && $html(firstElement).get(0).name === 'img') || $html(firstElement).find('img').length) {
175
+ let theElementItself = (firstElement.tagName === 'img' || $html(firstElement).get(0).name === 'img') ? firstElement : $html(firstElement).find('img');
176
+ let firstImgSrc = $html(theElementItself).attr('src');
180
177
 
181
178
  if (firstImgSrc.length > 0) {
182
179
  let unsizedFirstSrc = getUnsizedImageName(firstImgSrc);
@@ -185,11 +182,11 @@ const processContent = (post, siteUrl, options) => {
185
182
  let unsizedOgSrc = getUnsizedImageName(ogImgSrc);
186
183
 
187
184
  if (unsizedFirstSrc === unsizedOgSrc) {
188
- if ($(firstElement).find('figcaption').length) {
189
- post.data.feature_image_caption = $(firstElement).find('figcaption').html();
185
+ if ($html(firstElement).find('figcaption').length) {
186
+ post.data.feature_image_caption = $html(firstElement).find('figcaption').html();
190
187
  }
191
188
 
192
- $(firstElement).remove();
189
+ $html(firstElement).remove();
193
190
  }
194
191
  }
195
192
  }
@@ -198,9 +195,9 @@ const processContent = (post, siteUrl, options) => {
198
195
  if (useFirstImage && !post.data.feature_image) {
199
196
  let firstElement = $html('.migrate-substack-wrapper *').first();
200
197
 
201
- if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
202
- let theElementItself = (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img') ? firstElement : $(firstElement).find('img');
203
- let firstImgSrc = $(theElementItself).attr('src');
198
+ if (firstElement.tagName === 'img' || ($html(firstElement).get(0) && $html(firstElement).get(0).name === 'img') || $html(firstElement).find('img').length) {
199
+ let theElementItself = (firstElement.tagName === 'img' || $html(firstElement).get(0).name === 'img') ? firstElement : $html(firstElement).find('img');
200
+ let firstImgSrc = $html(theElementItself).attr('src');
204
201
 
205
202
  if (firstImgSrc.length > 0) {
206
203
  let unsizedFirstSrc = largeImageUrl(firstImgSrc);
@@ -208,11 +205,11 @@ const processContent = (post, siteUrl, options) => {
208
205
  if (unsizedFirstSrc) {
209
206
  post.data.feature_image = unsizedFirstSrc;
210
207
 
211
- if ($(firstElement).find('figcaption').length) {
212
- post.data.feature_image_caption = $(firstElement).find('figcaption').html();
208
+ if ($html(firstElement).find('figcaption').length) {
209
+ post.data.feature_image_caption = $html(firstElement).find('figcaption').html();
213
210
  }
214
211
 
215
- $(firstElement).remove();
212
+ $html(firstElement).remove();
216
213
  }
217
214
  }
218
215
  }
@@ -248,7 +245,7 @@ const processContent = (post, siteUrl, options) => {
248
245
  }
249
246
 
250
247
  $html('div.tweet').each((i, el) => {
251
- let src = $(el).children('a').attr('href');
248
+ let src = $html(el).children('a').attr('href');
252
249
  let parsed = url.parse(src);
253
250
 
254
251
  if (parsed.search) {
@@ -257,11 +254,11 @@ const processContent = (post, siteUrl, options) => {
257
254
  }
258
255
  src = url.format(parsed, {search: false});
259
256
 
260
- let tweetText = $(el)?.find('.tweet-text')?.html()?.replace(/(?:\r\n|\r|\n)/g, '<br>') ?? false;
261
- let tweetAuthorName = $(el)?.find('.tweet-author-name')?.html()?.trim() ?? false;
262
- let tweetAuthorHandle = $(el)?.find('.tweet-author-handle')?.html()?.trim() ?? false;
263
- let tweetDateTime = $(el)?.find('.tweet-date')?.text()?.trim() ?? false;
264
- let tweetURL = $(el)?.find('.tweet-link-top')?.attr('href') ?? false;
257
+ let tweetText = $html(el)?.find('.tweet-text')?.html()?.replace(/(?:\r\n|\r|\n)/g, '<br>') ?? false;
258
+ let tweetAuthorName = $html(el)?.find('.tweet-author-name')?.html()?.trim() ?? false;
259
+ let tweetAuthorHandle = $html(el)?.find('.tweet-author-handle')?.html()?.trim() ?? false;
260
+ let tweetDateTime = $html(el)?.find('.tweet-date')?.text()?.trim() ?? false;
261
+ let tweetURL = $html(el)?.find('.tweet-link-top')?.attr('href') ?? false;
265
262
 
266
263
  let theHtml = [];
267
264
 
@@ -289,21 +286,21 @@ const processContent = (post, siteUrl, options) => {
289
286
 
290
287
  theHtml.push(`</a>`);
291
288
 
292
- let $figure = $('<figure class="kg-card kg-embed-card"></figure>');
293
- let $blockquote = $(`<blockquote class="twitter-tweet">${theHtml.join(' ')}</blockquote>`);
294
- let $anchor = $(`<a href="${src}"></a>`);
295
- let $script = $('<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>');
289
+ let $figure = $html('<figure class="kg-card kg-embed-card"></figure>');
290
+ let $blockquote = $html(`<blockquote class="twitter-tweet">${theHtml.join(' ')}</blockquote>`);
291
+ let $anchor = $html(`<a href="${src}"></a>`);
292
+ let $script = $html('<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>');
296
293
 
297
294
  $blockquote.append($anchor);
298
295
 
299
296
  $figure.append($blockquote);
300
297
  $figure.append($script);
301
298
 
302
- $(el).replaceWith($figure);
299
+ $html(el).replaceWith($figure);
303
300
  });
304
301
 
305
302
  $html('.image-gallery-embed').each((i, el) => {
306
- const attrs = $(el).attr('data-attrs');
303
+ const attrs = $html(el).attr('data-attrs');
307
304
  const attrsObj = JSON.parse(attrs);
308
305
 
309
306
  let items = [];
@@ -334,20 +331,20 @@ const processContent = (post, siteUrl, options) => {
334
331
  }
335
332
  };
336
333
 
337
- $(el).replaceWith(serializer.serialize(galleryCard.render(cardOpts)));
334
+ $html(el).replaceWith(serializer.serialize(galleryCard.render(cardOpts)));
338
335
  });
339
336
 
340
337
  $html('[class*="ImageGallery-module__imageGallery"]').each((i, el) => {
341
- const $row = $(el).find('[class*="ImageGallery-module__imageRow"]');
342
- const caption = $(el).find('figcaption').html();
338
+ const $row = $html(el).find('[class*="ImageGallery-module__imageRow"]');
339
+ const caption = $html(el).find('figcaption').html();
343
340
 
344
341
  let items = [];
345
342
 
346
343
  $row.each((ii, row) => {
347
- const $pictures = $(row).find('picture');
344
+ const $pictures = $html(row).find('picture');
348
345
 
349
346
  $pictures.each((iii, picture) => {
350
- const $img = $(picture).find('img');
347
+ const $img = $html(picture).find('img');
351
348
  const src = largestSrc($img);
352
349
  const dimensions = getImageDimensions(src);
353
350
 
@@ -375,14 +372,14 @@ const processContent = (post, siteUrl, options) => {
375
372
  }
376
373
  };
377
374
 
378
- $(el).replaceWith(serializer.serialize(galleryCard.render(cardOpts)));
375
+ $html(el).replaceWith(serializer.serialize(galleryCard.render(cardOpts)));
379
376
  });
380
377
 
381
378
  $html('.captioned-image-container').each((i, div) => {
382
- const imgAlt = $(div).find('img[alt]').attr('alt') || '';
383
- const linkHref = $(div).find('a.image-link').attr('href') || false;
384
- const imgCaption = $(div).find('figcaption').html() || false;
385
- const imageSrc = largestSrc($(div).find('img'));
379
+ const imgAlt = $html(div).find('img[alt]').attr('alt') || '';
380
+ const linkHref = $html(div).find('a.image-link').attr('href') || false;
381
+ const imgCaption = $html(div).find('figcaption').html() || false;
382
+ const imageSrc = largestSrc($html(div).find('img'));
386
383
 
387
384
  let cardOpts = {
388
385
  env: {dom: new SimpleDom.Document()},
@@ -397,13 +394,13 @@ const processContent = (post, siteUrl, options) => {
397
394
  cardOpts.payload.href = linkHref;
398
395
  }
399
396
 
400
- $(div).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
397
+ $html(div).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
401
398
  });
402
399
 
403
400
  $html('.image-link').each((i, anchor) => {
404
- const imgAlt = $(anchor).find('img[alt]').attr('alt') || '';
405
- const linkHref = $(anchor).attr('href');
406
- const imageSrc = largestSrc($(anchor).find('img'));
401
+ const imgAlt = $html(anchor).find('img[alt]').attr('alt') || '';
402
+ const linkHref = $html(anchor).attr('href');
403
+ const imageSrc = largestSrc($html(anchor).find('img'));
407
404
 
408
405
  let cardOpts = {
409
406
  env: {dom: new SimpleDom.Document()},
@@ -419,13 +416,13 @@ const processContent = (post, siteUrl, options) => {
419
416
  cardOpts.payload.href = linkHref;
420
417
  }
421
418
 
422
- $(anchor).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
419
+ $html(anchor).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
423
420
  });
424
421
 
425
422
  $html('.file-embed-wrapper').each((i, el) => {
426
- const fileSrc = $(el).find('.file-embed-button').attr('href');
427
- const fileTitle = $(el).find('.file-embed-details-h1').text();
428
- const fileDetails = $(el).find('.file-embed-details-h2').text();
423
+ const fileSrc = $html(el).find('.file-embed-button').attr('href');
424
+ const fileTitle = $html(el).find('.file-embed-details-h1').text();
425
+ const fileDetails = $html(el).find('.file-embed-details-h2').text();
429
426
 
430
427
  const fileSizeMatch = fileDetails.match(/([\d.]+)([KMGT]B)/i);
431
428
  let fileSizeBytes = 0;
@@ -462,15 +459,15 @@ const processContent = (post, siteUrl, options) => {
462
459
  }
463
460
  };
464
461
 
465
- $(el).replaceWith(serializer.serialize(fileCard.render(cardOpts)));
462
+ $html(el).replaceWith(serializer.serialize(fileCard.render(cardOpts)));
466
463
  });
467
464
 
468
465
  $html('.comment').each((i, el) => {
469
- $(el).remove();
466
+ $html(el).remove();
470
467
  });
471
468
 
472
469
  $html('.digest-post-embed').each((i, el) => {
473
- const attrsRaw = $(el).attr('data-attrs');
470
+ const attrsRaw = $html(el).attr('data-attrs');
474
471
 
475
472
  let attrs;
476
473
 
@@ -508,37 +505,37 @@ const processContent = (post, siteUrl, options) => {
508
505
 
509
506
  const bookmarkHtml = serializer.serialize(bookmarkCard.render(cardOpts));
510
507
 
511
- $(el).replaceWith(bookmarkHtml);
508
+ $html(el).replaceWith(bookmarkHtml);
512
509
  });
513
510
 
514
511
  $html('a > style').each((i, style) => {
515
- $(style).remove();
512
+ $html(style).remove();
516
513
  });
517
514
 
518
515
  $html('ul, ol').each((i, list) => {
519
- if ($(list).find('img, div, figure, blockquote, .button-wrapper').length) {
520
- $(list).before('<!--kg-card-begin: html-->');
521
- $(list).after('<!--kg-card-end: html-->');
516
+ if ($html(list).find('img, div, figure, blockquote, .button-wrapper').length) {
517
+ $html(list).before('<!--kg-card-begin: html-->');
518
+ $html(list).after('<!--kg-card-end: html-->');
522
519
  }
523
520
  });
524
521
 
525
522
  // Remove Substack share buttons
526
523
  $html('p.button-wrapper').each((i, button) => {
527
- let shareLinks = $(button).children('a.button');
524
+ let shareLinks = $html(button).children('a.button');
528
525
  if (shareLinks.length === 1 && siteUrl) {
529
- let shareLink = $(shareLinks).get(0);
530
- let src = $(shareLink).attr('href');
526
+ let shareLink = $html(shareLinks).get(0);
527
+ let src = $html(shareLink).attr('href');
531
528
  let parsed = url.parse(src);
532
529
 
533
530
  // If it's a share button, there's no use for it and completely remove the button
534
531
  if (parsed.search && parsed.search.indexOf('action=share') >= 0) {
535
- $(button).remove();
532
+ $html(button).remove();
536
533
  return;
537
534
  }
538
535
 
539
536
  // If it's a gift button, there's no use for it and completely remove the button
540
537
  if (parsed.search && parsed.search.indexOf('gift=true') >= 0) {
541
- $(button).remove();
538
+ $html(button).remove();
542
539
  return;
543
540
  }
544
541
  }
@@ -546,12 +543,12 @@ const processContent = (post, siteUrl, options) => {
546
543
 
547
544
  // Update button elements
548
545
  $html('p.button-wrapper').each((i, button) => {
549
- let buttons = $(button).children('a.button');
546
+ let buttons = $html(button).children('a.button');
550
547
  if (buttons.length === 1 && siteUrl) {
551
548
  let siteRegex = new RegExp(`^(?:${siteUrl}(?:\\/?)(?:p\\/)?)([a-zA-Z-_\\d]*)(?:\\/?)`, 'gi');
552
- let buttonLink = $(buttons).get(0);
553
- let buttonHref = $(buttonLink).attr('href');
554
- let buttonText = $(buttonLink).text();
549
+ let buttonLink = $html(buttons).get(0);
550
+ let buttonHref = $html(buttonLink).attr('href');
551
+ let buttonText = $html(buttonLink).text();
555
552
  let parsed = url.parse(buttonHref);
556
553
 
557
554
  // remove possible query params
@@ -571,63 +568,63 @@ const processContent = (post, siteUrl, options) => {
571
568
  buttonHref = options.commentLink || '#ghost-comments-root';
572
569
 
573
570
  if (!options.comments) {
574
- $(button).remove();
571
+ $html(button).remove();
575
572
  return;
576
573
  }
577
574
  }
578
575
 
579
- $(button).replaceWith(`<div class="kg-card kg-button-card kg-align-center"><a href="${buttonHref}" class="kg-btn kg-btn-accent">${buttonText}</a></div>`);
576
+ $html(button).replaceWith(`<div class="kg-card kg-button-card kg-align-center"><a href="${buttonHref}" class="kg-btn kg-btn-accent">${buttonText}</a></div>`);
580
577
  }
581
578
  });
582
579
 
583
580
  // TODO: this should be a parser plugin
584
581
  // Wrap nested lists in HTML card
585
582
  $html('ul li ul, ol li ol, ol li ul, ul li ol').each((i, nestedList) => {
586
- let $parent = $(nestedList).parentsUntil('ul, ol').parent();
583
+ let $parent = $html(nestedList).parentsUntil('ul, ol').parent();
587
584
  $parent.before('<!--kg-card-begin: html-->');
588
585
  $parent.after('<!--kg-card-end: html-->');
589
586
  });
590
587
 
591
588
  // Handle footnotes
592
- let footnotesMarkup = $(`<div class="footnotes"><hr><ol></ol></div>`);
589
+ let footnotesMarkup = $html(`<div class="footnotes"><hr><ol></ol></div>`);
593
590
  let footnotesCount = 0;
594
591
  $html('.footnote').each((i, el) => {
595
- let footnoteBodyAnchor = $(el).find('a').attr('href');
592
+ let footnoteBodyAnchor = $html(el).find('a').attr('href');
596
593
 
597
594
  let footnoteID = null;
598
- if ($(el).attr('id')) {
599
- footnoteID = $(el).attr('id');
595
+ if ($html(el).attr('id')) {
596
+ footnoteID = $html(el).attr('id');
600
597
  } else {
601
- footnoteID = $(el).find('a').attr('id');
598
+ footnoteID = $html(el).find('a').attr('id');
602
599
  }
603
600
 
604
601
  let footnoteNumber = footnoteID.replace('footnote-', '');
605
- let footnoteContent = $(el).find('.footnote-content');
602
+ let footnoteContent = $html(el).find('.footnote-content');
606
603
 
607
604
  footnoteContent.find('p').last().append(` <a href="${footnoteBodyAnchor}" title="Jump back to footnote ${footnoteNumber} in the text.">↩</a>`);
608
605
  footnotesMarkup.find('ol').append(`<li id="${footnoteID}">${footnoteContent.html()}</li>`);
609
- $(el).remove();
606
+ $html(el).remove();
610
607
 
611
608
  footnotesCount = footnotesCount + 1;
612
609
  });
613
610
 
614
611
  if (footnotesCount > 0) {
615
- let footnotedHTML = $.html($(footnotesMarkup));
612
+ let footnotedHTML = $html.html($html(footnotesMarkup));
616
613
  $html('.migrate-substack-wrapper').append(`<!--kg-card-begin: html-->${footnotedHTML}<!--kg-card-end: html-->`);
617
614
  }
618
615
 
619
616
  // Wrap content that has footnote anchors in HTML tags to retain the footnote jump anchor
620
617
  $html('p, ul, ol').each((i, el) => {
621
- if ($(el).find('a.footnote-anchor').length > 0) {
622
- $(el).before('<!--kg-card-begin: html-->');
623
- $(el).after('<!--kg-card-end: html-->');
618
+ if ($html(el).find('a.footnote-anchor').length > 0) {
619
+ $html(el).before('<!--kg-card-begin: html-->');
620
+ $html(el).after('<!--kg-card-end: html-->');
624
621
  }
625
622
  });
626
623
 
627
624
  // Replace any subscribe link on the same domain with a specific link
628
625
  if (options.subscribeLink) {
629
626
  $html('a').each((i, anchor) => {
630
- let href = $(anchor).attr('href');
627
+ let href = $html(anchor).attr('href');
631
628
  let linkRegex = new RegExp(`^(${siteUrl})?(/subscribe)(.*)`, 'gi');
632
629
 
633
630
  if (!href) {
@@ -637,7 +634,7 @@ const processContent = (post, siteUrl, options) => {
637
634
  let matches = href.replace(linkRegex, '$2');
638
635
 
639
636
  if (matches === '/subscribe') {
640
- $(anchor).attr('href', options.subscribeLink);
637
+ $html(anchor).attr('href', options.subscribeLink);
641
638
  }
642
639
  });
643
640
  }
@@ -645,17 +642,17 @@ const processContent = (post, siteUrl, options) => {
645
642
  // Replace any signup forms with a Portal signup button
646
643
  if (options.subscribeLink) {
647
644
  $html('.subscription-widget-wrap, .subscription-widget-wrap-editor').each((i, div) => {
648
- const hasForm = $(div).find('form');
645
+ const hasForm = $html(div).find('form');
649
646
 
650
647
  if (hasForm.length) {
651
- const buttonText = $(div).find('form input[type="submit"]').attr('value');
652
- $(div).replaceWith(`<div class="kg-card kg-button-card kg-align-center"><a href="${options.subscribeLink}" class="kg-btn kg-btn-accent">${buttonText}</a></div>`);
648
+ const buttonText = $html(div).find('form input[type="submit"]').attr('value');
649
+ $html(div).replaceWith(`<div class="kg-card kg-button-card kg-align-center"><a href="${options.subscribeLink}" class="kg-btn kg-btn-accent">${buttonText}</a></div>`);
653
650
  }
654
651
  });
655
652
  }
656
653
 
657
654
  $html('.embedded-post-wrap').each((i, div) => {
658
- const attrs = $(div).attr('data-attrs') || false;
655
+ const attrs = $html(div).attr('data-attrs') || false;
659
656
 
660
657
  if (!attrs) {
661
658
  return;
@@ -670,20 +667,20 @@ const processContent = (post, siteUrl, options) => {
670
667
  let bookmarkTitle = bookmarkJSON.title;
671
668
  let bookmarkContent = bookmarkJSON.truncated_body_text;
672
669
 
673
- let $bookmark = $('<figure class="kg-card kg-bookmark-card"></figure>');
674
- let $link = $(`<a class="kg-bookmark-container" href="${bookmarkLink}"></a>`);
675
- let $content = $(`<div class="kg-bookmark-content"><div class="kg-bookmark-title">${bookmarkTitle}</div><div class="kg-bookmark-description">${bookmarkContent}</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="${bookmarkPubIcon}"><span class="kg-bookmark-author">${bookmarkPubName}</span></div></div>`);
670
+ let $bookmark = $html('<figure class="kg-card kg-bookmark-card"></figure>');
671
+ let $link = $html(`<a class="kg-bookmark-container" href="${bookmarkLink}"></a>`);
672
+ let $content = $html(`<div class="kg-bookmark-content"><div class="kg-bookmark-title">${bookmarkTitle}</div><div class="kg-bookmark-description">${bookmarkContent}</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="${bookmarkPubIcon}"><span class="kg-bookmark-author">${bookmarkPubName}</span></div></div>`);
676
673
 
677
674
  $link.append($content);
678
675
  $bookmark.append($link);
679
676
 
680
- $(div).replaceWith($bookmark);
677
+ $html(div).replaceWith($bookmark);
681
678
  $bookmark.before('<!--kg-card-begin: html-->');
682
679
  $bookmark.after('<!--kg-card-end: html-->');
683
680
  });
684
681
 
685
682
  $html('div.instagram').each((i, el) => {
686
- let src = $(el).find('a.instagram-image').attr('href');
683
+ let src = $html(el).find('a.instagram-image').attr('href');
687
684
 
688
685
  if (!src) {
689
686
  return;
@@ -697,9 +694,9 @@ const processContent = (post, siteUrl, options) => {
697
694
  }
698
695
  src = url.format(parsed, {search: false});
699
696
 
700
- let $iframe = $('<iframe class="instagram-media instagram-media-rendered" id="instagram-embed-0" allowtransparency="true" allowfullscreen="true" frameborder="0" height="968" data-instgrm-payload-id="instagram-media-payload-0" scrolling="no" style="background: white; max-width: 658px; width: calc(100% - 2px); border-radius: 3px; border: 1px solid rgb(219, 219, 219); box-shadow: none; display: block; margin: 0px 0px 12px; min-width: 326px; padding: 0px;"></iframe>');
701
- let $script = $('<script async="" src="//www.instagram.com/embed.js"></script>');
702
- let $figure = $('<figure class="instagram"></figure>');
697
+ let $iframe = $html('<iframe class="instagram-media instagram-media-rendered" id="instagram-embed-0" allowtransparency="true" allowfullscreen="true" frameborder="0" height="968" data-instgrm-payload-id="instagram-media-payload-0" scrolling="no" style="background: white; max-width: 658px; width: calc(100% - 2px); border-radius: 3px; border: 1px solid rgb(219, 219, 219); box-shadow: none; display: block; margin: 0px 0px 12px; min-width: 326px; padding: 0px;"></iframe>');
698
+ let $script = $html('<script async="" src="//www.instagram.com/embed.js"></script>');
699
+ let $figure = $html('<figure class="instagram"></figure>');
703
700
 
704
701
  // Trim the trailing slash from src if it exists
705
702
  if (src.endsWith('/')) {
@@ -710,20 +707,20 @@ const processContent = (post, siteUrl, options) => {
710
707
  $figure.append($iframe);
711
708
  $figure.append($script);
712
709
 
713
- $(el).replaceWith($figure);
710
+ $html(el).replaceWith($figure);
714
711
  });
715
712
 
716
713
  // For each image and link, alter the path to remove cropping & sizing for image paths
717
714
  $html('img[src], a[href]').each((i, el) => {
718
- const src = $(el).attr('src');
719
- const href = $(el).attr('href');
715
+ const src = $html(el).attr('src');
716
+ const href = $html(el).attr('href');
720
717
 
721
718
  if (src) {
722
- $(el).attr('src', largeImageUrl(src));
719
+ $html(el).attr('src', largeImageUrl(src));
723
720
  }
724
721
 
725
722
  if (href) {
726
- $(el).attr('href', largeImageUrl(href));
723
+ $html(el).attr('href', largeImageUrl(href));
727
724
  }
728
725
  });
729
726
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -27,14 +27,15 @@
27
27
  "dependencies": {
28
28
  "@tryghost/debug": "0.1.35",
29
29
  "@tryghost/errors": "1.3.8",
30
- "@tryghost/kg-default-cards": "10.2.0",
31
- "@tryghost/mg-fs-utils": "0.16.2",
32
- "@tryghost/string": "0.2.17",
33
- "cheerio": "1.0.0-rc.12",
30
+ "@tryghost/kg-default-cards": "10.2.3",
31
+ "@tryghost/mg-fs-utils": "0.16.3",
32
+ "@tryghost/string": "0.2.21",
33
+ "cheerio": "1.1.2",
34
34
  "he": "1.2.0",
35
35
  "html-entities": "2.6.0",
36
36
  "lodash": "4.17.21",
37
37
  "simple-dom": "1.4.0",
38
- "srcset": "5.0.2"
39
- }
38
+ "srcset": "5.0.3"
39
+ },
40
+ "gitHead": "027225930710c0643603f6ae346dc76504d9bb7a"
40
41
  }