@tryghost/mg-json 0.10.2 → 0.10.4
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.
|
@@ -4,12 +4,12 @@ import processPostRelations from './process-post-relations.js';
|
|
|
4
4
|
import validate from './validate.js';
|
|
5
5
|
import reorderTags from './reorder-tags.js';
|
|
6
6
|
|
|
7
|
-
export default (input, options = {}) => {
|
|
7
|
+
export default (input, options = {}, ctx) => {
|
|
8
8
|
// Construct a basic Ghost JSON template
|
|
9
9
|
let output = baseTemplate();
|
|
10
10
|
|
|
11
11
|
// Validate data and potentially alter if needed
|
|
12
|
-
input = validate(input);
|
|
12
|
+
input = validate(input, ctx);
|
|
13
13
|
|
|
14
14
|
// Reorder tags so #internal-tags appear last
|
|
15
15
|
input = reorderTags(input);
|
|
@@ -1,44 +1,31 @@
|
|
|
1
|
-
export default (json) => {
|
|
1
|
+
export default (json, ctx = null) => {
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
input.meta_title = input.meta_title.substring(0, 300);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (input.meta_description && input.meta_description.length > 500) {
|
|
33
|
-
input.meta_description = input.meta_description.substring(0, 500);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (input.email_subject && input.email_subject.length > 300) {
|
|
37
|
-
input.email_subject = input.email_subject.substring(0, 300);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (input.feature_image_alt && input.feature_image_alt.length > 125) {
|
|
41
|
-
input.feature_image_alt = input.feature_image_alt.substring(0, 125);
|
|
5
|
+
// String length data from https://github.com/TryGhost/Ghost/blob/main/ghost/core/core/server/data/schema/schema.js
|
|
6
|
+
let properties = {
|
|
7
|
+
slug: 191,
|
|
8
|
+
custom_excerpt: 300,
|
|
9
|
+
og_title: 300,
|
|
10
|
+
og_description: 500,
|
|
11
|
+
twitter_title: 300,
|
|
12
|
+
twitter_description: 500,
|
|
13
|
+
meta_title: 300,
|
|
14
|
+
meta_description: 500,
|
|
15
|
+
email_subject: 300,
|
|
16
|
+
feature_image_alt: 125
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
for (const [propKey, propValue] of Object.entries(properties)) {
|
|
20
|
+
if (input[propKey] && input[propKey].length > propValue) {
|
|
21
|
+
let truncated = input[propKey].substring(0, propValue);
|
|
22
|
+
|
|
23
|
+
if (ctx && ctx.logger) {
|
|
24
|
+
ctx.logger.warn({message: `${propKey} "${input[propKey]}" is longer than ${propValue} characters, truncating to "${truncated}"`});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
input[propKey] = truncated;
|
|
28
|
+
}
|
|
42
29
|
}
|
|
43
30
|
|
|
44
31
|
json.posts[index].data = input;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-json",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-json",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
23
|
+
"eslint": "8.36.0",
|
|
24
24
|
"jest": "29.5.0",
|
|
25
25
|
"jest-extended": "3.2.4"
|
|
26
26
|
},
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"html-entities": "2.3.3",
|
|
31
31
|
"lodash": "4.17.21"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "9601c998cb107ea3a64a67da3018a4d7ff22e7a3"
|
|
34
34
|
}
|