@tryghost/mg-json 0.8.7 → 0.9.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/index.js +8 -2
- package/lib/to-ghost-json/base-template.js +3 -2
- package/lib/to-ghost-json/hydrate.js +12 -7
- package/lib/to-ghost-json/index.js +6 -6
- package/lib/to-ghost-json/meta-to-ghost.js +5 -5
- package/lib/to-ghost-json/process-post-relations.js +4 -4
- package/lib/to-ghost-json/reorder-tags.js +1 -1
- package/lib/to-ghost-json/validate.js +1 -1
- package/lib/utils/schema.js +9 -3
- package/package.json +7 -6
package/index.js
CHANGED
|
@@ -18,7 +18,13 @@
|
|
|
18
18
|
* }]
|
|
19
19
|
* }
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
import toGhostJSON from './lib/to-ghost-json/index.js';
|
|
22
|
+
import hydrate from './lib/to-ghost-json/hydrate.js';
|
|
22
23
|
|
|
23
24
|
// @TODO: validator
|
|
24
|
-
//
|
|
25
|
+
// import validate from './lib/validator.js';
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
toGhostJSON,
|
|
29
|
+
hydrate
|
|
30
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
|
|
2
3
|
const baseJSON = `{
|
|
3
4
|
"meta": {
|
|
4
5
|
"exported_on": <%= timestamp %>,
|
|
@@ -9,7 +10,7 @@ const baseJSON = `{
|
|
|
9
10
|
const baseTemplate = _.template(baseJSON);
|
|
10
11
|
const defaultVersion = '2.0.0';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
export default (version) => {
|
|
13
14
|
return JSON.parse(baseTemplate({
|
|
14
15
|
timestamp: Date.now(),
|
|
15
16
|
version: version || defaultVersion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import {slugify} from '@tryghost/string';
|
|
3
|
+
import Entities from 'html-entities';
|
|
4
4
|
/**
|
|
5
5
|
* Hydrate Ghost objects
|
|
6
6
|
* Extend object with the minimum data needed for an import to succeed
|
|
@@ -52,8 +52,7 @@ const hydrateUser = (input, options) => {
|
|
|
52
52
|
return input;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
module.exports.users = hydrateUser;
|
|
55
|
+
const users = hydrateUser;
|
|
57
56
|
|
|
58
57
|
/**
|
|
59
58
|
* Tags(s)
|
|
@@ -75,7 +74,7 @@ const hydrateTag = (input) => {
|
|
|
75
74
|
return input;
|
|
76
75
|
};
|
|
77
76
|
|
|
78
|
-
|
|
77
|
+
const tags = hydrateTag;
|
|
79
78
|
|
|
80
79
|
/**
|
|
81
80
|
* Post(s)
|
|
@@ -103,4 +102,10 @@ const hydratePost = (input, options) => {
|
|
|
103
102
|
return input;
|
|
104
103
|
};
|
|
105
104
|
|
|
106
|
-
|
|
105
|
+
const posts = hydratePost;
|
|
106
|
+
|
|
107
|
+
export default {
|
|
108
|
+
users,
|
|
109
|
+
tags,
|
|
110
|
+
posts
|
|
111
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import baseTemplate from './base-template.js';
|
|
2
|
+
import stripMeta from './meta-to-ghost.js';
|
|
3
|
+
import processPostRelations from './process-post-relations.js';
|
|
4
|
+
import validate from './validate.js';
|
|
5
|
+
import reorderTags from './reorder-tags.js';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export default (input, options = {}) => {
|
|
8
8
|
// Construct a basic Ghost JSON template
|
|
9
9
|
let output = baseTemplate();
|
|
10
10
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import ObjectID from 'bson-objectid';
|
|
3
|
+
import schema from '../utils/schema.js';
|
|
4
|
+
import hydrate from './hydrate.js';
|
|
5
5
|
/**
|
|
6
6
|
* A resource might be a plain resource ready for import, or if it came from our migrate tooling,
|
|
7
7
|
* probably an object with some metadata (like URL) and a `data` key with the resource fields
|
|
@@ -78,7 +78,7 @@ const normalizeValue = (value) => {
|
|
|
78
78
|
* We expect an object with keys that match Ghost resources
|
|
79
79
|
* Iterate over each key and return only ones that we recognise
|
|
80
80
|
*/
|
|
81
|
-
|
|
81
|
+
export default (input, options) => {
|
|
82
82
|
return _.reduce(input, (data, inputValue, inputKey) => {
|
|
83
83
|
let key = normalizeKey(inputKey);
|
|
84
84
|
let entries = normalizeValue(inputValue);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import ObjectID from 'bson-objectid';
|
|
3
|
+
import schema from '../utils/schema.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export default (json) => {
|
|
6
6
|
json.users = json.users || [];
|
|
7
7
|
json.tags = json.tags || []; // expected to be empty
|
|
8
8
|
|
package/lib/utils/schema.js
CHANGED
|
@@ -3,20 +3,26 @@
|
|
|
3
3
|
// From Ghost core, along with a bunch of utility classes
|
|
4
4
|
|
|
5
5
|
// @TODO extend this to all importable Ghost resources
|
|
6
|
-
|
|
6
|
+
const RESOURCES = [
|
|
7
7
|
'posts', 'posts_authors', 'posts_meta', 'posts_tags', 'tags', 'users'
|
|
8
8
|
];
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const RESOURCE_SINGULAR_TO_PLURAL = {
|
|
11
11
|
user: 'users',
|
|
12
12
|
author: 'authors',
|
|
13
13
|
post: 'posts',
|
|
14
14
|
tag: 'tags'
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const AUTHOR_ALIASES = [
|
|
18
18
|
'author',
|
|
19
19
|
'authors',
|
|
20
20
|
'primary_author',
|
|
21
21
|
'author_id'
|
|
22
22
|
];
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
RESOURCES,
|
|
26
|
+
RESOURCE_SINGULAR_TO_PLURAL,
|
|
27
|
+
AUTHOR_ALIASES
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
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",
|
|
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,9 +20,9 @@
|
|
|
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/string": "0.2.1",
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
"html-entities": "2.3.3",
|
|
30
31
|
"lodash": "4.17.21"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "35cb5c1ca6a826e1e596c4f2e209ab690fa06fa0"
|
|
33
34
|
}
|