@tryghost/mg-json 0.11.9 → 0.11.11

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.
@@ -3,6 +3,7 @@ import stripMeta from './meta-to-ghost.js';
3
3
  import processPostRelations from './process-post-relations.js';
4
4
  import validate from './validate.js';
5
5
  import reorderTags from './reorder-tags.js';
6
+ import {removeEmptyUsers} from './remove-empty.js';
6
7
 
7
8
  export default async (input, options = {}, ctx) => {
8
9
  // Construct a basic Ghost JSON template
@@ -20,5 +21,8 @@ export default async (input, options = {}, ctx) => {
20
21
  // Strip any meta data from the input / flatten structures
21
22
  output.data = stripMeta(output.data, options);
22
23
 
24
+ // Remove empty users (without posts)
25
+ output.data = removeEmptyUsers(output.data);
26
+
23
27
  return output;
24
28
  };
@@ -0,0 +1,24 @@
1
+ const removeEmptyUsers = (data) => {
2
+ // Assign temp IDs to users without IDs
3
+ data.users.forEach((user) => {
4
+ if (!user.id || user.id === '') {
5
+ user.id = `temp-id-${Math.random().toString(36).substring(2, 15)}`;
6
+ }
7
+ });
8
+
9
+ // Remove users without posts and their role associations
10
+ const userIdsWithPosts = new Set(
11
+ data.posts_authors.map(pa => pa.author_id)
12
+ );
13
+
14
+ data.users = data?.users?.filter(user => userIdsWithPosts.has(user.id)) || [];
15
+ if (data?.roles_users) {
16
+ data.roles_users = data?.roles_users?.filter(ru => userIdsWithPosts.has(ru.user_id)) || [];
17
+ }
18
+
19
+ return data;
20
+ };
21
+
22
+ export {
23
+ removeEmptyUsers
24
+ };
@@ -24,17 +24,35 @@ export default async (json) => {
24
24
  feature_image_alt: 125
25
25
  };
26
26
 
27
+ let tagProperties = {
28
+ name: 185,
29
+ slug: 185
30
+ };
31
+
27
32
  for (const [propKey, propValue] of Object.entries(properties)) {
28
33
  if (input[propKey] && input[propKey].length > propValue) {
29
34
  let truncated = input[propKey].substring(0, propValue).trim();
30
35
 
31
36
  // eslint-disable-next-line no-console
32
- console.warn(`${propKey} for slug "${item.data.slug}" is too long.\nOriginal: "${input[propKey]}"\nTruncated to: "${truncated}"`);
37
+ console.warn(`${propKey} for post slug "${item.data.slug}" is too long.\nOriginal: "${input[propKey]}"\nTruncated to: "${truncated}"`);
33
38
 
34
39
  input[propKey] = truncated;
35
40
  }
36
41
  }
37
42
 
43
+ input?.tags?.forEach((tag, iindex) => {
44
+ for (const [propKey, propValue] of Object.entries(tagProperties)) {
45
+ if (tag.data[propKey] && tag.data[propKey].length > propValue) {
46
+ let truncated = tag.data[propKey].substring(0, propValue).trim();
47
+
48
+ // eslint-disable-next-line no-console
49
+ console.warn(`${propKey} for tag slug "${input.tags[iindex].data.slug}" is too long.\nOriginal: "${input.tags[iindex].data[propKey]}"\nTruncated to: "${truncated}"`);
50
+
51
+ input.tags[iindex].data[propKey] = truncated;
52
+ }
53
+ }
54
+ });
55
+
38
56
  json.posts[index].data = input;
39
57
  });
40
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-json",
3
- "version": "0.11.9",
3
+ "version": "0.11.11",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-json",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -31,5 +31,5 @@
31
31
  "lodash": "4.17.21",
32
32
  "node-email-verifier": "2.0.0"
33
33
  },
34
- "gitHead": "89e6e38587face966cdfadfbbc74aef95c594c7c"
34
+ "gitHead": "93b72e5f4374d9f097876b71e78fdc920af364ff"
35
35
  }