@tryghost/mg-substack 0.2.12 → 0.3.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 CHANGED
@@ -25,23 +25,29 @@ or
25
25
  To run basic Substack migration, the required command is this:
26
26
 
27
27
  ```sh
28
- migrate substack <pathToZip> <susbtackURL>
28
+ migrate substack --pathToZip /path/to/my-export.zip --url https://example.com
29
29
  ```
30
30
 
31
31
  A more complex command for a Substack migration looks like this:
32
32
 
33
33
  ```sh
34
- migrate substack <pathToZip> <susbtackURL> --email 'person@example.com' --drafts false
34
+ migrate substack --pathToZip /path/to/my-export.zip --url https://example.com --email 'person@example.com' --drafts false
35
35
  ```
36
36
 
37
37
  It's possible to pass more options, in order to achieve a better migration file for Ghost:
38
38
 
39
+ - **`--pathToZip`** (required)
40
+ - Path to a zip file
41
+ - string - default: `null`
42
+ - **`--url`** (required)
43
+ - Site URL
44
+ - string - default: `null`
39
45
  - **`-V` `--verbose`**
40
46
  - Show verbose output
41
47
  - bool - default: `false`
42
48
  - **`--zip`**
43
49
  - Create a zip file
44
- - bool - default: `true`
50
+ - bool - default: `true`
45
51
  - **`-s` `--scrape`**
46
52
  - Configure scraping tasks
47
53
  - string - default: `all`
@@ -81,7 +87,7 @@ It's possible to pass more options, in order to achieve a better migration file
81
87
  - string - default: `null`
82
88
  - **`--fallBackHTMLCard`**
83
89
  - Fall back to convert to HTMLCard, if standard Mobiledoc convert fails
84
- - bool - default: `false`
90
+ - bool - default: `true`
85
91
  - **`--cache`**
86
92
  - Persist local cache after migration is complete (Only if `--zip` is `true`)
87
93
  - bool - default: `true`
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import readZip from './lib/read-zip.js';
1
+ import readZip, {contentStats} from './lib/read-zip.js';
2
2
  import fsUtils from '@tryghost/mg-fs-utils';
3
3
  import map from './lib/mapper.js';
4
4
  import process from './lib/process.js';
@@ -25,3 +25,7 @@ export default {
25
25
  ingest,
26
26
  process
27
27
  };
28
+
29
+ export {
30
+ contentStats
31
+ };
package/lib/mapper.js CHANGED
@@ -2,6 +2,9 @@ import {formatISO, parseISO, isBefore, isAfter, add} from 'date-fns';
2
2
  import _ from 'lodash';
3
3
  import errors from '@tryghost/errors';
4
4
  import {slugify} from '@tryghost/string';
5
+ import {_base as debugFactory} from '@tryghost/debug';
6
+
7
+ const debug = debugFactory('migrate:substack:mapper');
5
8
 
