@tryghost/mg-substack 0.3.22 → 0.3.23
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 +14 -10
- package/package.json +7 -6
package/lib/process.js
CHANGED
|
@@ -88,10 +88,11 @@ const processContent = (post, siteUrl, options) => {
|
|
|
88
88
|
return post;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
// As there is HTML, pass it to Cheerio inside a `<
|
|
92
|
-
const $html = $.load(`<
|
|
93
|
-
decodeEntities: false
|
|
94
|
-
|
|
91
|
+
// 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
|
|
92
|
+
const $html = $.load(`<div class="migrate-substack-wrapper">${html}</div>`, {
|
|
93
|
+
decodeEntities: false,
|
|
94
|
+
scriptingEnabled: false
|
|
95
|
+
}, false); // This `false` is `isDocument`. If `true`, <html>, <head>, and <body> elements are introduced
|
|
95
96
|
|
|
96
97
|
// Empty text elements are commonplace and are not needed
|
|
97
98
|
$html('p').each((i, el) => {
|
|
@@ -108,7 +109,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
108
109
|
post.data.feature_image = largeImageUrl(post.data.og_image);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
let firstElement = $html('
|
|
112
|
+
let firstElement = $html('.migrate-substack-wrapper *').first();
|
|
112
113
|
|
|
113
114
|
if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
|
|
114
115
|
let theElementItself = (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img') ? firstElement : $(firstElement).find('img');
|
|
@@ -132,7 +133,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
if (useFirstImage && !post.data.feature_image) {
|
|
135
|
-
let firstElement = $html('
|
|
136
|
+
let firstElement = $html('.migrate-substack-wrapper *').first();
|
|
136
137
|
|
|
137
138
|
if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
|
|
138
139
|
let theElementItself = (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img') ? firstElement : $(firstElement).find('img');
|
|
@@ -168,7 +169,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
168
169
|
const buildCard = audioCard.render(cardOpts);
|
|
169
170
|
const cardHTML = buildCard.nodeValue;
|
|
170
171
|
|
|
171
|
-
$html('
|
|
172
|
+
$html('.migrate-substack-wrapper').prepend(cardHTML);
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
$html('div.tweet').each((i, el) => {
|
|
@@ -336,8 +337,8 @@ const processContent = (post, siteUrl, options) => {
|
|
|
336
337
|
});
|
|
337
338
|
|
|
338
339
|
if (footnotesCount > 0) {
|
|
339
|
-
|
|
340
|
-
$html('
|
|
340
|
+
let footnotedHTML = $.html($(footnotesMarkup));
|
|
341
|
+
$html('.migrate-substack-wrapper').append(`<!--kg-card-begin: html-->${footnotedHTML}<!--kg-card-end: html-->`);
|
|
341
342
|
}
|
|
342
343
|
|
|
343
344
|
// Wrap content that has footnote anchors in HTML tags to retain the footnote jump anchor
|
|
@@ -429,7 +430,10 @@ const processContent = (post, siteUrl, options) => {
|
|
|
429
430
|
});
|
|
430
431
|
|
|
431
432
|
// convert HTML back to a string
|
|
432
|
-
html = $html('
|
|
433
|
+
html = $html('.migrate-substack-wrapper').html();
|
|
434
|
+
|
|
435
|
+
// Remove empty attributes
|
|
436
|
+
html = html.replace(/=""/g, '');
|
|
433
437
|
|
|
434
438
|
// Apply our new HTML back to the post object
|
|
435
439
|
post.data.html = html.trim();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.23",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,21 +20,22 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
23
|
+
"eslint": "8.54.0",
|
|
24
24
|
"jest": "29.7.0",
|
|
25
25
|
"jest-extended": "4.0.2"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tryghost/debug": "0.1.26",
|
|
29
29
|
"@tryghost/errors": "1.2.26",
|
|
30
|
-
"@tryghost/kg-default-cards": "9.1.
|
|
31
|
-
"@tryghost/mg-fs-utils": "^0.12.
|
|
32
|
-
"@tryghost/string": "0.2.
|
|
30
|
+
"@tryghost/kg-default-cards": "9.1.9",
|
|
31
|
+
"@tryghost/mg-fs-utils": "^0.12.20",
|
|
32
|
+
"@tryghost/string": "0.2.10",
|
|
33
|
+
"cheerio": "1.0.0-rc.12",
|
|
33
34
|
"date-fns": "2.30.0",
|
|
34
35
|
"html-entities": "2.4.0",
|
|
35
36
|
"lodash": "4.17.21",
|
|
36
37
|
"simple-dom": "1.4.0",
|
|
37
38
|
"srcset": "5.0.0"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "87eac9f1a90b9e8935ce70d9459db6f8ffec6133"
|
|
40
41
|
}
|