@tryghost/mg-medium-export 0.17.29 → 0.19.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 CHANGED
@@ -79,7 +79,7 @@ This will process all posts from the zip file, and all authors will have an emai
79
79
 
80
80
  ## Develop
81
81
 
82
- This is a mono repository, managed with [lerna](https://lerna.js.org).
82
+ This is a mono repository, managed with [Nx](https://nx.dev/) and yarn workspaces.
83
83
 
84
84
  Follow the instructions for the top-level repo.
85
85
  1. `git clone` this repo & `cd` into it as usual
@@ -83,102 +83,102 @@ const processTags = ({tagLinks}) => {
83
83
  };
84
84
 
85
85
  const processFeatureImage = ({html, post, options}) => {
86
- const parsed = domUtils.parseFragment(html);
87
-
88
- // Look for data-is-featured
89
- let featured = parsed.$('[data-is-featured]')[0] || null;
86
+ return domUtils.processFragment(html, (parsed) => {
87
+ // Look for data-is-featured
88
+ let featured = parsed.$('[data-is-featured]')[0] || null;
89
+
90
+ // Look for an image that appears before content
91
+ let allSections = parsed.$(sectionTags.join(','));
92
+ let foundImg = false;
93
+ let preImageTags = [];
94
+
95
+ allSections.forEach((el) => {
96
+ if (!foundImg) {
97
+ preImageTags.push(el.tagName.toLowerCase());
98
+ }
90
99
 
91
- // Look for an image that appears before content
92
- let allSections = parsed.$(sectionTags.join(','));
93
- let foundImg = false;
94
- let preImageTags = [];
100
+ if (!foundImg && el.tagName.toLowerCase() === 'img') {
101
+ foundImg = el;
102
+ }
103
+ });
95
104
 
96
- allSections.forEach((el) => {
97
- if (!foundImg) {
98
- preImageTags.push(el.tagName.toLowerCase());
105
+ // We don't have a designated feature image, but there's an image above the content so use that image instead
106
+ if (!featured && !preImageTags.includes('p')) {
107
+ featured = foundImg;
108
+
109
+ if (options?.addPlatformTag) {
110
+ // tag it with #auto-feature-image so we can tell the difference
111
+ post.data.tags.push({
112
+ data: {
113
+ name: '#auto-feature-image'
114
+ }
115
+ });
116
+ }
99
117
  }
100
118
 
101
- if (!foundImg && el.tagName.toLowerCase() === 'img') {
102
- foundImg = el;
119
+ if (featured) {
120
+ post.data.feature_image = featured.getAttribute('src');
121
+ post.data.feature_image_alt = featured.getAttribute('alt') || null;
122
+ const figure = featured.closest('figure');
123
+ const figcaption = figure ? figure.querySelector('figcaption') : null;
124
+ post.data.feature_image_caption = figcaption ? domUtils.serializeChildren(figcaption).trim() : null;
125
+
126
+ if (figure) {
127
+ figure.remove();
128
+ }
103
129
  }
130
+
131
+ return parsed.html().trim();
104
132
  });
133
+ };
134
+
135
+ export default ({name, html, globalUser, options}) => {
136
+ return domUtils.processFragment(html, (parsed) => {
137
+ let post = processMeta({name, parsed, options});
138
+
139
+ // Process author
140
+ const pAuthor = parsed.$('.p-author')[0];
141
+ if (pAuthor) {
142
+ post.data.author = processAuthor({pAuthor});
143
+ } else if (globalUser) {
144
+ post.data.author = globalUser;
145
+ }
105
146
 
106
- // We don't have a designated feature image, but there's an image above the content so use that image instead
107
- if (!featured && !preImageTags.includes('p')) {
108
- featured = foundImg;
147
+ post.data.tags = [];
109
148
 
110
- if (options?.addPlatformTag) {
111
- // tag it with #auto-feature-image so we can tell the difference
149
+ if (options?.addTag) {
112
150
  post.data.tags.push({
151
+ url: 'migrator-added-tag',
113
152
  data: {
114
- name: '#auto-feature-image'
153
+ name: options.addTag
115
154
  }
116
155
  });
117
156
  }
118
- }
119
157
 
120
- if (featured) {
121
- post.data.feature_image = featured.getAttribute('src');
122
- post.data.feature_image_alt = featured.getAttribute('alt') || null;
123
- const figure = featured.closest('figure');
124
- const figcaption = figure ? figure.querySelector('figcaption') : null;
125
- post.data.feature_image_caption = figcaption ? domUtils.serializeChildren(figcaption).trim() : null;
126
-
127
- if (figure) {
128
- figure.remove();
158
+ // Process tags
159
+ const tagLinks = parsed.$('.p-tags a');
160
+ if (tagLinks.length) {
161
+ post.data.tags = [...post.data.tags, ...processTags({tagLinks})];
129
162
  }
130
- }
131
163
 
132
- return parsed.html().trim();
133
- };
134
-
135
- export default ({name, html, globalUser, options}) => {
136
- const parsed = domUtils.parseFragment(html);
137
-
138
- let post = processMeta({name, parsed, options});
139
-
140
- // Process author
141
- const pAuthor = parsed.$('.p-author')[0];
142
- if (pAuthor) {
143
- post.data.author = processAuthor({pAuthor});
144
- } else if (globalUser) {
145
- post.data.author = globalUser;
146
- }
147
-
148
- post.data.tags = [];
149
-
150
- if (options?.addTag) {
151
- post.data.tags.push({
152
- url: 'migrator-added-tag',
153
- data: {
154
- name: options.addTag
155
- }
156
- });
157
- }
158
-
159
- // Process tags
160
- const tagLinks = parsed.$('.p-tags a');
161
- if (tagLinks.length) {
162
- post.data.tags = [...post.data.tags, ...processTags({tagLinks})];
163
- }
164
-
165
- if (options?.addPlatformTag) {
166
- post.data.tags.push({
167
- url: 'migrator-added-platform-tag',
168
- data: {
169
- name: '#medium'
170
- }
171
- });
172
- }
164
+ if (options?.addPlatformTag) {
165
+ post.data.tags.push({
166
+ url: 'migrator-added-platform-tag',
167
+ data: {
168
+ name: '#medium'
169
+ }
170
+ });
171
+ }
173
172
 
174
- // Process content
175
- const eContent = parsed.$('.e-content')[0];
176
- const contentHtml = eContent ? domUtils.serializeChildren(eContent) : '';
177
- post = processContent({html: contentHtml, post});
173
+ // Process content
174
+ const eContent = parsed.$('.e-content')[0];
175
+ const contentHtml = eContent ? domUtils.serializeChildren(eContent) : '';
176
+ post = processContent({html: contentHtml, post});
178
177
 
179
- // Grab the featured image
180
- // Do this last so that we can add tags to indicate feature image style
181
- post.data.html = processFeatureImage({html: post.data.html, post, options});
178
+ // Grab the featured image
179
+ // Do this last so that we can add tags to indicate feature image style
180
+ post.data.html = processFeatureImage({html: post.data.html, post, options});
182
181
 
183
- return post;
182
+ return post;
183
+ });
184
184
  };
@@ -1,4 +1,5 @@
1
1
  import {domUtils} from '@tryghost/mg-utils';
2
+ const {processFragment} = domUtils;
2
3
 
3
4
  // Keys we've seen so far
4
5
  // Profile
@@ -22,26 +23,27 @@ const mediumToGhost = {
22
23
  };
23
24
 
24
25
  export default ({html}) => {
25
- const parsed = domUtils.parseFragment(html);
26
- let profile = {
27
- url: parsed.$('.u-url')[0]?.getAttribute('href'),
28
- data: {
29
- name: parsed.$('.p-name')[0]?.textContent || '',
30
- profile_image: parsed.$('.u-photo')[0]?.getAttribute('src'),
31
- roles: [
32
- 'Contributor'
33
- ]
34
- }
35
- };
26
+ return processFragment(html, (parsed) => {
27
+ let profile = {
28
+ url: parsed.$('.u-url')[0]?.getAttribute('href'),
29
+ data: {
30
+ name: parsed.$('.p-name')[0]?.textContent || '',
31
+ profile_image: parsed.$('.u-photo')[0]?.getAttribute('src'),
32
+ roles: [
33
+ 'Contributor'
34
+ ]
35
+ }
36
+ };
36
37
 
37
- parsed.$('ul li').forEach((el) => {
38
- let [item, value] = el.textContent.split(': ');
39
- let key = mediumToGhost[item.toLowerCase()] || null;
38
+ parsed.$('ul li').forEach((el) => {
39
+ let [item, value] = el.textContent.split(': ');
40
+ let key = mediumToGhost[item.toLowerCase()] || null;
40
41
 
41
- if (key) {
42
- profile.data[key] = value;
43
- }
44
- });
42
+ if (key) {
43
+ profile.data[key] = value;
44
+ }
45
+ });
45
46
 
46
- return profile;
47
+ return profile;
48
+ });
47
49
  };
package/lib/process.js CHANGED
@@ -11,7 +11,13 @@ export default (input, options) => {
11
11
  let globalUser = output.users && output.users.length === 1 ? output.users[0] : null;
12
12
 
13
13
  if (input.posts && input.posts.length > 0) {
14
- output.posts = input.posts.map(post => processPost({name: post.name, html: post.html, globalUser, options}));
14
+ output.posts = [];
15
+ for (let i = 0; i < input.posts.length; i++) {
16
+ const post = input.posts[i];
17
+ if (post) {
18
+ output.posts.push(processPost({name: post.name, html: post.html, globalUser, options}));
19
+ }
20
+ }
15
21
  }
16
22
 
17
23
  return output;
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@tryghost/mg-medium-export",
3
- "version": "0.17.29",
3
+ "version": "0.19.0",
4
4
  "description": "tbc",
5
- "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-medium-export",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/TryGhost/migrate.git",
8
+ "directory": "packages/mg-medium-export"
9
+ },
6
10
  "author": "Ghost Foundation",
7
11
  "license": "MIT",
8
12
  "main": "index.js",
@@ -10,8 +14,8 @@
10
14
  "scripts": {
11
15
  "dev": "echo \"Implement me!\"",
12
16
  "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --statements 100 node --test 'test/**/*.test.js'",
13
- "lint": "eslint . --ext .js --cache",
14
- "posttest": "yarn lint"
17
+ "posttest": "yarn lint",
18
+ "lint": "eslint . --ext .js --cache"
15
19
  },
16
20
  "files": [
17
21
  "index.js",
@@ -27,10 +31,9 @@
27
31
  "dependencies": {
28
32
  "@tryghost/debug": "2.0.3",
29
33
  "@tryghost/kg-default-cards": "10.2.10",
30
- "@tryghost/mg-fs-utils": "0.16.7",
31
- "@tryghost/mg-utils": "0.1.2",
34
+ "@tryghost/mg-fs-utils": "0.18.0",
35
+ "@tryghost/mg-utils": "0.3.0",
32
36
  "@tryghost/string": "0.3.1",
33
37
  "simple-dom": "1.4.0"
34
- },
35
- "gitHead": "dfaf02f58e6598ec4abb56a568eb1b6a65ee12f4"
38
+ }
36
39
  }