@tryghost/mg-substack 0.1.2 → 0.1.4
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 +20 -20
- package/index.js +8 -3
- package/lib/process.js +28 -12
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -22,17 +22,23 @@ or
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
To run
|
|
25
|
+
To run basic Substack migration, the required command is this:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
|
-
migrate substack <
|
|
28
|
+
migrate substack <pathToZip> <susbtackURL>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A more complex command for a Substack migration looks like this:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
migrate substack <pathToZip> <susbtackURL> --email 'person@example.com' --drafts false
|
|
29
35
|
```
|
|
30
36
|
|
|
31
37
|
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
32
38
|
|
|
33
39
|
- **`-V` `--verbose`**
|
|
34
40
|
- Show verbose output
|
|
35
|
-
- bool - default: `false`
|
|
41
|
+
- bool - default: `false`
|
|
36
42
|
- **`--zip`**
|
|
37
43
|
- Create a zip file
|
|
38
44
|
- bool - default: `true`
|
|
@@ -45,28 +51,28 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
45
51
|
- Media files larger than this size (defined in MB [i.e. `5`]) will be flagged as oversize
|
|
46
52
|
- **`-e` `--email`**
|
|
47
53
|
- Provide an email domain for users e.g. `person@example.com` (Is ignored if `--useMetaAuthor` is provided)
|
|
48
|
-
- bool/string - default: `false`
|
|
49
|
-
- **`-u` `--url`**
|
|
50
|
-
- Provide a URL (without trailing slash) to the hosted source site, so we can scrape data e.g. `https://example.substack.com`
|
|
51
|
-
- string - default:`https://ghost.io`
|
|
54
|
+
- bool/string - default: `false`
|
|
52
55
|
- **`--drafts`**
|
|
53
56
|
- Import draft posts
|
|
54
|
-
- bool - default: `true`
|
|
57
|
+
- bool - default: `true`
|
|
55
58
|
- **`--threads`**
|
|
56
59
|
- Import thread posts
|
|
57
|
-
- bool - default: `false`
|
|
60
|
+
- bool - default: `false`
|
|
58
61
|
- **`--subscribeLink`**
|
|
59
62
|
- Provide a path that existing `/subscribe` anchors will link to e.g. `/join-us` or `#/portal/signup` (`#` characters need to be escaped with a `\`)
|
|
60
|
-
- string - default: `
|
|
63
|
+
- string - default: `#/portal/signup`
|
|
64
|
+
- **`--comments`**
|
|
65
|
+
- Keep comment buttons
|
|
66
|
+
- bool - default: `true`
|
|
61
67
|
- **`--commentLink`**
|
|
62
68
|
- Provide a path that existing `/comments` anchors will link to e.g. `#ghost-comments-root` (`#` characters need to be escaped with a `\`)
|
|
63
|
-
- string - default: `
|
|
69
|
+
- string - default: `#ghost-comments-root`
|
|
64
70
|
- **`--useMetaImage`**
|
|
65
71
|
- Use `og:image` value as the feature image
|
|
66
|
-
- bool - default: `
|
|
72
|
+
- bool - default: `true`
|
|
67
73
|
- **`--useMetaAuthor`**
|
|
68
74
|
- Use the author field from `ld+json` (useful for posts with multiple authors)
|
|
69
|
-
- bool - default: `
|
|
75
|
+
- bool - default: `true`
|
|
70
76
|
- **`--postsBefore`**
|
|
71
77
|
- Only migrate posts before and including a given date e.g. 'March 20 2018'
|
|
72
78
|
- string - default: `null`
|
|
@@ -79,12 +85,6 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
79
85
|
|
|
80
86
|
**Note**: You can combine `--postsBefore` and `--postsAfter` to migrate posts between 2 dates.
|
|
81
87
|
|
|
82
|
-
A more realistic command for a Substack migration looks like this:
|
|
83
|
-
|
|
84
|
-
```sh
|
|
85
|
-
migrate substack <path to zip file> --url <URL to substack instance> --subscribeLink \#/portal/signup --useMetaImage true --useMetaAuthor true
|
|
86
|
-
```
|
|
87
|
-
|
|
88
88
|
|
|
89
89
|
## Develop
|
|
90
90
|
|
|
@@ -100,7 +100,7 @@ Follow the instructions for the top-level repo.
|
|
|
100
100
|
To run a local development copy, `cd` into this directory, and use `yarn dev` instead of `migrate` like so:
|
|
101
101
|
|
|
102
102
|
```sh
|
|
103
|
-
yarn dev substack <
|
|
103
|
+
yarn dev substack <pathToZip>
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
|
package/index.js
CHANGED
|
@@ -3,15 +3,20 @@ const csv = require('@tryghost/mg-fs-utils').csv;
|
|
|
3
3
|
const map = require('./lib/mapper');
|
|
4
4
|
const process = require('./lib/process');
|
|
5
5
|
|
|
6
|
-
module.exports = async (ctx) => {
|
|
6
|
+
module.exports.ingest = async (ctx) => {
|
|
7
|
+
// Extract the ZIP file
|
|
7
8
|
let zipContent = readZip(ctx.options.pathToZip);
|
|
9
|
+
|
|
10
|
+
// Convert the included CSV data to a JSON object
|
|
8
11
|
zipContent.meta = csv.parseString(zipContent.csv);
|
|
12
|
+
|
|
13
|
+
// Remove the CSV data from the extracted data object
|
|
9
14
|
delete zipContent.csv;
|
|
10
15
|
|
|
16
|
+
// Map out the data into a format ready for other tools to consume
|
|
11
17
|
const mapped = await map(zipContent, ctx.options);
|
|
12
|
-
const processed = await process(mapped, ctx);
|
|
13
18
|
|
|
14
|
-
return
|
|
19
|
+
return mapped;
|
|
15
20
|
};
|
|
16
21
|
|
|
17
22
|
module.exports.process = process;
|
package/lib/process.js
CHANGED
|
@@ -52,25 +52,36 @@ const processContent = (post, siteUrl, options) => {
|
|
|
52
52
|
decodeEntities: false
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
// Empty text elements are commonplace and are not needed
|
|
56
|
+
$html('p').each((i, el) => {
|
|
57
|
+
let content = $(el).html().trim();
|
|
58
|
+
|
|
59
|
+
if (content.length === 0) {
|
|
60
|
+
$(el).remove();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
55
64
|
// 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
|
|
56
65
|
if (responseData?.og_image) {
|
|
57
66
|
let firstElement = $html('body *').first();
|
|
58
67
|
|
|
59
|
-
if (firstElement.tagName === 'img' || $(firstElement).find('img').length) {
|
|
60
|
-
let theElementItself = (firstElement.tagName === 'img') ? firstElement : $(firstElement).find('img');
|
|
61
|
-
|
|
68
|
+
if (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img' || $(firstElement).find('img').length) {
|
|
69
|
+
let theElementItself = (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img') ? firstElement : $(firstElement).find('img');
|
|
62
70
|
let firstImgSrc = $(theElementItself).attr('src');
|
|
63
|
-
let unsizedFirstSrc = getUnsizedImageName(firstImgSrc);
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
if (firstImgSrc.length > 0) {
|
|
73
|
+
let unsizedFirstSrc = getUnsizedImageName(firstImgSrc);
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
let ogImgSrc = responseData.og_image;
|
|
76
|
+
let unsizedOgSrc = getUnsizedImageName(ogImgSrc);
|
|
77
|
+
|
|
78
|
+
if (unsizedFirstSrc === unsizedOgSrc) {
|
|
79
|
+
if ($(firstElement).find('figcaption').length) {
|
|
80
|
+
post.data.feature_image_caption = $(firstElement).find('figcaption').html();
|
|
81
|
+
}
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
$(firstElement).remove();
|
|
84
|
+
}
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
87
|
}
|
|
@@ -192,6 +203,11 @@ const processContent = (post, siteUrl, options) => {
|
|
|
192
203
|
|
|
193
204
|
if (buttonHref.endsWith('/comments')) {
|
|
194
205
|
buttonHref = options.commentLink || '#ghost-comments-root';
|
|
206
|
+
|
|
207
|
+
if (!options.comments) {
|
|
208
|
+
$(button).remove();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
195
211
|
}
|
|
196
212
|
|
|
197
213
|
$(button).replaceWith(`<div class="kg-card kg-button-card kg-align-center"><a href="${buttonHref}" class="kg-btn kg-btn-accent">${buttonText}</a></div>`);
|
|
@@ -256,7 +272,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
256
272
|
|
|
257
273
|
if (hasForm.length) {
|
|
258
274
|
const buttonText = $(div).find('form input[type="submit"]').attr('value');
|
|
259
|
-
$(div).replaceWith(`<div class="kg-card kg-button-card kg-align-center"><a href="
|
|
275
|
+
$(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>`);
|
|
260
276
|
}
|
|
261
277
|
});
|
|
262
278
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"sinon": "14.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tryghost/errors": "1.2.
|
|
27
|
+
"@tryghost/errors": "1.2.15",
|
|
28
28
|
"@tryghost/kg-default-cards": "5.16.5",
|
|
29
|
-
"@tryghost/mg-fs-utils": "^0.9.
|
|
30
|
-
"@tryghost/string": "0.1
|
|
29
|
+
"@tryghost/mg-fs-utils": "^0.9.1",
|
|
30
|
+
"@tryghost/string": "0.2.1",
|
|
31
31
|
"date-fns": "2.29.1",
|
|
32
32
|
"lodash": "4.17.21",
|
|
33
33
|
"simple-dom": "1.4.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "3cf1d928d6c29573098dfd0e792464995449484b"
|
|
36
36
|
}
|