@tryghost/mg-json 0.7.3 → 0.8.3
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/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/to-ghost-json/process-post-relations.js +37 -1
- package/lib/to-ghost-json/validate.js +25 -0
- package/lib/utils/schema.js +1 -1
- package/package.json +8 -8
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ module.exports = (json) => {
|
|
|
9
9
|
// We create these fresh as all relation processing should be done in here
|
|
10
10
|
json.posts_authors = [];
|
|
11
11
|
json.posts_tags = [];
|
|
12
|
+
json.posts_meta = [];
|
|
12
13
|
|
|
13
14
|
const findPostRelations = (postData, relation) => {
|
|
14
15
|
let relations = [];
|
|
@@ -29,7 +30,7 @@ module.exports = (json) => {
|
|
|
29
30
|
if (!_.has(json, location)) {
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
|
-
return json[location].find((item) => {
|
|
33
|
+
return json[location].find((item) => { // eslint-disable-line array-callback-return
|
|
33
34
|
// @TODO: need to scrape, or post-process scrape for user and tag slugs
|
|
34
35
|
if (item.data.id && item.data.id === match.data.id) {
|
|
35
36
|
return item;
|
|
@@ -89,6 +90,40 @@ module.exports = (json) => {
|
|
|
89
90
|
});
|
|
90
91
|
};
|
|
91
92
|
|
|
93
|
+
const processPostMeta = (postData) => {
|
|
94
|
+
let postMeta = {
|
|
95
|
+
post_id: postData.id
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// List from https://github.com/TryGhost/Ghost/blob/main/core/server/data/schema/schema.js#L63-L79
|
|
99
|
+
const metaKeys = [
|
|
100
|
+
'og_image',
|
|
101
|
+
'og_title',
|
|
102
|
+
'og_description',
|
|
103
|
+
'twitter_image',
|
|
104
|
+
'twitter_title',
|
|
105
|
+
'twitter_description',
|
|
106
|
+
'meta_title',
|
|
107
|
+
'meta_description',
|
|
108
|
+
'email_subject',
|
|
109
|
+
'frontmatter',
|
|
110
|
+
'feature_image_alt',
|
|
111
|
+
'feature_image_caption',
|
|
112
|
+
'email_only'
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
metaKeys.forEach((item) => {
|
|
116
|
+
if (postData[item]) {
|
|
117
|
+
postMeta[item] = postData[item];
|
|
118
|
+
delete postData[item];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
json.posts_meta.push(postMeta);
|
|
123
|
+
|
|
124
|
+
return postData;
|
|
125
|
+
};
|
|
126
|
+
|
|
92
127
|
const processPostRelations = (post) => {
|
|
93
128
|
try {
|
|
94
129
|
// Ensure we have a post ID
|
|
@@ -98,6 +133,7 @@ module.exports = (json) => {
|
|
|
98
133
|
|
|
99
134
|
processPostAuthors(post.data);
|
|
100
135
|
processPostTags(post.data);
|
|
136
|
+
post.data = processPostMeta(post.data);
|
|
101
137
|
} catch (error) {
|
|
102
138
|
error.reference = post.url;
|
|
103
139
|
throw error;
|
|
@@ -2,16 +2,41 @@ module.exports = (json) => {
|
|
|
2
2
|
json.posts.forEach((item, index) => {
|
|
3
3
|
let input = item.data;
|
|
4
4
|
|
|
5
|
+
// String length data from https://github.com/TryGhost/Ghost/blob/main/core/server/data/schema/schema.js
|
|
5
6
|
// @TODO: log some sort of warning for things like this?
|
|
6
7
|
|
|
7
8
|
if (input.custom_excerpt && input.custom_excerpt.length > 300) {
|
|
8
9
|
input.custom_excerpt = input.custom_excerpt.substring(0, 300);
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
if (input.og_title && input.og_title.length > 300) {
|
|
13
|
+
input.og_title = input.og_title.substring(0, 300);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (input.og_description && input.og_description.length > 500) {
|
|
17
|
+
input.og_description = input.og_description.substring(0, 500);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (input.twitter_title && input.twitter_title.length > 300) {
|
|
21
|
+
input.twitter_title = input.twitter_title.substring(0, 300);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (input.twitter_description && input.twitter_description.length > 500) {
|
|
25
|
+
input.twitter_description = input.twitter_description.substring(0, 500);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (input.meta_title && input.meta_title.length > 300) {
|
|
29
|
+
input.meta_title = input.meta_title.substring(0, 300);
|
|
30
|
+
}
|
|
31
|
+
|
|
11
32
|
if (input.meta_description && input.meta_description.length > 500) {
|
|
12
33
|
input.meta_description = input.meta_description.substring(0, 500);
|
|
13
34
|
}
|
|
14
35
|
|
|
36
|
+
if (input.email_subject && input.email_subject.length > 300) {
|
|
37
|
+
input.email_subject = input.email_subject.substring(0, 300);
|
|
38
|
+
}
|
|
39
|
+
|
|
15
40
|
if (input.feature_image_alt && input.feature_image_alt.length > 125) {
|
|
16
41
|
input.feature_image_alt = input.feature_image_alt.substring(0, 125);
|
|
17
42
|
}
|
package/lib/utils/schema.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// @TODO extend this to all importable Ghost resources
|
|
6
6
|
module.exports.RESOURCES = [
|
|
7
|
-
'posts', '
|
|
7
|
+
'posts', 'posts_authors', 'posts_meta', 'posts_tags', 'tags', 'users'
|
|
8
8
|
];
|
|
9
9
|
|
|
10
10
|
module.exports.RESOURCE_SINGULAR_TO_PLURAL = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-json",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"repository": "https://github.com/TryGhost/migrate/tree/
|
|
3
|
+
"version": "0.8.3",
|
|
4
|
+
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-json",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"mocha": "9.
|
|
22
|
+
"mocha": "9.2.2",
|
|
23
23
|
"should": "13.2.3",
|
|
24
|
-
"sinon": "
|
|
24
|
+
"sinon": "13.0.2"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tryghost/string": "0.1.
|
|
28
|
-
"bson-objectid": "2.0.
|
|
29
|
-
"html-entities": "2.3.
|
|
27
|
+
"@tryghost/string": "0.1.23",
|
|
28
|
+
"bson-objectid": "2.0.3",
|
|
29
|
+
"html-entities": "2.3.3",
|
|
30
30
|
"lodash": "4.17.21"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "0b3c4695d98527db9559444d81eaf9afcf2d1b6a"
|
|
33
33
|
}
|