@tryghost/mg-medium-export 0.12.3 → 0.13.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 +2 -0
- package/lib/read-zip.js +40 -15
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -28,6 +28,8 @@ To run a Medium migration, the required command is:
|
|
|
28
28
|
migrate medium <path to zip file>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
**Note:** The zip path can be to a singular zip file or a folder of zip files
|
|
32
|
+
|
|
31
33
|
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
32
34
|
|
|
33
35
|
- **`-V` `--verbose`**
|
package/lib/read-zip.js
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
|
+
import {lstatSync, readdirSync} from 'node:fs';
|
|
2
|
+
import {join} from 'node:path';
|
|
1
3
|
import fsUtils from '@tryghost/mg-fs-utils';
|
|
2
4
|
import {ui} from '@tryghost/pretty-cli';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
let content = {
|
|
6
|
-
posts: []
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
let skippedFileCount = 0;
|
|
10
|
-
|
|
11
|
-
// We only support the current Medium export file structure:
|
|
12
|
-
// - posts
|
|
13
|
-
// - the-post-name-b3h4k5l6b2u5.html
|
|
14
|
-
// - another-post-name-w9g8b5a4v6n8.html
|
|
15
|
-
// - profile
|
|
16
|
-
// - file.html
|
|
17
|
-
|
|
6
|
+
const readMediumZip = ({content, zipPath, options, skippedFileCount}) => {
|
|
18
7
|
fsUtils.zip.read(zipPath, (entryName, zipEntry) => {
|
|
19
8
|
// Catch all HTML files inside `profile/`
|
|
20
9
|
if (/^profile\/profile\.html/.test(entryName)) {
|
|
21
|
-
content.
|
|
10
|
+
content.profiles.push({data: zipEntry.getData().toString('utf8')});
|
|
22
11
|
|
|
23
12
|
// Catch all HTML files in `posts/`
|
|
24
13
|
} else if (/^posts\/.*\.html$/.test(entryName)) {
|
|
@@ -36,6 +25,42 @@ export default (zipPath, options) => {
|
|
|
36
25
|
}
|
|
37
26
|
});
|
|
38
27
|
|
|
28
|
+
return {
|
|
29
|
+
content,
|
|
30
|
+
skippedFileCount
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default (zipPath, options) => {
|
|
35
|
+
let content = {
|
|
36
|
+
profiles: [],
|
|
37
|
+
posts: []
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let skippedFileCount = 0;
|
|
41
|
+
|
|
42
|
+
// We only support the current Medium export file structure:
|
|
43
|
+
// - posts
|
|
44
|
+
// - the-post-name-b3h4k5l6b2u5.html
|
|
45
|
+
// - another-post-name-w9g8b5a4v6n8.html
|
|
46
|
+
// - profile
|
|
47
|
+
// - file.html
|
|
48
|
+
|
|
49
|
+
const ifIsDirectory = lstatSync(zipPath).isDirectory();
|
|
50
|
+
|
|
51
|
+
if (ifIsDirectory) {
|
|
52
|
+
readdirSync(zipPath).forEach((file) => {
|
|
53
|
+
const filePath = join(zipPath, file);
|
|
54
|
+
const zipContent = readMediumZip({content, zipPath: filePath, options, skippedFileCount});
|
|
55
|
+
content = zipContent.content;
|
|
56
|
+
skippedFileCount = zipContent.skippedFileCount;
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
const zipContent = readMediumZip({content, zipPath, options, skippedFileCount});
|
|
60
|
+
content = zipContent.content;
|
|
61
|
+
skippedFileCount = zipContent.skippedFileCount;
|
|
62
|
+
}
|
|
63
|
+
|
|
39
64
|
ui.log.info('Skipped files: ' + skippedFileCount);
|
|
40
65
|
|
|
41
66
|
return content;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-medium-export",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "tbc",
|
|
5
5
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-medium-export",
|
|
6
6
|
"author": "Ghost Foundation",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"eslint": "8.
|
|
25
|
-
"jest": "29.2.
|
|
24
|
+
"eslint": "8.26.0",
|
|
25
|
+
"jest": "29.2.2",
|
|
26
26
|
"jest-extended": "3.1.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@tryghost/mg-fs-utils": "^0.
|
|
29
|
+
"@tryghost/mg-fs-utils": "^0.11.0",
|
|
30
30
|
"@tryghost/string": "^0.2.0",
|
|
31
31
|
"cheerio": "0.22.0",
|
|
32
32
|
"date-fns": "2.29.3"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "49293c6abb8c3d32ff2d7c97b90fbea25fe4a4ef"
|
|
35
35
|
}
|