@tryghost/mg-substack 0.6.5 → 0.7.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/lib/process.js +30 -66
- package/lib/read-zip.js +4 -4
- package/package.json +5 -5
package/lib/process.js
CHANGED
|
@@ -7,6 +7,7 @@ import SimpleDom from 'simple-dom';
|
|
|
7
7
|
import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
|
|
8
8
|
import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';
|
|
9
9
|
import galleryCard from '@tryghost/kg-default-cards/lib/cards/gallery.js';
|
|
10
|
+
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';
|
|
10
11
|
import {decode} from 'html-entities';
|
|
11
12
|
import {parseSrcset} from 'srcset';
|
|
12
13
|
import {_base as debugFactory} from '@tryghost/debug';
|
|
@@ -111,6 +112,11 @@ const processContent = (post, siteUrl, options) => {
|
|
|
111
112
|
scriptingEnabled: false
|
|
112
113
|
}, false); // This `false` is `isDocument`. If `true`, <html>, <head>, and <body> elements are introduced
|
|
113
114
|
|
|
115
|
+
// Change paywall card to comment
|
|
116
|
+
$html('.paywall-jump').each((i, el) => {
|
|
117
|
+
$(el).replaceWith('<!--members-only-->');
|
|
118
|
+
});
|
|
119
|
+
|
|
114
120
|
// Convert bucketeer image paths
|
|
115
121
|
$html('a[href^="https://bucketeer-"], img[src^="https://bucketeer-"]').each((i, el) => {
|
|
116
122
|
const href = $(el).attr('href') ?? false;
|
|
@@ -412,76 +418,34 @@ const processContent = (post, siteUrl, options) => {
|
|
|
412
418
|
const attrsRaw = $(el).attr('data-attrs');
|
|
413
419
|
const attrs = JSON.parse(attrsRaw);
|
|
414
420
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
theHtml.push(`<h3>`);
|
|
423
|
-
|
|
424
|
-
if (attrs.canonical_url) {
|
|
425
|
-
theHtml.push(`<a href="${attrs.canonical_url}">`);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
theHtml.push(attrs.title);
|
|
429
|
-
|
|
430
|
-
if (attrs.canonical_url) {
|
|
431
|
-
theHtml.push(`</a>`);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
theHtml.push(`</h3>`);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
if (attrs.publishedBylines.length || attrs.post_date) {
|
|
438
|
-
theHtml.push(`<p>`);
|
|
439
|
-
|
|
440
|
-
if (attrs.publishedBylines) {
|
|
441
|
-
let bylines = [];
|
|
442
|
-
|
|
443
|
-
attrs.publishedBylines.forEach((byline) => {
|
|
444
|
-
bylines.push(byline.name);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
theHtml.push(bylines.join(', '));
|
|
448
|
-
}
|
|
421
|
+
const postUrl = attrs.canonical_url;
|
|
422
|
+
const postTitle = attrs.title;
|
|
423
|
+
const postCaption = attrs.caption;
|
|
424
|
+
const postImage = attrs.cover_image;
|
|
425
|
+
const postIcon = attrs.publication_logo_url;
|
|
426
|
+
const postAuthor = attrs.publishedBylines[0].name;
|
|
427
|
+
const postPubName = attrs.publication_name;
|
|
449
428
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
theHtml.push(`<img src="${attrs.cover_image}" alt="${attrs.cover_image_alt || ''}">`);
|
|
467
|
-
|
|
468
|
-
if (attrs.canonical_url) {
|
|
469
|
-
theHtml.push(`</a>`);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (attrs.caption) {
|
|
474
|
-
theHtml.push(`<p>`);
|
|
475
|
-
theHtml.push(attrs.caption);
|
|
476
|
-
|
|
477
|
-
if (attrs.canonical_url) {
|
|
478
|
-
theHtml.push(`<br><br><a href="${attrs.canonical_url}">Read full story →</a>`);
|
|
429
|
+
let cardOpts = {
|
|
430
|
+
env: {dom: new SimpleDom.Document()},
|
|
431
|
+
payload: {
|
|
432
|
+
url: postUrl,
|
|
433
|
+
metadata: {
|
|
434
|
+
url: postUrl,
|
|
435
|
+
title: postTitle,
|
|
436
|
+
description: postCaption,
|
|
437
|
+
icon: postIcon,
|
|
438
|
+
thumbnail: postImage,
|
|
439
|
+
publisher: postPubName,
|
|
440
|
+
author: postAuthor
|
|
441
|
+
},
|
|
442
|
+
caption: null
|
|
479
443
|
}
|
|
444
|
+
};
|
|
480
445
|
|
|
481
|
-
|
|
482
|
-
}
|
|
446
|
+
const bookmarkHtml = serializer.serialize(bookmarkCard.render(cardOpts));
|
|
483
447
|
|
|
484
|
-
$(el).replaceWith(
|
|
448
|
+
$(el).replaceWith(bookmarkHtml);
|
|
485
449
|
});
|
|
486
450
|
|
|
487
451
|
$html('a > style').each((i, style) => {
|
package/lib/read-zip.js
CHANGED
|
@@ -26,16 +26,16 @@ export default (zipPath) => {
|
|
|
26
26
|
// - 5678.another-slug.html
|
|
27
27
|
|
|
28
28
|
fsUtils.zip.read(zipPath, (entryName, zipEntry) => {
|
|
29
|
-
// Catch all HTML files inside `
|
|
30
|
-
if (/^posts\/.*\.html$/.test(entryName)) {
|
|
29
|
+
// Catch all HTML files inside `post/`
|
|
30
|
+
if (/^posts\/.*\.html$/.test(entryName) || /\/posts\/.*\.html$/.test(entryName)) {
|
|
31
31
|
debug(`Found post HTML file ${entryName}`);
|
|
32
32
|
content.posts.push({
|
|
33
33
|
name: entryName.replace('posts/', ''),
|
|
34
34
|
html: zipEntry.getData().toString('utf8')
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
} else if (entryName === 'posts.csv') {
|
|
37
|
+
// Get the posts.csv
|
|
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');
|
|
41
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"jest-extended": "4.0.2"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tryghost/debug": "0.1.
|
|
29
|
-
"@tryghost/errors": "1.3.
|
|
28
|
+
"@tryghost/debug": "0.1.33",
|
|
29
|
+
"@tryghost/errors": "1.3.6",
|
|
30
30
|
"@tryghost/kg-default-cards": "10.0.9",
|
|
31
|
-
"@tryghost/mg-fs-utils": "0.15.
|
|
31
|
+
"@tryghost/mg-fs-utils": "0.15.1",
|
|
32
32
|
"@tryghost/string": "0.2.12",
|
|
33
33
|
"cheerio": "1.0.0-rc.12",
|
|
34
34
|
"he": "1.2.0",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"simple-dom": "1.4.0",
|
|
38
38
|
"srcset": "5.0.1"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f8384df52f15e14456c33fea4de8dac2408376a3"
|
|
41
41
|
}
|