@tryghost/mg-substack 0.1.5 → 0.2.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 +3 -3
- package/index.js +12 -7
- package/lib/mapper.js +5 -5
- package/lib/process.js +14 -10
- package/lib/read-zip.js +2 -2
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -45,10 +45,10 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
45
45
|
- **`-s` `--scrape`**
|
|
46
46
|
- Configure scraping tasks
|
|
47
47
|
- string - default: `all`
|
|
48
|
-
- Choices: `all`, `img`, `web`, `media`, `none`
|
|
49
|
-
- **`--
|
|
48
|
+
- Choices: `all`, `img`, `web`, `media`, `files`, `none`
|
|
49
|
+
- **`--sizeLimit`**
|
|
50
50
|
- number - default: `false`
|
|
51
|
-
- Media files larger than this size (defined in MB [i.e. `5`]) will be flagged as oversize
|
|
51
|
+
- Media files larger than this size (defined in MB [i.e. `5`]) will be flagged as oversize
|
|
52
52
|
- **`-e` `--email`**
|
|
53
53
|
- Provide an email domain for users e.g. `person@example.com` (Is ignored if `--useMetaAuthor` is provided)
|
|
54
54
|
- bool/string - default: `false`
|
package/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import readZip from './lib/read-zip.js';
|
|
2
|
+
import fsUtils from '@tryghost/mg-fs-utils';
|
|
3
|
+
import map from './lib/mapper.js';
|
|
4
|
+
import process from './lib/process.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const parseString = fsUtils.csv.parseString;
|
|
7
|
+
|
|
8
|
+
const ingest = async (ctx) => {
|
|
7
9
|
// Extract the ZIP file
|
|
8
10
|
let zipContent = readZip(ctx.options.pathToZip);
|
|
9
11
|
|
|
10
12
|
// Convert the included CSV data to a JSON object
|
|
11
|
-
zipContent.meta =
|
|
13
|
+
zipContent.meta = parseString(zipContent.csv);
|
|
12
14
|
|
|
13
15
|
// Remove the CSV data from the extracted data object
|
|
14
16
|
delete zipContent.csv;
|
|
@@ -19,4 +21,7 @@ module.exports.ingest = async (ctx) => {
|
|
|
19
21
|
return mapped;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
export default {
|
|
25
|
+
ingest,
|
|
26
|
+
process
|
|
27
|
+
};
|
package/lib/mapper.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {formatISO, parseISO, isBefore, isAfter, add} from 'date-fns';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import errors from '@tryghost/errors';
|
|
4
|
+
import {slugify} from '@tryghost/string';
|
|
5
5
|
|
|
6
6
|
const mapConfig = (data, {url, email, useMetaAuthor}) => {
|
|
7
7
|
const slug = data.post_id.replace(/^(?:\d{1,10}\.)(\S*)/gm, '$1');
|
|
@@ -89,7 +89,7 @@ const mapConfig = (data, {url, email, useMetaAuthor}) => {
|
|
|
89
89
|
*
|
|
90
90
|
* @returns {Array} A singular array of post objects, in a structure compatible with the other Migrate tools
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
export default async (input, options) => {
|
|
93
93
|
const output = {
|
|
94
94
|
posts: []
|
|
95
95
|
};
|
package/lib/process.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {promises as fs} from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import url from 'node:url';
|
|
4
|
+
import $ from 'cheerio';
|
|
5
|
+
import errors from '@tryghost/errors';
|
|
6
|
+
import SimpleDom from 'simple-dom';
|
|
7
|
+
import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';
|
|
8
8
|
|
|
9
9
|
const getFiles = async (filePath) => {
|
|
10
10
|
let filenames = await fs.readdir(filePath);
|
|
@@ -33,7 +33,11 @@ const getUnsizedImageName = (str) => {
|
|
|
33
33
|
let last = srcParts.slice(-1)[0];
|
|
34
34
|
let matches = noSizeRegex.exec(last);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
if (matches) {
|
|
37
|
+
return matches[1];
|
|
38
|
+
} else {
|
|
39
|
+
return str;
|
|
40
|
+
}
|
|
37
41
|
};
|
|
38
42
|
|
|
39
43
|
const processContent = (post, siteUrl, options) => {
|
|
@@ -313,7 +317,7 @@ const processPost = (post, siteUrl, options) => {
|
|
|
313
317
|
return post;
|
|
314
318
|
};
|
|
315
319
|
|
|
316
|
-
|
|
320
|
+
export default async (input, ctx) => {
|
|
317
321
|
let {postsDir, options} = ctx;
|
|
318
322
|
let {url: siteUrl} = options;
|
|
319
323
|
const output = {};
|
|
@@ -340,4 +344,4 @@ module.exports = async (input, ctx) => {
|
|
|
340
344
|
return output;
|
|
341
345
|
};
|
|
342
346
|
|
|
343
|
-
|
|
347
|
+
export {processContent};
|
package/lib/read-zip.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"dev": "echo \"Implement me!\"",
|
|
10
|
-
"test": "
|
|
11
|
+
"test": "node --experimental-vm-modules $(yarn bin jest)",
|
|
11
12
|
"lint": "eslint . --ext .js --cache",
|
|
12
13
|
"posttest": "yarn lint"
|
|
13
14
|
},
|
|
@@ -19,18 +20,18 @@
|
|
|
19
20
|
"access": "public"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"eslint": "8.25.0",
|
|
24
|
+
"jest": "29.1.2",
|
|
25
|
+
"jest-extended": "3.1.0"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@tryghost/errors": "1.2.
|
|
28
|
-
"@tryghost/kg-default-cards": "5.18.
|
|
29
|
-
"@tryghost/mg-fs-utils": "^0.
|
|
28
|
+
"@tryghost/errors": "1.2.18",
|
|
29
|
+
"@tryghost/kg-default-cards": "5.18.3",
|
|
30
|
+
"@tryghost/mg-fs-utils": "^0.10.0",
|
|
30
31
|
"@tryghost/string": "0.2.1",
|
|
31
32
|
"date-fns": "2.29.3",
|
|
32
33
|
"lodash": "4.17.21",
|
|
33
34
|
"simple-dom": "1.4.0"
|
|
34
35
|
},
|
|
35
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "35cb5c1ca6a826e1e596c4f2e209ab690fa06fa0"
|
|
36
37
|
}
|