@tryghost/mg-medium-export 0.17.28 → 0.18.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 +1 -1
- package/lib/process-content.js +78 -78
- package/lib/process-post.js +104 -115
- package/lib/process-profile.js +22 -20
- package/lib/process.js +7 -1
- package/package.json +10 -10
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 [
|
|
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
|
package/lib/process-content.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {domUtils} from '@tryghost/mg-utils';
|
|
2
2
|
import SimpleDom from 'simple-dom';
|
|
3
3
|
import galleryCard from '@tryghost/kg-default-cards/lib/cards/gallery.js';
|
|
4
4
|
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';
|
|
@@ -8,10 +8,10 @@ const doReplace = (str) => {
|
|
|
8
8
|
const replaceParts = [
|
|
9
9
|
[/[\s\n]/g, ''], // Remove spaces
|
|
10
10
|
[/\.$/, ''], // Trim trailing full stop
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[/\u2018/, '\''], // Convert single opening curly quote to straight quote
|
|
12
|
+
[/\u2019/, '\''], // Convert single closing curly quote to straight quote
|
|
13
|
+
[/\u201c/, '"'], // Convert double opening curly quote to straight quote
|
|
14
|
+
[/\u201d/, '"'] // Convert double closing curly quote to straight quote
|
|
15
15
|
];
|
|
16
16
|
|
|
17
17
|
replaceParts.forEach((re) => {
|
|
@@ -28,17 +28,14 @@ const equivalentTitles = (title1, title2) => {
|
|
|
28
28
|
return title1 === title2;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export default ({
|
|
32
|
-
|
|
33
|
-
// Uses default cheerio options (parse5) to decode entities and preserve empty attributes
|
|
34
|
-
const $ = cheerio.load(content.html(), {}, false);
|
|
35
|
-
let $content = $.root();
|
|
31
|
+
export default ({html, post}) => {
|
|
32
|
+
const parsed = domUtils.parseFragment(html);
|
|
36
33
|
|
|
37
34
|
// Detect if post is likely to be a comment. If so, set as draft and add tag
|
|
38
35
|
// Based on being published, content having 1 paragraph, and having no images
|
|
39
|
-
let childrenCount =
|
|
40
|
-
let pCount =
|
|
41
|
-
let imgCount =
|
|
36
|
+
let childrenCount = parsed.body.children.length;
|
|
37
|
+
let pCount = parsed.$('p').length;
|
|
38
|
+
let imgCount = parsed.$('img').length;
|
|
42
39
|
|
|
43
40
|
if (post.data.status === 'published' && childrenCount <= 1 && pCount <= 1 && imgCount === 0) {
|
|
44
41
|
post.data.status = 'draft';
|
|
@@ -53,38 +50,38 @@ export default ({content, post}) => {
|
|
|
53
50
|
|
|
54
51
|
// Medium usually has an hr divider at the very beginning of the content
|
|
55
52
|
// We don't need this so remove it if we find it
|
|
56
|
-
let
|
|
57
|
-
if (
|
|
58
|
-
|
|
53
|
+
let firstSection = parsed.$('.section--first')[0];
|
|
54
|
+
if (firstSection) {
|
|
55
|
+
let firstChild = firstSection.firstElementChild;
|
|
56
|
+
if (firstChild && firstChild.classList.contains('section-divider')) {
|
|
57
|
+
firstChild.remove();
|
|
58
|
+
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// Sometimes Medium has a duplicate header at the beginning of the content
|
|
62
62
|
// Don't need this either so remove it
|
|
63
|
-
let firstTitle =
|
|
64
|
-
if (equivalentTitles(firstTitle.
|
|
65
|
-
|
|
63
|
+
let firstTitle = parsed.$('h1, h2, h3, h4, blockquote')[0];
|
|
64
|
+
if (firstTitle && equivalentTitles(firstTitle.textContent, post.data.title)) {
|
|
65
|
+
firstTitle.remove();
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Remove the subtitle if it's the same as the excerpt
|
|
69
|
-
|
|
70
|
-
if (equivalentTitles(
|
|
71
|
-
|
|
69
|
+
parsed.$('.graf--subtitle').forEach((el) => {
|
|
70
|
+
if (equivalentTitles(el.textContent, post.data.custom_excerpt)) {
|
|
71
|
+
el.remove();
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
// Convert galleries
|
|
76
|
-
|
|
76
|
+
parsed.$('.section-inner.sectionLayout--outsetRow').forEach((el) => {
|
|
77
77
|
// Check we're only working with a group of <figure> elements
|
|
78
|
-
const children =
|
|
79
|
-
const
|
|
80
|
-
return ell.tagName.toLowerCase();
|
|
81
|
-
}).get();
|
|
82
|
-
const allFigures = childElementTags.every(e => e === 'figure');
|
|
78
|
+
const children = Array.from(el.children);
|
|
79
|
+
const allFigures = children.every(child => child.tagName.toLowerCase() === 'figure');
|
|
83
80
|
|
|
84
81
|
// If it's all figures
|
|
85
82
|
if (allFigures) {
|
|
86
|
-
let
|
|
87
|
-
let caption =
|
|
83
|
+
let figcaption = el.querySelector('figcaption');
|
|
84
|
+
let caption = figcaption ? domUtils.serializeChildren(figcaption).trim() : null;
|
|
88
85
|
|
|
89
86
|
let cardOpts = {
|
|
90
87
|
env: {dom: new SimpleDom.Document()},
|
|
@@ -94,105 +91,108 @@ export default ({content, post}) => {
|
|
|
94
91
|
}
|
|
95
92
|
};
|
|
96
93
|
|
|
97
|
-
|
|
98
|
-
let img =
|
|
94
|
+
el.querySelectorAll('figure').forEach((figure) => { // eslint-disable-line no-shadow
|
|
95
|
+
let img = figure.querySelector('img');
|
|
99
96
|
cardOpts.payload.images.push({
|
|
100
97
|
row: 0,
|
|
101
|
-
fileName: img.
|
|
102
|
-
src: img.
|
|
103
|
-
width: img.
|
|
104
|
-
height: img.
|
|
98
|
+
fileName: img.getAttribute('data-image-id'),
|
|
99
|
+
src: img.getAttribute('src'),
|
|
100
|
+
width: img.getAttribute('data-width'),
|
|
101
|
+
height: img.getAttribute('data-height')
|
|
105
102
|
});
|
|
106
103
|
});
|
|
107
104
|
|
|
108
105
|
const galleryHtml = serializer.serialize(galleryCard.render(cardOpts));
|
|
109
106
|
|
|
110
|
-
|
|
107
|
+
domUtils.replaceWith(el, galleryHtml);
|
|
111
108
|
}
|
|
112
109
|
});
|
|
113
110
|
|
|
114
111
|
// Convert Medium bookmarks
|
|
115
|
-
|
|
112
|
+
parsed.$('.graf--mixtapeEmbed').forEach((el) => {
|
|
116
113
|
let cardOpts = {
|
|
117
114
|
env: {dom: new SimpleDom.Document()},
|
|
118
115
|
payload: {}
|
|
119
116
|
};
|
|
120
117
|
|
|
121
|
-
let href =
|
|
118
|
+
let href = el.querySelector('.markup--anchor')?.getAttribute('href');
|
|
122
119
|
cardOpts.payload.url = href;
|
|
123
120
|
|
|
124
121
|
cardOpts.payload.metadata = {
|
|
125
122
|
url: href,
|
|
126
|
-
title:
|
|
127
|
-
description:
|
|
123
|
+
title: el.querySelector('.markup--strong')?.textContent || '',
|
|
124
|
+
description: el.querySelector('.markup--em')?.textContent || ''
|
|
128
125
|
};
|
|
129
126
|
|
|
130
|
-
const
|
|
127
|
+
const mixtapeImage = el.querySelector('.js-mixtapeImage');
|
|
128
|
+
const bngImage = mixtapeImage ? mixtapeImage.style.backgroundImage : null;
|
|
131
129
|
if (bngImage) {
|
|
132
|
-
let src = bngImage.replace(/url\((.*?)
|
|
130
|
+
let src = bngImage.replace(/url\(["']?(.*?)["']?\)/, (m, p) => p);
|
|
133
131
|
cardOpts.payload.metadata.thumbnail = src;
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
const bookmarkHtml = serializer.serialize(bookmarkCard.render(cardOpts));
|
|
137
135
|
|
|
138
|
-
|
|
136
|
+
domUtils.replaceWith(el, `<!--kg-card-begin: html-->\n${bookmarkHtml}\n<!--kg-card-end: html-->`);
|
|
139
137
|
});
|
|
140
138
|
|
|
141
139
|
// Handle blockquotes made of 2 elements
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
140
|
+
parsed.$('blockquote.graf--pullquote, blockquote.graf--blockquote').forEach((bq) => {
|
|
141
|
+
bq.removeAttribute('name');
|
|
142
|
+
bq.removeAttribute('id');
|
|
143
|
+
bq.removeAttribute('class');
|
|
144
|
+
|
|
145
|
+
bq.querySelectorAll('a').forEach((a) => {
|
|
146
|
+
a.removeAttribute('data-href');
|
|
147
|
+
a.removeAttribute('class');
|
|
150
148
|
});
|
|
151
149
|
|
|
152
150
|
let textElements = [];
|
|
153
|
-
textElements.push(
|
|
151
|
+
textElements.push(domUtils.serializeChildren(bq).trim());
|
|
154
152
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const nextText =
|
|
153
|
+
const nextElem = bq.nextElementSibling;
|
|
154
|
+
if (nextElem && nextElem.matches('.graf-after--pullquote')) {
|
|
155
|
+
const nextText = domUtils.serializeChildren(nextElem);
|
|
158
156
|
if (nextText && nextText.length > 0) {
|
|
159
157
|
textElements.push(nextText.trim());
|
|
160
|
-
|
|
158
|
+
nextElem.remove();
|
|
161
159
|
}
|
|
162
160
|
}
|
|
163
161
|
|
|
164
|
-
|
|
162
|
+
domUtils.replaceWith(bq, `<blockquote><p>${textElements.join('<br><br>')}</p></blockquote>`);
|
|
165
163
|
});
|
|
166
164
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const lang =
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
165
|
+
parsed.$('pre.graf--pre').forEach((pre) => {
|
|
166
|
+
pre.removeAttribute('name');
|
|
167
|
+
pre.removeAttribute('id');
|
|
168
|
+
pre.removeAttribute('class');
|
|
169
|
+
pre.removeAttribute('data-code-block-mode');
|
|
170
|
+
pre.removeAttribute('spellcheck');
|
|
171
|
+
pre.innerHTML = domUtils.serializeChildren(pre).trim();
|
|
172
|
+
|
|
173
|
+
const lang = pre.getAttribute('data-code-block-lang');
|
|
174
|
+
pre.removeAttribute('data-code-block-lang');
|
|
175
|
+
|
|
176
|
+
pre.querySelectorAll('span.pre--content').forEach((span) => {
|
|
177
|
+
const code = parsed.document.createElement('code');
|
|
178
|
+
code.innerHTML = span.innerHTML;
|
|
179
|
+
span.parentNode.replaceChild(code, span);
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
pre.querySelectorAll('code').forEach((code) => {
|
|
183
|
+
code.removeAttribute('name');
|
|
184
|
+
code.removeAttribute('id');
|
|
185
|
+
code.removeAttribute('class');
|
|
186
186
|
|
|
187
187
|
if (lang && lang.length > 0) {
|
|
188
|
-
|
|
188
|
+
code.classList.add(`language-${lang}`);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
code.innerHTML = domUtils.serializeChildren(code).replace(/<br>/g, ' \n').trim();
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
post.data.html =
|
|
195
|
+
post.data.html = parsed.html().trim();
|
|
196
196
|
|
|
197
197
|
return post;
|
|
198
198
|
};
|
package/lib/process-post.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {domUtils} from '@tryghost/mg-utils';
|
|
2
2
|
import string from '@tryghost/string';
|
|
3
3
|
import processContent from './process-content.js';
|
|
4
4
|
|
|
5
5
|
const sectionTags = ['aside', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'img'];
|
|
6
6
|
|
|
7
|
-
const processMeta = ({name,
|
|
7
|
+
const processMeta = ({name, parsed, options}) => {
|
|
8
8
|
const mediumAsCanonical = options?.mediumAsCanonical ?? false;
|
|
9
9
|
|
|
10
10
|
let urlInfo;
|
|
@@ -12,16 +12,17 @@ const processMeta = ({name, $post, options}) => {
|
|
|
12
12
|
const dateNow = new Date();
|
|
13
13
|
|
|
14
14
|
const post = {
|
|
15
|
-
url:
|
|
15
|
+
url: parsed.$('.p-canonical')[0]?.getAttribute('href'),
|
|
16
16
|
data: {
|
|
17
|
-
title:
|
|
18
|
-
custom_excerpt:
|
|
17
|
+
title: parsed.$('.p-name')[0]?.textContent || '',
|
|
18
|
+
custom_excerpt: (parsed.$('.p-summary')[0]?.textContent || '').trim()
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
if (/^(?:posts\/)?draft/.test(name)) {
|
|
23
23
|
urlInfo = name.match(/_(.*?)-([0-9a-f]+)\.html/);
|
|
24
|
-
|
|
24
|
+
const footerLink = parsed.$('footer p a')[0];
|
|
25
|
+
post.url = footerLink?.getAttribute('href');
|
|
25
26
|
post.data.status = 'draft';
|
|
26
27
|
post.data.created_at = dateNow;
|
|
27
28
|
post.data.updated_at = dateNow;
|
|
@@ -35,23 +36,17 @@ const processMeta = ({name, $post, options}) => {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
post.data.status = 'published';
|
|
38
|
-
|
|
39
|
-
post.data.
|
|
40
|
-
post.data.
|
|
39
|
+
const publishedDatetime = parsed.$('.dt-published')[0]?.getAttribute('datetime');
|
|
40
|
+
post.data.created_at = publishedDatetime || dateNow;
|
|
41
|
+
post.data.published_at = publishedDatetime || dateNow;
|
|
42
|
+
post.data.updated_at = publishedDatetime || dateNow;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
if (mediumAsCanonical) {
|
|
44
|
-
const canonicalUrl =
|
|
46
|
+
const canonicalUrl = parsed.$('.p-canonical')[0]?.getAttribute('href');
|
|
45
47
|
post.data.canonical_url = canonicalUrl;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
// $('img').map(async (i, el) => {
|
|
49
|
-
// let $image = $(el);
|
|
50
|
-
// let type = $image.attr('src') === undefined ? 'data-src' : 'src';
|
|
51
|
-
// let newSrc = await this.downloadImage($image.attr(type));
|
|
52
|
-
// $image.attr(type, newSrc);
|
|
53
|
-
// }).get();
|
|
54
|
-
|
|
55
50
|
// Ensure the slug is clean and valid according to Ghost
|
|
56
51
|
post.data.slug = string.slugify(urlInfo[1]);
|
|
57
52
|
// Store the medium ID in the comment ID legacy field - not sure if this is useful
|
|
@@ -60,12 +55,13 @@ const processMeta = ({name, $post, options}) => {
|
|
|
60
55
|
return post;
|
|
61
56
|
};
|
|
62
57
|
|
|
63
|
-
const processAuthor = ({
|
|
58
|
+
const processAuthor = ({pAuthor}) => {
|
|
59
|
+
const href = pAuthor.getAttribute('href');
|
|
64
60
|
return {
|
|
65
|
-
url:
|
|
61
|
+
url: href,
|
|
66
62
|
data: {
|
|
67
|
-
name:
|
|
68
|
-
slug:
|
|
63
|
+
name: pAuthor.textContent,
|
|
64
|
+
slug: href.replace(/.*?@(.*?)$/, (m, p) => p.toLowerCase()),
|
|
69
65
|
roles: [
|
|
70
66
|
'Contributor'
|
|
71
67
|
]
|
|
@@ -73,123 +69,116 @@ const processAuthor = ({$author}) => {
|
|
|
73
69
|
};
|
|
74
70
|
};
|
|
75
71
|
|
|
76
|
-
const processTags = ({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
url: $tag.attr('href'),
|
|
72
|
+
const processTags = ({tagLinks}) => {
|
|
73
|
+
return tagLinks.map((tag) => {
|
|
74
|
+
const href = tag.getAttribute('href');
|
|
75
|
+
return {
|
|
76
|
+
url: href,
|
|
82
77
|
data: {
|
|
83
|
-
name:
|
|
84
|
-
slug:
|
|
78
|
+
name: tag.textContent,
|
|
79
|
+
slug: href.replace(/.*\/(.*?)$/, (m, p) => p.toLowerCase())
|
|
85
80
|
}
|
|
86
|
-
}
|
|
81
|
+
};
|
|
87
82
|
});
|
|
88
|
-
return tags;
|
|
89
83
|
};
|
|
90
84
|
|
|
91
85
|
const processFeatureImage = ({html, post, options}) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
+
}
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
if (!foundImg && el.tagName.toLowerCase() === 'img') {
|
|
101
|
+
foundImg = el;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
if (!
|
|
109
|
-
|
|
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
|
+
}
|
|
110
117
|
}
|
|
111
118
|
|
|
112
|
-
if (
|
|
113
|
-
|
|
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
|
+
}
|
|
114
129
|
}
|
|
130
|
+
|
|
131
|
+
return parsed.html().trim();
|
|
115
132
|
});
|
|
133
|
+
};
|
|
116
134
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
}
|
|
120
146
|
|
|
121
|
-
|
|
122
|
-
|
|
147
|
+
post.data.tags = [];
|
|
148
|
+
|
|
149
|
+
if (options?.addTag) {
|
|
123
150
|
post.data.tags.push({
|
|
151
|
+
url: 'migrator-added-tag',
|
|
124
152
|
data: {
|
|
125
|
-
name:
|
|
153
|
+
name: options.addTag
|
|
126
154
|
}
|
|
127
155
|
});
|
|
128
156
|
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (featured) {
|
|
132
|
-
post.data.feature_image = $html(featured).attr('src');
|
|
133
|
-
post.data.feature_image_alt = $html(featured).attr('alt') || null;
|
|
134
|
-
post.data.feature_image_caption = $html(featured).parents('figure').find('figcaption').html() || null;
|
|
135
157
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export default ({name, html, globalUser, options}) => {
|
|
143
|
-
const $post = cheerio.load(html, {
|
|
144
|
-
xml: {
|
|
145
|
-
xmlMode: false,
|
|
146
|
-
decodeEntities: false,
|
|
147
|
-
scriptingEnabled: false
|
|
158
|
+
// Process tags
|
|
159
|
+
const tagLinks = parsed.$('.p-tags a');
|
|
160
|
+
if (tagLinks.length) {
|
|
161
|
+
post.data.tags = [...post.data.tags, ...processTags({tagLinks})];
|
|
148
162
|
}
|
|
149
|
-
}, false); // This `false` is `isDocument`. If `true`, <html>, <head>, and <body> elements are introduced
|
|
150
163
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
post.data.tags = [];
|
|
162
|
-
|
|
163
|
-
if (options?.addTag) {
|
|
164
|
-
post.data.tags.push({
|
|
165
|
-
url: 'migrator-added-tag',
|
|
166
|
-
data: {
|
|
167
|
-
name: options.addTag
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Process tags
|
|
173
|
-
if ($post('.p-tags a').length) {
|
|
174
|
-
post.data.tags = [...post.data.tags, ...processTags({$tags: $post('.p-tags a')})];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (options?.addPlatformTag) {
|
|
178
|
-
post.data.tags.push({
|
|
179
|
-
url: 'migrator-added-platform-tag',
|
|
180
|
-
data: {
|
|
181
|
-
name: '#medium'
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
164
|
+
if (options?.addPlatformTag) {
|
|
165
|
+
post.data.tags.push({
|
|
166
|
+
url: 'migrator-added-platform-tag',
|
|
167
|
+
data: {
|
|
168
|
+
name: '#medium'
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
185
172
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
173
|
+
// Process content
|
|
174
|
+
const eContent = parsed.$('.e-content')[0];
|
|
175
|
+
const contentHtml = eContent ? domUtils.serializeChildren(eContent) : '';
|
|
176
|
+
post = processContent({html: contentHtml, post});
|
|
189
177
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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});
|
|
193
181
|
|
|
194
|
-
|
|
182
|
+
return post;
|
|
183
|
+
});
|
|
195
184
|
};
|
package/lib/process-profile.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
parsed.$('ul li').forEach((el) => {
|
|
39
|
+
let [item, value] = el.textContent.split(': ');
|
|
40
|
+
let key = mediumToGhost[item.toLowerCase()] || null;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (key) {
|
|
43
|
+
profile.data[key] = value;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
45
46
|
|
|
46
|
-
|
|
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 =
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-medium-export",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "tbc",
|
|
5
5
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-medium-export",
|
|
6
6
|
"author": "Ghost Foundation",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"dev": "echo \"Implement me!\"",
|
|
12
|
-
"test": "node --test 'test/**/*.test.js'",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
12
|
+
"test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --statements 100 node --test 'test/**/*.test.js'",
|
|
13
|
+
"posttest": "yarn lint",
|
|
14
|
+
"lint": "eslint . --ext .js --cache"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"index.js",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"c8": "11.0.0",
|
|
24
25
|
"eslint": "8.57.1"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@tryghost/debug": "2.0.
|
|
28
|
-
"@tryghost/kg-default-cards": "10.2.
|
|
29
|
-
"@tryghost/mg-fs-utils": "0.
|
|
28
|
+
"@tryghost/debug": "2.0.3",
|
|
29
|
+
"@tryghost/kg-default-cards": "10.2.10",
|
|
30
|
+
"@tryghost/mg-fs-utils": "0.17.0",
|
|
31
|
+
"@tryghost/mg-utils": "0.2.0",
|
|
30
32
|
"@tryghost/string": "0.3.1",
|
|
31
|
-
"cheerio": "1.2.0",
|
|
32
33
|
"simple-dom": "1.4.0"
|
|
33
|
-
}
|
|
34
|
-
"gitHead": "e1680568191322d738c188f03298910aa3622735"
|
|
34
|
+
}
|
|
35
35
|
}
|