6
9
  const mapConfig = (data, {url, email, useMetaAuthor}) => {
7
10
  const slug = data.post_id.replace(/^(?:\d{1,10}\.)(\S*)/gm, '$1');
@@ -112,10 +115,12 @@ export default async (input, options) => {
112
115
  input = input.meta;
113
116
 
114
117
  if (!options.drafts) {
118
+ debug(`Ignoring drafts`);
115
119
  input = input.filter(data => data.is_published.toLowerCase() === `true`);
116
120
  }
117
121
 
118
122
  if (!options.threads) {
123
+ debug(`Ignoring threads`);
119
124
  input = input.filter(data => data.type.toLowerCase() !== `thread`);
120
125
  }
121
126
 
@@ -124,6 +129,7 @@ export default async (input, options) => {
124
129
  const endDate = add(parseISO(formatISO(new Date(options.postsBefore))), {
125
130
  days: 1
126
131
  });
132
+ debug(`Getting posts between ${startDate} and ${endDate}`);
127
133
 
128
134
  await input.forEach((data) => {
129
135
  if (isAfter(parseISO(data.post_date), startDate) && isBefore(parseISO(data.post_date), endDate)) {
@@ -132,6 +138,7 @@ export default async (input, options) => {
132
138
  });
133
139
  } else if (options.postsAfter) {
134
140
  const startDate = parseISO(formatISO(new Date(options.postsAfter)));
141
+ debug(`Getting posts after ${startDate}`);
135
142
 
136
143
  await input.forEach((data) => {
137
144
  if (isAfter(parseISO(data.post_date), startDate)) {
@@ -142,6 +149,7 @@ export default async (input, options) => {
142
149
  const endDate = add(parseISO(formatISO(new Date(options.postsBefore))), {
143
150
  days: 1
144
151
  });
152
+ debug(`Getting posts until ${endDate}`);
145
153
 
146
154
  await input.forEach((data) => {
147
155
  if (isBefore(parseISO(data.post_date), endDate)) {
@@ -149,6 +157,7 @@ export default async (input, options) => {
149
157
  }
150
158
  });
151
159
  } else {
160
+ debug(`Getting all posts`);
152
161
  await input.forEach((data) => {
153
162
  output.posts.push(mapConfig(data, options));
154
163
  });
package/lib/process.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import {promises as fs} from 'node:fs';
2
- import path from 'node:path';
2
+ import {join} from 'node:path';
3
3
  import url from 'node:url';
4
4
  import $ from 'cheerio';
5
5
  import errors from '@tryghost/errors';
6
6
  import SimpleDom from 'simple-dom';
7
7
  import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';
8
8
  import {decode} from 'html-entities';
9
+ import {_base as debugFactory} from '@tryghost/debug';
10
+
11
+ const debug = debugFactory('migrate:substack:process');
9
12
 
10
13
  const getFiles = async (filePath) => {
11
14
  let filenames = await fs.readdir(filePath);
@@ -22,7 +25,7 @@ const readFiles = async (files, postsDir) => {
22
25
  for (const file of files) {
23
26
  const substackId = file.replace(/\.html/, '');
24
27
 
25
- postContent[substackId] = await readContent(path.join(postsDir, file));
28
+ postContent[substackId] = await readContent(join(postsDir, file));
26
29
  }
27
30
 
28
31
  return postContent;
@@ -49,6 +52,7 @@ const processContent = (post, siteUrl, options) => {
49
52
 
50
53
  // If there's no HTML, exit & return an empty string to avoid errors
51
54
  if (!html) {
55
+ debug(`Post ${post.data.slug} has no HTML content`);
52
56
  return '';
53
57
  }
54
58
 
@@ -93,6 +97,7 @@ const processContent = (post, siteUrl, options) => {
93
97
 
94
98
  // If we have a podcast URL, embed an audio card at the start of the document
95
99
  if (substackPodcastURL) {
100
+ debug(`Post ${post.data.slug} has podcast episode`);
96
101
  let cardOpts = {
97
102
  env: {dom: new SimpleDom.Document()},
98
103
  payload: {
package/lib/read-zip.js CHANGED
@@ -1,4 +1,17 @@
1
1
  import fsUtils from '@tryghost/mg-fs-utils';
2
+ import {_base as debugFactory} from '@tryghost/debug';
3
+
4
+ const debug = debugFactory('migrate:substack:read-zip');
5
+
6
+ const contentStats = async (zipPath) => {
7
+ const entries = await fsUtils.readZipEntries(zipPath);
8
+
9
+ const posts = entries.filter(value => /posts\/.*\.html/.test(value)).length;
10
+
11
+ return {
12
+ posts: posts
13
+ };
14
+ };
2
15
 
3
16
  export default (zipPath) => {
4
17
  let content = {
@@ -15,16 +28,22 @@ export default (zipPath) => {
15
28
  fsUtils.zip.read(zipPath, (entryName, zipEntry) => {
16
29
  // Catch all HTML files inside `profile/`
17
30
  if (/^posts\/.*\.html$/.test(entryName)) {
31
+ debug(`Found post HTML file ${entryName}`);
18
32
  content.posts.push({
19
33
  name: entryName.replace('posts/', ''),
20
34
  html: zipEntry.getData().toString('utf8')
21
35
  });
22
36
 
23
- // Skip if not matched above, and report skipped files if `--verbose`
37
+ // Skip if not matched above
24
38
  } else if (entryName === 'posts.csv') {
39
+ debug(`Found posts CSV file ${entryName}`);
25
40
  content.csv = zipEntry.getData().toString('utf8');
26
41
  }
27
42
  });
28
43
 
29
44
  return content;
30
45
  };
46
+
47
+ export {
48
+ contentStats
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "0.2.12",
3
+ "version": "0.3.0",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -20,19 +20,20 @@
20
20
  "access": "public"
21
21
  },
22
22
  "devDependencies": {
23
- "eslint": "8.31.0",
24
- "jest": "29.3.1",
25
- "jest-extended": "3.2.2"
23
+ "eslint": "8.34.0",
24
+ "jest": "29.4.3",
25
+ "jest-extended": "3.2.3"
26
26
  },
27
27
  "dependencies": {
28
+ "@tryghost/debug": "0.1.21",
28
29
  "@tryghost/errors": "1.2.20",
29
- "@tryghost/kg-default-cards": "5.18.7",
30
- "@tryghost/mg-fs-utils": "^0.11.7",
30
+ "@tryghost/kg-default-cards": "6.0.3",
31
+ "@tryghost/mg-fs-utils": "^0.12.0",
31
32
  "@tryghost/string": "0.2.2",
32
33
  "date-fns": "2.29.3",
33
34
  "html-entities": "2.3.3",
34
35
  "lodash": "4.17.21",
35
36
  "simple-dom": "1.4.0"
36
37
  },
37
- "gitHead": "ac01636f55ec4bcf15b1fed2e5efe58327009d0a"
38
+ "gitHead": "c4270f6229caa350155a03a0646b3c0c21eaff5e"
38
39
  }