@tryghost/mg-ghost-api 0.2.18 → 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 +2 -2
- package/index.js +8 -6
- package/lib/fetch.js +10 -5
- package/lib/processor.js +21 -12
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -39,8 +39,8 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
39
39
|
- **`-s` `--scrape`**
|
|
40
40
|
- Configure scraping tasks
|
|
41
41
|
- string - default: `all`
|
|
42
|
-
- Choices: `all`, `img`, `web`, `media`, `none`
|
|
43
|
-
- **`--
|
|
42
|
+
- Choices: `all`, `img`, `web`, `media`, `files`, `none`
|
|
43
|
+
- **`--sizeLimit`**
|
|
44
44
|
- number - default: `false`
|
|
45
45
|
- Media files larger than this size (defined in MB [i.e. `5`]) will be flagged as oversize
|
|
46
46
|
- **`-I` `--info`**
|
package/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fetch from './lib/fetch.js';
|
|
2
|
+
import process from './lib/processor.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const discover = fetch.discover;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export default {
|
|
7
|
+
discover,
|
|
8
|
+
fetch,
|
|
9
|
+
process
|
|
10
|
+
};
|
package/lib/fetch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import ghostAPI from '@tryghost/admin-api';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const discover = async (options) => {
|
|
4
4
|
const requestOptions = {
|
|
5
5
|
url: options.url,
|
|
6
6
|
version: 'v2',
|
|
@@ -94,12 +94,12 @@ const buildTasks = (fileCache, tasks, api, type, options) => {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
const tasks = async (options, ctx) => {
|
|
98
98
|
const {limit} = ctx.options;
|
|
99
99
|
|
|
100
|
-
const api = await
|
|
100
|
+
const api = await discover(options, {limit});
|
|
101
101
|
|
|
102
|
-
const tasks = [];
|
|
102
|
+
const tasks = []; // eslint-disable-line no-shadow
|
|
103
103
|
|
|
104
104
|
ctx.result = {
|
|
105
105
|
posts: [],
|
|
@@ -112,3 +112,8 @@ module.exports.tasks = async (options, ctx) => {
|
|
|
112
112
|
|
|
113
113
|
return tasks;
|
|
114
114
|
};
|
|
115
|
+
|
|
116
|
+
export default {
|
|
117
|
+
discover,
|
|
118
|
+
tasks
|
|
119
|
+
};
|
package/lib/processor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const processTags = (ghTags) => {
|
|
2
2
|
let tags = [];
|
|
3
3
|
|
|
4
4
|
ghTags.forEach((tag) => {
|
|
@@ -23,16 +23,16 @@ module.exports.processTags = (ghTags) => {
|
|
|
23
23
|
return tags;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const processPost = (ghPost) => {
|
|
27
27
|
const post = {
|
|
28
28
|
url: ghPost.url,
|
|
29
29
|
data: ghPost
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
post.data.authors =
|
|
32
|
+
post.data.authors = processAuthors(ghPost.authors);
|
|
33
33
|
|
|
34
34
|
if (ghPost.tags && ghPost.tags.length > 0) {
|
|
35
|
-
post.data.tags =
|
|
35
|
+
post.data.tags = processTags(ghPost.tags);
|
|
36
36
|
} else {
|
|
37
37
|
delete post.data.tags;
|
|
38
38
|
}
|
|
@@ -40,11 +40,11 @@ module.exports.processPost = (ghPost) => {
|
|
|
40
40
|
return post;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
return posts.map(post =>
|
|
43
|
+
const processPosts = (posts) => {
|
|
44
|
+
return posts.map(post => processPost(post));
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const processAuthor = (ghAuthor) => {
|
|
48
48
|
let authorData = {
|
|
49
49
|
url: ghAuthor.url,
|
|
50
50
|
data: ghAuthor
|
|
@@ -59,15 +59,24 @@ module.exports.processAuthor = (ghAuthor) => {
|
|
|
59
59
|
return authorData;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
return authors.map(author =>
|
|
62
|
+
const processAuthors = (authors) => {
|
|
63
|
+
return authors.map(author => processAuthor(author));
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
const all = async ({result: input}) => {
|
|
67
67
|
const output = {};
|
|
68
68
|
|
|
69
|
-
output.users =
|
|
70
|
-
output.posts =
|
|
69
|
+
output.users = processAuthors(input.users);
|
|
70
|
+
output.posts = processPosts(input.posts, output.users);
|
|
71
71
|
|
|
72
72
|
return output;
|
|
73
73
|
};
|
|
74
|
+
|
|
75
|
+
export default {
|
|
76
|
+
processTags,
|
|
77
|
+
processPost,
|
|
78
|
+
processPosts,
|
|
79
|
+
processAuthor,
|
|
80
|
+
processAuthors,
|
|
81
|
+
all
|
|
82
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-ghost-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-ghost-api",
|
|
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,12 +20,12 @@
|
|
|
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
28
|
"@tryghost/admin-api": "1.13.1"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "35cb5c1ca6a826e1e596c4f2e209ab690fa06fa0"
|
|
30
31
|
}
|