@tryghost/mg-substack 0.5.1 → 0.6.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 +10 -0
- package/lib/mapper.js +10 -0
- package/lib/process.js +25 -15
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -34,6 +34,10 @@ A more complex command for a Substack migration looks like this:
|
|
|
34
34
|
migrate substack --pathToZip /path/to/my-export.zip --url https://example.com --email 'person@example.com' --drafts false
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
```sh
|
|
38
|
+
migrate substack --pathToZip /path/to/my-export.zip --url https://example.com --posts false --pages false --podcasts false --threads true
|
|
39
|
+
```
|
|
40
|
+
|
|
37
41
|
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
38
42
|
|
|
39
43
|
- **`--pathToZip`** (required)
|
|
@@ -70,12 +74,18 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
70
74
|
- **`--addAccessTag`**
|
|
71
75
|
- Add #substack-{access} tag to migrated content (public, paid, etc)
|
|
72
76
|
- bool - default: `true`
|
|
77
|
+
- **`--posts`**
|
|
78
|
+
- Import posts
|
|
79
|
+
- bool - default: `true`
|
|
73
80
|
- **`--drafts`**
|
|
74
81
|
- Import draft posts
|
|
75
82
|
- bool - default: `true`
|
|
76
83
|
- **`--pages`**
|
|
77
84
|
- Import pages
|
|
78
85
|
- bool - default: `true`
|
|
86
|
+
- **`--podcasts`**
|
|
87
|
+
- Import podcasts
|
|
88
|
+
- bool - default: `true`
|
|
79
89
|
- **`--threads`**
|
|
80
90
|
- Import threads
|
|
81
91
|
- bool - default: `false`
|
package/lib/mapper.js
CHANGED
|
@@ -140,6 +140,11 @@ export default async (input, options) => {
|
|
|
140
140
|
// Reassign the CSV array to input var
|
|
141
141
|
input = input.meta;
|
|
142
142
|
|
|
143
|
+
if (!options.posts) {
|
|
144
|
+
debug(`Ignoring posts`);
|
|
145
|
+
input = input.filter(data => data.type.toLowerCase() !== `newsletter`);
|
|
146
|
+
}
|
|
147
|
+
|
|
143
148
|
if (!options.drafts) {
|
|
144
149
|
debug(`Ignoring drafts`);
|
|
145
150
|
input = input.filter(data => data.is_published.toLowerCase() === `true`);
|
|
@@ -155,6 +160,11 @@ export default async (input, options) => {
|
|
|
155
160
|
input = input.filter(data => data.type.toLowerCase() !== `thread`);
|
|
156
161
|
}
|
|
157
162
|
|
|
163
|
+
if (!options.podcasts) {
|
|
164
|
+
debug(`Ignoring podcasts`);
|
|
165
|
+
input = input.filter(data => data.type.toLowerCase() !== `podcast`);
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
if (options.postsBefore && options.postsAfter) {
|
|
159
169
|
const startDate = parseISO(formatISO(new Date(options.postsAfter)));
|
|
160
170
|
const endDate = add(parseISO(formatISO(new Date(options.postsBefore))), {
|
package/lib/process.js
CHANGED
|
@@ -168,8 +168,6 @@ const processContent = (post, siteUrl, options) => {
|
|
|
168
168
|
let ogImgSrc = post.data.og_image;
|
|
169
169
|
let unsizedOgSrc = getUnsizedImageName(ogImgSrc);
|
|
170
170
|
|
|
171
|
-
// console.log({unsizedFirstSrc, unsizedOgSrc});
|
|
172
|
-
|
|
173
171
|
if (unsizedFirstSrc === unsizedOgSrc) {
|
|
174
172
|
if ($(firstElement).find('figcaption').length) {
|
|
175
173
|
post.data.feature_image_caption = $(firstElement).find('figcaption').html();
|
|
@@ -204,21 +202,33 @@ const processContent = (post, siteUrl, options) => {
|
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
|
|
207
|
-
// If we have a podcast URL
|
|
208
|
-
if
|
|
209
|
-
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
205
|
+
// If we have a podcast URL `posts.csv`, embed an audio card at the start of the document
|
|
206
|
+
// Else, if we have scraped a podcast URL, embed that instead
|
|
207
|
+
if (substackPodcastURL || post.data?.podcast_audio_src) {
|
|
208
|
+
let audioSrc = '';
|
|
209
|
+
|
|
210
|
+
if (substackPodcastURL) {
|
|
211
|
+
debug(`Post ${post.data.slug} has podcast episode from CSV`);
|
|
212
|
+
audioSrc = substackPodcastURL;
|
|
213
|
+
} else if (post.data?.podcast_audio_src) {
|
|
214
|
+
debug(`Post ${post.data.slug} has podcast episode from scrape`);
|
|
215
|
+
audioSrc = post.data.podcast_audio_src;
|
|
216
|
+
}
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
if (audioSrc && audioSrc.length > 0) {
|
|
219
|
+
let cardOpts = {
|
|
220
|
+
env: {dom: new SimpleDom.Document()},
|
|
221
|
+
payload: {
|
|
222
|
+
src: audioSrc,
|
|
223
|
+
title: post.data.title
|
|
224
|
+
}
|
|
225
|
+
};
|
|
220
226
|
|
|
221
|
-
|
|
227
|
+
const buildCard = audioCard.render(cardOpts);
|
|
228
|
+
const cardHTML = buildCard.nodeValue;
|
|
229
|
+
|
|
230
|
+
$html('.migrate-substack-wrapper').prepend(cardHTML);
|
|
231
|
+
}
|
|
222
232
|
}
|
|
223
233
|
|
|
224
234
|
$html('div.tweet').each((i, el) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
23
|
+
"eslint": "8.57.0",
|
|
24
24
|
"jest": "29.7.0",
|
|
25
25
|
"jest-extended": "4.0.2"
|
|
26
26
|
},
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"@tryghost/debug": "0.1.27",
|
|
29
29
|
"@tryghost/errors": "1.3.0",
|
|
30
30
|
"@tryghost/kg-default-cards": "10.0.2",
|
|
31
|
-
"@tryghost/mg-fs-utils": "^0.13.
|
|
31
|
+
"@tryghost/mg-fs-utils": "^0.13.1",
|
|
32
32
|
"@tryghost/string": "0.2.11",
|
|
33
33
|
"cheerio": "1.0.0-rc.12",
|
|
34
34
|
"date-fns": "2.30.0",
|
|
35
35
|
"he": "1.2.0",
|
|
36
|
-
"html-entities": "2.
|
|
36
|
+
"html-entities": "2.5.2",
|
|
37
37
|
"lodash": "4.17.21",
|
|
38
38
|
"simple-dom": "1.4.0",
|
|
39
39
|
"srcset": "5.0.1"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "11cc97db15efc3e19af16253cd53694cf72aa55d"
|
|
42
42
|
}
|