@tryghost/mg-substack 0.8.7 → 0.8.9
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 +1 -1
- package/README.md +9 -5
- package/lib/process.js +130 -110
- package/package.json +12 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -55,10 +55,11 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
55
55
|
- **`-s` `--scrape`**
|
|
56
56
|
- Configure scraping tasks
|
|
57
57
|
- string - default: `all`
|
|
58
|
-
- Choices: `all`, `
|
|
59
|
-
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
- Choices: `all`, `web`, `assets`, `none`
|
|
59
|
+
- `all`: Scrape web metadata and download assets
|
|
60
|
+
- `web`: Only scrape metadata from web pages
|
|
61
|
+
- `assets`: Only download assets (images, media, files)
|
|
62
|
+
- `none`: Skip all scraping tasks
|
|
62
63
|
- **`-e` `--email`**
|
|
63
64
|
- Provide an email domain for users e.g. `person@example.com` (Is ignored if `--useMetaAuthor` is provided)
|
|
64
65
|
- bool/string - default: `false`
|
|
@@ -92,6 +93,9 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
92
93
|
- **`--subscribeLink`**
|
|
93
94
|
- Provide a path that existing `/subscribe` anchors will link to e.g. `/join-us` or `#/portal/signup` (`#` characters need to be escaped with a `\`)
|
|
94
95
|
- string - default: `#/portal/signup`
|
|
96
|
+
- **`--noSubscribeButtons`**
|
|
97
|
+
- Remove subscribe buttons and links from content (no replacement link)
|
|
98
|
+
- bool - default: `false`
|
|
95
99
|
- **`--comments`**
|
|
96
100
|
- Keep comment buttons
|
|
97
101
|
- bool - default: `true`
|
|
@@ -149,4 +153,4 @@ yarn dev substack <pathToZip>
|
|
|
149
153
|
|
|
150
154
|
# Copyright & License
|
|
151
155
|
|
|
152
|
-
Copyright (c) 2013-
|
|
156
|
+
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
|
|
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 =
|
|
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
|
|
@@ -564,6 +561,10 @@ const processContent = (post, siteUrl, options) => {
|
|
|
564
561
|
}
|
|
565
562
|
|
|
566
563
|
if (buttonHref === '/subscribe/') {
|
|
564
|
+
if (options.noSubscribeButtons) {
|
|
565
|
+
$html(button).remove();
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
567
568
|
buttonHref = options.subscribeLink || '#/portal/signup';
|
|
568
569
|
}
|
|
569
570
|
|
|
@@ -571,63 +572,78 @@ const processContent = (post, siteUrl, options) => {
|
|
|
571
572
|
buttonHref = options.commentLink || '#ghost-comments-root';
|
|
572
573
|
|
|
573
574
|
if (!options.comments) {
|
|
574
|
-
$(button).remove();
|
|
575
|
+
$html(button).remove();
|
|
575
576
|
return;
|
|
576
577
|
}
|
|
577
578
|
}
|
|
578
579
|
|
|
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>`);
|
|
580
|
+
$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
581
|
}
|
|
581
582
|
});
|
|
582
583
|
|
|
583
584
|
// TODO: this should be a parser plugin
|
|
584
585
|
// Wrap nested lists in HTML card
|
|
585
586
|
$html('ul li ul, ol li ol, ol li ul, ul li ol').each((i, nestedList) => {
|
|
586
|
-
let $parent = $(nestedList).parentsUntil('ul, ol').parent();
|
|
587
|
+
let $parent = $html(nestedList).parentsUntil('ul, ol').parent();
|
|
587
588
|
$parent.before('<!--kg-card-begin: html-->');
|
|
588
589
|
$parent.after('<!--kg-card-end: html-->');
|
|
589
590
|
});
|
|
590
591
|
|
|
591
592
|
// Handle footnotes
|
|
592
|
-
let footnotesMarkup = $(`<div class="footnotes"><hr><ol></ol></div>`);
|
|
593
|
+
let footnotesMarkup = $html(`<div class="footnotes"><hr><ol></ol></div>`);
|
|
593
594
|
let footnotesCount = 0;
|
|
594
595
|
$html('.footnote').each((i, el) => {
|
|
595
|
-
let footnoteBodyAnchor = $(el).find('a').attr('href');
|
|
596
|
+
let footnoteBodyAnchor = $html(el).find('a').attr('href');
|
|
596
597
|
|
|
597
598
|
let footnoteID = null;
|
|
598
|
-
if ($(el).attr('id')) {
|
|
599
|
-
footnoteID = $(el).attr('id');
|
|
599
|
+
if ($html(el).attr('id')) {
|
|
600
|
+
footnoteID = $html(el).attr('id');
|
|
600
601
|
} else {
|
|
601
|
-
footnoteID = $(el).find('a').attr('id');
|
|
602
|
+
footnoteID = $html(el).find('a').attr('id');
|
|
602
603
|
}
|
|
603
604
|
|
|
604
605
|
let footnoteNumber = footnoteID.replace('footnote-', '');
|
|
605
|
-
let footnoteContent = $(el).find('.footnote-content');
|
|
606
|
+
let footnoteContent = $html(el).find('.footnote-content');
|
|
606
607
|
|
|
607
608
|
footnoteContent.find('p').last().append(` <a href="${footnoteBodyAnchor}" title="Jump back to footnote ${footnoteNumber} in the text.">↩</a>`);
|
|
608
609
|
footnotesMarkup.find('ol').append(`<li id="${footnoteID}">${footnoteContent.html()}</li>`);
|
|
609
|
-
$(el).remove();
|
|
610
|
+
$html(el).remove();
|
|
610
611
|
|
|
611
612
|
footnotesCount = footnotesCount + 1;
|
|
612
613
|
});
|
|
613
614
|
|
|
614
615
|
if (footnotesCount > 0) {
|
|
615
|
-
let footnotedHTML =
|
|
616
|
+
let footnotedHTML = $html.html($html(footnotesMarkup));
|
|
616
617
|
$html('.migrate-substack-wrapper').append(`<!--kg-card-begin: html-->${footnotedHTML}<!--kg-card-end: html-->`);
|
|
617
618
|
}
|
|
618
619
|
|
|
619
620
|
// Wrap content that has footnote anchors in HTML tags to retain the footnote jump anchor
|
|
620
621
|
$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-->');
|
|
622
|
+
if ($html(el).find('a.footnote-anchor').length > 0) {
|
|
623
|
+
$html(el).before('<!--kg-card-begin: html-->');
|
|
624
|
+
$html(el).after('<!--kg-card-end: html-->');
|
|
624
625
|
}
|
|
625
626
|
});
|
|
626
627
|
|
|
627
|
-
//
|
|
628
|
-
if (options.
|
|
628
|
+
// Remove or replace subscribe links on the same domain
|
|
629
|
+
if (options.noSubscribeButtons) {
|
|
630
|
+
$html('a').each((i, anchor) => {
|
|
631
|
+
let href = $html(anchor).attr('href');
|
|
632
|
+
let linkRegex = new RegExp(`^(${siteUrl})?(/subscribe)(.*)`, 'gi');
|
|
633
|
+
|
|
634
|
+
if (!href) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
let matches = href.replace(linkRegex, '$2');
|
|
639
|
+
|
|
640
|
+
if (matches === '/subscribe') {
|
|
641
|
+
$html(anchor).remove();
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
} else if (options.subscribeLink) {
|
|
629
645
|
$html('a').each((i, anchor) => {
|
|
630
|
-
let href = $(anchor).attr('href');
|
|
646
|
+
let href = $html(anchor).attr('href');
|
|
631
647
|
let linkRegex = new RegExp(`^(${siteUrl})?(/subscribe)(.*)`, 'gi');
|
|
632
648
|
|
|
633
649
|
if (!href) {
|
|
@@ -637,25 +653,29 @@ const processContent = (post, siteUrl, options) => {
|
|
|
637
653
|
let matches = href.replace(linkRegex, '$2');
|
|
638
654
|
|
|
639
655
|
if (matches === '/subscribe') {
|
|
640
|
-
$(anchor).attr('href', options.subscribeLink);
|
|
656
|
+
$html(anchor).attr('href', options.subscribeLink);
|
|
641
657
|
}
|
|
642
658
|
});
|
|
643
659
|
}
|
|
644
660
|
|
|
645
|
-
//
|
|
646
|
-
if (options.
|
|
661
|
+
// Remove or replace signup forms with a Portal signup button
|
|
662
|
+
if (options.noSubscribeButtons) {
|
|
663
|
+
$html('.subscription-widget-wrap, .subscription-widget-wrap-editor').each((i, div) => {
|
|
664
|
+
$html(div).remove();
|
|
665
|
+
});
|
|
666
|
+
} else if (options.subscribeLink) {
|
|
647
667
|
$html('.subscription-widget-wrap, .subscription-widget-wrap-editor').each((i, div) => {
|
|
648
|
-
const hasForm = $(div).find('form');
|
|
668
|
+
const hasForm = $html(div).find('form');
|
|
649
669
|
|
|
650
670
|
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>`);
|
|
671
|
+
const buttonText = $html(div).find('form input[type="submit"]').attr('value');
|
|
672
|
+
$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
673
|
}
|
|
654
674
|
});
|
|
655
675
|
}
|
|
656
676
|
|
|
657
677
|
$html('.embedded-post-wrap').each((i, div) => {
|
|
658
|
-
const attrs = $(div).attr('data-attrs') || false;
|
|
678
|
+
const attrs = $html(div).attr('data-attrs') || false;
|
|
659
679
|
|
|
660
680
|
if (!attrs) {
|
|
661
681
|
return;
|
|
@@ -670,20 +690,20 @@ const processContent = (post, siteUrl, options) => {
|
|
|
670
690
|
let bookmarkTitle = bookmarkJSON.title;
|
|
671
691
|
let bookmarkContent = bookmarkJSON.truncated_body_text;
|
|
672
692
|
|
|
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>`);
|
|
693
|
+
let $bookmark = $html('<figure class="kg-card kg-bookmark-card"></figure>');
|
|
694
|
+
let $link = $html(`<a class="kg-bookmark-container" href="${bookmarkLink}"></a>`);
|
|
695
|
+
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
696
|
|
|
677
697
|
$link.append($content);
|
|
678
698
|
$bookmark.append($link);
|
|
679
699
|
|
|
680
|
-
$(div).replaceWith($bookmark);
|
|
700
|
+
$html(div).replaceWith($bookmark);
|
|
681
701
|
$bookmark.before('<!--kg-card-begin: html-->');
|
|
682
702
|
$bookmark.after('<!--kg-card-end: html-->');
|
|
683
703
|
});
|
|
684
704
|
|
|
685
705
|
$html('div.instagram').each((i, el) => {
|
|
686
|
-
let src = $(el).find('a.instagram-image').attr('href');
|
|
706
|
+
let src = $html(el).find('a.instagram-image').attr('href');
|
|
687
707
|
|
|
688
708
|
if (!src) {
|
|
689
709
|
return;
|
|
@@ -697,9 +717,9 @@ const processContent = (post, siteUrl, options) => {
|
|
|
697
717
|
}
|
|
698
718
|
src = url.format(parsed, {search: false});
|
|
699
719
|
|
|
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>');
|
|
720
|
+
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>');
|
|
721
|
+
let $script = $html('<script async="" src="//www.instagram.com/embed.js"></script>');
|
|
722
|
+
let $figure = $html('<figure class="instagram"></figure>');
|
|
703
723
|
|
|
704
724
|
// Trim the trailing slash from src if it exists
|
|
705
725
|
if (src.endsWith('/')) {
|
|
@@ -710,20 +730,20 @@ const processContent = (post, siteUrl, options) => {
|
|
|
710
730
|
$figure.append($iframe);
|
|
711
731
|
$figure.append($script);
|
|
712
732
|
|
|
713
|
-
$(el).replaceWith($figure);
|
|
733
|
+
$html(el).replaceWith($figure);
|
|
714
734
|
});
|
|
715
735
|
|
|
716
736
|
// For each image and link, alter the path to remove cropping & sizing for image paths
|
|
717
737
|
$html('img[src], a[href]').each((i, el) => {
|
|
718
|
-
const src = $(el).attr('src');
|
|
719
|
-
const href = $(el).attr('href');
|
|
738
|
+
const src = $html(el).attr('src');
|
|
739
|
+
const href = $html(el).attr('href');
|
|
720
740
|
|
|
721
741
|
if (src) {
|
|
722
|
-
$(el).attr('src', largeImageUrl(src));
|
|
742
|
+
$html(el).attr('src', largeImageUrl(src));
|
|
723
743
|
}
|
|
724
744
|
|
|
725
745
|
if (href) {
|
|
726
|
-
$(el).attr('href', largeImageUrl(href));
|
|
746
|
+
$html(el).attr('href', largeImageUrl(href));
|
|
727
747
|
}
|
|
728
748
|
});
|
|
729
749
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,20 +21,21 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"eslint": "8.57.0",
|
|
24
|
-
"jest": "30.0
|
|
25
|
-
"jest-extended": "
|
|
24
|
+
"jest": "30.2.0",
|
|
25
|
+
"jest-extended": "7.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tryghost/debug": "0.1.
|
|
28
|
+
"@tryghost/debug": "0.1.36",
|
|
29
29
|
"@tryghost/errors": "1.3.8",
|
|
30
|
-
"@tryghost/kg-default-cards": "10.2.
|
|
31
|
-
"@tryghost/mg-fs-utils": "0.16.
|
|
32
|
-
"@tryghost/string": "0.2.
|
|
33
|
-
"cheerio": "1.
|
|
30
|
+
"@tryghost/kg-default-cards": "10.2.6",
|
|
31
|
+
"@tryghost/mg-fs-utils": "0.16.4",
|
|
32
|
+
"@tryghost/string": "0.2.21",
|
|
33
|
+
"cheerio": "1.2.0",
|
|
34
34
|
"he": "1.2.0",
|
|
35
35
|
"html-entities": "2.6.0",
|
|
36
|
-
"lodash": "4.17.
|
|
36
|
+
"lodash": "4.17.23",
|
|
37
37
|
"simple-dom": "1.4.0",
|
|
38
|
-
"srcset": "5.0.
|
|
39
|
-
}
|
|
38
|
+
"srcset": "5.0.3"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "ac9a868976ef5963df7fc2426af9e298bd5d8666"
|
|
40
41
|
}
|