@tryghost/mg-medium-export 0.27.7 → 0.28.0-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 +83 -10
- package/build/index.d.ts +7 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/lib/ingest.d.ts +22 -0
- package/build/lib/ingest.js +66 -0
- package/build/lib/ingest.js.map +1 -0
- package/build/lib/map.d.ts +23 -0
- package/build/lib/map.js +245 -0
- package/build/lib/map.js.map +1 -0
- package/build/lib/process-content.d.ts +21 -0
- package/{lib → build/lib}/process-content.js +14 -47
- package/build/lib/process-content.js.map +1 -0
- package/build/lib/process-post.d.ts +17 -0
- package/build/lib/process-post.js +176 -0
- package/build/lib/process-post.js.map +1 -0
- package/build/lib/process-profile.d.ts +6 -0
- package/{lib → build/lib}/process-profile.js +10 -14
- package/build/lib/process-profile.js.map +1 -0
- package/build/lib/types.d.ts +58 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/test/helpers.d.ts +39 -0
- package/build/test/helpers.js +78 -0
- package/build/test/helpers.js.map +1 -0
- package/build/test/ingest.test.d.ts +1 -0
- package/build/test/ingest.test.js +115 -0
- package/build/test/ingest.test.js.map +1 -0
- package/build/test/map.test.d.ts +1 -0
- package/build/test/map.test.js +286 -0
- package/build/test/map.test.js.map +1 -0
- package/build/test/process-profile.test.d.ts +1 -0
- package/build/test/process-profile.test.js +70 -0
- package/build/test/process-profile.test.js.map +1 -0
- package/build/test/process.test.d.ts +1 -0
- package/build/test/process.test.js +505 -0
- package/build/test/process.test.js.map +1 -0
- package/package.json +22 -12
- package/index.js +0 -11
- package/lib/process-post.js +0 -182
- package/lib/process.js +0 -24
- package/lib/read-zip.js +0 -83
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {domUtils, cardUtils} from '@tryghost/mg-utils';
|
|
1
|
+
import { domUtils, cardUtils } from '@tryghost/mg-utils';
|
|
2
2
|
import SimpleDom from 'simple-dom';
|
|
3
3
|
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
|
|
4
|
+
const serialize = (node) => serializer.serialize(node);
|
|
4
5
|
const galleryCard = cardUtils.getCard('gallery');
|
|
5
6
|
const bookmarkCard = cardUtils.getCard('bookmark');
|
|
6
|
-
|
|
7
|
-
const doReplace = str => {
|
|
7
|
+
const doReplace = (str) => {
|
|
8
8
|
const replaceParts = [
|
|
9
9
|
[/[\s\n]/g, ''], // Remove spaces
|
|
10
10
|
[/\.$/, ''], // Trim trailing full stop
|
|
@@ -13,28 +13,23 @@ const doReplace = str => {
|
|
|
13
13
|
[/\u201c/, '"'], // Convert double opening curly quote to straight quote
|
|
14
14
|
[/\u201d/, '"'] // Convert double closing curly quote to straight quote
|
|
15
15
|
];
|
|
16
|
-
|
|
17
16
|
replaceParts.forEach(re => {
|
|
18
17
|
str = str.replace(re[0], re[1]);
|
|
19
18
|
});
|
|
20
|
-
|
|
21
19
|
return str;
|
|
22
20
|
};
|
|
23
|
-
|
|
24
21
|
const equivalentTitles = (title1, title2) => {
|
|
25
22
|
title1 = doReplace(title1);
|
|
26
23
|
title2 = doReplace(title2);
|
|
27
|
-
|
|
28
24
|
return title1 === title2;
|
|
29
25
|
};
|
|
30
|
-
|
|
31
26
|
// Trim leading and trailing whitespace from an element's edge text nodes using
|
|
32
27
|
// DOM operations. This reproduces the output of the previous
|
|
33
28
|
// `serializeChildren(el).trim()` round-trip without reinterpreting serialized
|
|
34
29
|
// DOM text as HTML via innerHTML. U+00A0 (non-breaking space) is excluded so the
|
|
35
30
|
// result matches the old String.trim(): serializeChildren escaped a nbsp to
|
|
36
31
|
// ` `, which trim() never stripped.
|
|
37
|
-
const trimEdgeWhitespace = el => {
|
|
32
|
+
const trimEdgeWhitespace = (el) => {
|
|
38
33
|
let node = el.firstChild;
|
|
39
34
|
while (node && node.nodeType === 3) {
|
|
40
35
|
const trimmed = node.nodeValue.replace(/^[^\S\u00a0]+/, '');
|
|
@@ -44,7 +39,6 @@ const trimEdgeWhitespace = el => {
|
|
|
44
39
|
}
|
|
45
40
|
node = node.nextSibling;
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
node = el.lastChild;
|
|
49
43
|
while (node && node.nodeType === 3) {
|
|
50
44
|
const trimmed = node.nodeValue.replace(/[^\S\u00a0]+$/, '');
|
|
@@ -55,16 +49,17 @@ const trimEdgeWhitespace = el => {
|
|
|
55
49
|
node = node.previousSibling;
|
|
56
50
|
}
|
|
57
51
|
};
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Convert a Medium post's body HTML to Ghost-friendly HTML, setting `post.data.html`. A short published post with
|
|
54
|
+
* one paragraph and no images is probably a comment, so it becomes a draft tagged `#Medium Possible Comment`.
|
|
55
|
+
*/
|
|
56
|
+
export default ({ html, post }) => {
|
|
60
57
|
const parsed = domUtils.parseFragment(html);
|
|
61
|
-
|
|
62
58
|
// Detect if post is likely to be a comment. If so, set as draft and add tag
|
|
63
59
|
// Based on being published, content having 1 paragraph, and having no images
|
|
64
60
|
let childrenCount = parsed.body.children.length;
|
|
65
61
|
let pCount = parsed.$('p').length;
|
|
66
62
|
let imgCount = parsed.$('img').length;
|
|
67
|
-
|
|
68
63
|
if (post.data.status === 'published' && childrenCount <= 1 && pCount <= 1 && imgCount === 0) {
|
|
69
64
|
post.data.status = 'draft';
|
|
70
65
|
post.data.tags.push({
|
|
@@ -75,7 +70,6 @@ export default ({html, post}) => {
|
|
|
75
70
|
}
|
|
76
71
|
});
|
|
77
72
|
}
|
|
78
|
-
|
|
79
73
|
// Medium usually has an hr divider at the very beginning of the content
|
|
80
74
|
// We don't need this so remove it if we find it
|
|
81
75
|
let firstSection = parsed.$('.section--first')[0];
|
|
@@ -85,42 +79,35 @@ export default ({html, post}) => {
|
|
|
85
79
|
firstChild.remove();
|
|
86
80
|
}
|
|
87
81
|
}
|
|
88
|
-
|
|
89
82
|
// Sometimes Medium has a duplicate header at the beginning of the content
|
|
90
83
|
// Don't need this either so remove it
|
|
91
84
|
let firstTitle = parsed.$('h1, h2, h3, h4, blockquote')[0];
|
|
92
85
|
if (firstTitle && equivalentTitles(firstTitle.textContent, post.data.title)) {
|
|
93
86
|
firstTitle.remove();
|
|
94
87
|
}
|
|
95
|
-
|
|
96
88
|
// Remove the subtitle if it's the same as the excerpt
|
|
97
89
|
parsed.$('.graf--subtitle').forEach(el => {
|
|
98
90
|
if (equivalentTitles(el.textContent, post.data.custom_excerpt)) {
|
|
99
91
|
el.remove();
|
|
100
92
|
}
|
|
101
93
|
});
|
|
102
|
-
|
|
103
94
|
// Convert galleries
|
|
104
95
|
parsed.$('.section-inner.sectionLayout--outsetRow').forEach(el => {
|
|
105
96
|
// Check we're only working with a group of <figure> elements
|
|
106
97
|
const children = Array.from(el.children);
|
|
107
98
|
const allFigures = children.every(child => child.tagName.toLowerCase() === 'figure');
|
|
108
|
-
|
|
109
99
|
// If it's all figures
|
|
110
100
|
if (allFigures) {
|
|
111
101
|
let figcaption = el.querySelector('figcaption');
|
|
112
102
|
let caption = figcaption ? domUtils.serializeChildren(figcaption).trim() : null;
|
|
113
|
-
|
|
114
103
|
let cardOpts = {
|
|
115
|
-
env: {dom: new SimpleDom.Document()},
|
|
104
|
+
env: { dom: new SimpleDom.Document() },
|
|
116
105
|
payload: {
|
|
117
106
|
images: [],
|
|
118
107
|
caption: caption
|
|
119
108
|
}
|
|
120
109
|
};
|
|
121
|
-
|
|
122
110
|
el.querySelectorAll('figure').forEach(figure => {
|
|
123
|
-
// eslint-disable-line no-shadow
|
|
124
111
|
let img = figure.querySelector('img');
|
|
125
112
|
cardOpts.payload.images.push({
|
|
126
113
|
row: 0,
|
|
@@ -130,55 +117,43 @@ export default ({html, post}) => {
|
|
|
130
117
|
height: img.getAttribute('data-height')
|
|
131
118
|
});
|
|
132
119
|
});
|
|
133
|
-
|
|
134
|
-
const galleryHtml = serializer.serialize(galleryCard.render(cardOpts));
|
|
135
|
-
|
|
120
|
+
const galleryHtml = serialize(galleryCard.render(cardOpts));
|
|
136
121
|
domUtils.replaceWith(el, galleryHtml);
|
|
137
122
|
}
|
|
138
123
|
});
|
|
139
|
-
|
|
140
124
|
// Convert Medium bookmarks
|
|
141
125
|
parsed.$('.graf--mixtapeEmbed').forEach(el => {
|
|
142
126
|
let cardOpts = {
|
|
143
|
-
env: {dom: new SimpleDom.Document()},
|
|
127
|
+
env: { dom: new SimpleDom.Document() },
|
|
144
128
|
payload: {}
|
|
145
129
|
};
|
|
146
|
-
|
|
147
130
|
let href = el.querySelector('.markup--anchor')?.getAttribute('href');
|
|
148
131
|
cardOpts.payload.url = href;
|
|
149
|
-
|
|
150
132
|
cardOpts.payload.metadata = {
|
|
151
133
|
url: href,
|
|
152
134
|
title: el.querySelector('.markup--strong')?.textContent || '',
|
|
153
135
|
description: el.querySelector('.markup--em')?.textContent || ''
|
|
154
136
|
};
|
|
155
|
-
|
|
156
137
|
const mixtapeImage = el.querySelector('.js-mixtapeImage');
|
|
157
138
|
const bngImage = mixtapeImage ? mixtapeImage.style.backgroundImage : null;
|
|
158
139
|
if (bngImage) {
|
|
159
140
|
let src = bngImage.replace(/url\(["']?(.*?)["']?\)/, (m, p) => p);
|
|
160
141
|
cardOpts.payload.metadata.thumbnail = src;
|
|
161
142
|
}
|
|
162
|
-
|
|
163
|
-
const bookmarkHtml = serializer.serialize(bookmarkCard.render(cardOpts));
|
|
164
|
-
|
|
143
|
+
const bookmarkHtml = serialize(bookmarkCard.render(cardOpts));
|
|
165
144
|
domUtils.replaceWith(el, `<!--kg-card-begin: html-->\n${bookmarkHtml}\n<!--kg-card-end: html-->`);
|
|
166
145
|
});
|
|
167
|
-
|
|
168
146
|
// Handle blockquotes made of 2 elements
|
|
169
147
|
parsed.$('blockquote.graf--pullquote, blockquote.graf--blockquote').forEach(bq => {
|
|
170
148
|
bq.removeAttribute('name');
|
|
171
149
|
bq.removeAttribute('id');
|
|
172
150
|
bq.removeAttribute('class');
|
|
173
|
-
|
|
174
151
|
bq.querySelectorAll('a').forEach(a => {
|
|
175
152
|
a.removeAttribute('data-href');
|
|
176
153
|
a.removeAttribute('class');
|
|
177
154
|
});
|
|
178
|
-
|
|
179
155
|
let textElements = [];
|
|
180
156
|
textElements.push(domUtils.serializeChildren(bq).trim());
|
|
181
|
-
|
|
182
157
|
const nextElem = bq.nextElementSibling;
|
|
183
158
|
if (nextElem && nextElem.matches('.graf-after--pullquote')) {
|
|
184
159
|
const nextText = domUtils.serializeChildren(nextElem);
|
|
@@ -187,10 +162,8 @@ export default ({html, post}) => {
|
|
|
187
162
|
nextElem.remove();
|
|
188
163
|
}
|
|
189
164
|
}
|
|
190
|
-
|
|
191
165
|
domUtils.replaceWith(bq, `<blockquote><p>${textElements.join('<br><br>')}</p></blockquote>`);
|
|
192
166
|
});
|
|
193
|
-
|
|
194
167
|
parsed.$('pre.graf--pre').forEach(pre => {
|
|
195
168
|
pre.removeAttribute('name');
|
|
196
169
|
pre.removeAttribute('id');
|
|
@@ -198,31 +171,25 @@ export default ({html, post}) => {
|
|
|
198
171
|
pre.removeAttribute('data-code-block-mode');
|
|
199
172
|
pre.removeAttribute('spellcheck');
|
|
200
173
|
trimEdgeWhitespace(pre);
|
|
201
|
-
|
|
202
174
|
const lang = pre.getAttribute('data-code-block-lang');
|
|
203
175
|
pre.removeAttribute('data-code-block-lang');
|
|
204
|
-
|
|
205
176
|
pre.querySelectorAll('span.pre--content').forEach(span => {
|
|
206
177
|
const code = parsed.document.createElement('code');
|
|
207
178
|
code.innerHTML = span.innerHTML;
|
|
208
179
|
span.parentNode.replaceChild(code, span);
|
|
209
180
|
});
|
|
210
|
-
|
|
211
181
|
pre.querySelectorAll('code').forEach(code => {
|
|
212
182
|
code.removeAttribute('name');
|
|
213
183
|
code.removeAttribute('id');
|
|
214
184
|
code.removeAttribute('class');
|
|
215
|
-
|
|
216
185
|
if (lang && lang.length > 0) {
|
|
217
186
|
code.classList.add(`language-${lang}`);
|
|
218
187
|
}
|
|
219
|
-
|
|
220
188
|
code.querySelectorAll('br').forEach(br => br.replaceWith(' \n'));
|
|
221
189
|
trimEdgeWhitespace(code);
|
|
222
190
|
});
|
|
223
191
|
});
|
|
224
|
-
|
|
225
192
|
post.data.html = parsed.html().trim();
|
|
226
|
-
|
|
227
193
|
return post;
|
|
228
194
|
};
|
|
195
|
+
//# sourceMappingURL=process-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-content.js","sourceRoot":"","sources":["../../src/lib/process-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACnE,MAAM,SAAS,GAAG,CAAC,IAAa,EAAU,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAW,CAAC,CAAC;AAC/E,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACjD,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAcnD,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EAAE;IACtC,MAAM,YAAY,GAAuB;QACrC,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,gBAAgB;QACjC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,0BAA0B;QACvC,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,uDAAuD;QACxE,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,uDAAuD;QACxE,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,uDAAuD;QACxE,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,uDAAuD;KAC1E,CAAC;IAEF,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACtB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC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SAAS,CAAC;YAChC,IAAI,CAAC,UAAW,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACxC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC3B,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YAE9B,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;YAC3C,CAAC;YAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YACjE,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAEtC,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MediumOptions, MediumPost } from './types.js';
|
|
2
|
+
/** The Medium username in a profile URL, such as `joebloggs` for `https://medium.com/@JoeBloggs`, in lower case. */
|
|
3
|
+
export declare function mediumHandle(url: string | undefined): string | undefined;
|
|
4
|
+
/** A published post's canonical Medium URL, from its export HTML. */
|
|
5
|
+
export declare function postUrl(html: string): string | undefined;
|
|
6
|
+
export default _default;
|
|
7
|
+
/**
|
|
8
|
+
* Convert one `posts/*.html` file of a Medium export. `name` is its path in the export, which marks drafts and
|
|
9
|
+
* holds the post ID when the canonical URL does not. Posts without a publish date, and drafts, are dated `date`.
|
|
10
|
+
* Throws a `RecordDataError` when no post ID can be found or the publish date is invalid.
|
|
11
|
+
*/
|
|
12
|
+
declare function _default({ name, html, options, date }: {
|
|
13
|
+
name: string;
|
|
14
|
+
html: string;
|
|
15
|
+
options?: MediumOptions;
|
|
16
|
+
date: Date;
|
|
17
|
+
}): MediumPost;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { RecordDataError } from '@tryghost/mg-context';
|
|
2
|
+
import { domUtils } from '@tryghost/mg-utils';
|
|
3
|
+
import { slugify } from '@tryghost/string';
|
|
4
|
+
import processContent from './process-content.js';
|
|
5
|
+
const sectionTags = ['aside', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'img'];
|
|
6
|
+
/** The Medium username in a profile URL, such as `joebloggs` for `https://medium.com/@JoeBloggs`, in lower case. */
|
|
7
|
+
export function mediumHandle(url) {
|
|
8
|
+
return url?.match(/\/@([^/?#]+)/)?.[1].toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
/** A published post's canonical Medium URL, from its export HTML. */
|
|
11
|
+
export function postUrl(html) {
|
|
12
|
+
return domUtils.processFragment(html, parsed => canonicalUrl(parsed));
|
|
13
|
+
}
|
|
14
|
+
function canonicalUrl(parsed) {
|
|
15
|
+
return parsed.$('.p-canonical')[0]?.getAttribute('href') ?? undefined;
|
|
16
|
+
}
|
|
17
|
+
function publishedDate(parsed) {
|
|
18
|
+
const value = parsed.$('.dt-published')[0]?.getAttribute('datetime');
|
|
19
|
+
if (!value) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const date = new Date(value);
|
|
23
|
+
if (!Number.isFinite(date.getTime())) {
|
|
24
|
+
throw new RecordDataError('Invalid Medium publish date');
|
|
25
|
+
}
|
|
26
|
+
return date;
|
|
27
|
+
}
|
|
28
|
+
const processMeta = ({ name, parsed, options, date }) => {
|
|
29
|
+
const canonical = canonicalUrl(parsed);
|
|
30
|
+
const draft = /^(?:posts\/)?draft/.test(name);
|
|
31
|
+
let url = canonical;
|
|
32
|
+
let urlInfo;
|
|
33
|
+
if (draft) {
|
|
34
|
+
url = parsed.$('footer p a')[0]?.getAttribute('href') ?? undefined;
|
|
35
|
+
urlInfo = name.match(/_(.*?)-([0-9a-f]+)\.html/);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// The canonical URL can be a profile URL followed by the ID, without a slug, such as
|
|
39
|
+
// https://medium.com/@username/1234567890, so fall back to the file name.
|
|
40
|
+
urlInfo = canonical?.match(/([^/]*?)-([0-9a-f]+)$/) ?? name.match(/_(.*?)-([0-9a-f]+)\.html/);
|
|
41
|
+
}
|
|
42
|
+
if (!urlInfo) {
|
|
43
|
+
throw new RecordDataError('No Medium post ID in the canonical URL or file name');
|
|
44
|
+
}
|
|
45
|
+
const published = draft ? undefined : (publishedDate(parsed) ?? date);
|
|
46
|
+
const post = {
|
|
47
|
+
url,
|
|
48
|
+
data: {
|
|
49
|
+
title: parsed.$('.p-name')[0]?.textContent || '',
|
|
50
|
+
custom_excerpt: (parsed.$('.p-summary')[0]?.textContent || '').trim(),
|
|
51
|
+
status: draft ? 'draft' : 'published',
|
|
52
|
+
created_at: published ?? date,
|
|
53
|
+
updated_at: published ?? date,
|
|
54
|
+
published_at: published,
|
|
55
|
+
// Ensure the slug is clean and valid according to Ghost
|
|
56
|
+
slug: slugify(urlInfo[1]),
|
|
57
|
+
// The Medium post ID
|
|
58
|
+
comment_id: urlInfo[2],
|
|
59
|
+
tags: [],
|
|
60
|
+
html: ''
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
if (options.mediumAsCanonical && canonical) {
|
|
64
|
+
post.data.canonical_url = canonical;
|
|
65
|
+
}
|
|
66
|
+
return post;
|
|
67
|
+
};
|
|
68
|
+
const processAuthor = (pAuthor) => {
|
|
69
|
+
const href = pAuthor.getAttribute('href') ?? undefined;
|
|
70
|
+
return {
|
|
71
|
+
url: href,
|
|
72
|
+
data: {
|
|
73
|
+
name: pAuthor.textContent.trim(),
|
|
74
|
+
slug: mediumHandle(href),
|
|
75
|
+
roles: ['Contributor']
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const processTags = (tagLinks) => {
|
|
80
|
+
return tagLinks.map(tag => {
|
|
81
|
+
const href = tag.getAttribute('href') ?? '';
|
|
82
|
+
return {
|
|
83
|
+
url: href,
|
|
84
|
+
data: {
|
|
85
|
+
name: tag.textContent.trim(),
|
|
86
|
+
slug: href.replace(/.*\/(.*?)$/, (m, p) => p.toLowerCase())
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const processFeatureImage = ({ html, post, options }) => {
|
|
92
|
+
return domUtils.processFragment(html, parsed => {
|
|
93
|
+
// Look for data-is-featured
|
|
94
|
+
let featured = parsed.$('[data-is-featured]')[0] || null;
|
|
95
|
+
// Look for an image that appears before content
|
|
96
|
+
const allSections = parsed.$(sectionTags.join(','));
|
|
97
|
+
let foundImg = null;
|
|
98
|
+
const preImageTags = [];
|
|
99
|
+
allSections.forEach(el => {
|
|
100
|
+
if (!foundImg) {
|
|
101
|
+
preImageTags.push(el.tagName.toLowerCase());
|
|
102
|
+
}
|
|
103
|
+
if (!foundImg && el.tagName.toLowerCase() === 'img') {
|
|
104
|
+
foundImg = el;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
// We don't have a designated feature image, but there's an image above the content so use that image instead
|
|
108
|
+
if (!featured && !preImageTags.includes('p')) {
|
|
109
|
+
featured = foundImg;
|
|
110
|
+
if (options.addPlatformTag) {
|
|
111
|
+
// tag it with #auto-feature-image so we can tell the difference
|
|
112
|
+
post.data.tags.push({
|
|
113
|
+
data: {
|
|
114
|
+
name: '#auto-feature-image'
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
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
|
+
if (figure) {
|
|
126
|
+
figure.remove();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return parsed.html().trim();
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Convert one `posts/*.html` file of a Medium export. `name` is its path in the export, which marks drafts and
|
|
134
|
+
* holds the post ID when the canonical URL does not. Posts without a publish date, and drafts, are dated `date`.
|
|
135
|
+
* Throws a `RecordDataError` when no post ID can be found or the publish date is invalid.
|
|
136
|
+
*/
|
|
137
|
+
export default ({ name, html, options = {}, date }) => {
|
|
138
|
+
return domUtils.processFragment(html, parsed => {
|
|
139
|
+
let post = processMeta({ name, parsed, options, date });
|
|
140
|
+
// Process author
|
|
141
|
+
const pAuthor = parsed.$('.p-author')[0];
|
|
142
|
+
if (pAuthor) {
|
|
143
|
+
post.data.author = processAuthor(pAuthor);
|
|
144
|
+
}
|
|
145
|
+
if (options.addTag) {
|
|
146
|
+
post.data.tags.push({
|
|
147
|
+
url: 'migrator-added-tag',
|
|
148
|
+
data: {
|
|
149
|
+
name: options.addTag
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Process tags
|
|
154
|
+
const tagLinks = parsed.$('.p-tags a');
|
|
155
|
+
if (tagLinks.length) {
|
|
156
|
+
post.data.tags = [...post.data.tags, ...processTags(tagLinks)];
|
|
157
|
+
}
|
|
158
|
+
if (options.addPlatformTag) {
|
|
159
|
+
post.data.tags.push({
|
|
160
|
+
url: 'migrator-added-platform-tag',
|
|
161
|
+
data: {
|
|
162
|
+
name: '#medium'
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
// Process content
|
|
167
|
+
const eContent = parsed.$('.e-content')[0];
|
|
168
|
+
const contentHtml = eContent ? domUtils.serializeChildren(eContent) : '';
|
|
169
|
+
post = processContent({ html: contentHtml, post });
|
|
170
|
+
// Grab the featured image
|
|
171
|
+
// Do this last so that we can add tags to indicate feature image style
|
|
172
|
+
post.data.html = processFeatureImage({ html: post.data.html, post, options });
|
|
173
|
+
return post;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=process-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-post.js","sourceRoot":"","sources":["../../src/lib/process-post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAKlD,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE5F,oHAAoH;AACpH,MAAM,UAAU,YAAY,CAAC,GAAuB;IAChD,OAAO,GAAG,EAAE,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACzD,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,OAAO,CAAC,IAAY;IAChC,OAAO,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,YAAY,CAAC,MAAsB;IACxC,OAAO,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,SAAS,CAA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M,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,IAAI,GAAG,cAAc,CAAC,EAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC,CAAC;QAEjD,0BAA0B;QAC1B,uEAAuE;QACvE,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAC;QAE5E,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {domUtils} from '@tryghost/mg-utils';
|
|
2
|
-
const {processFragment} = domUtils;
|
|
3
|
-
|
|
1
|
+
import { domUtils } from '@tryghost/mg-utils';
|
|
2
|
+
const { processFragment } = domUtils;
|
|
4
3
|
// Keys we've seen so far
|
|
5
4
|
// Profile
|
|
6
5
|
// Display name
|
|
@@ -14,34 +13,31 @@ const {processFragment} = domUtils;
|
|
|
14
13
|
// Google email
|
|
15
14
|
// Google display name
|
|
16
15
|
// Google account ID
|
|
17
|
-
|
|
18
16
|
const mediumToGhost = {
|
|
19
17
|
'email address': 'email',
|
|
20
18
|
'created at': 'created_at',
|
|
21
19
|
image: 'profile_image',
|
|
22
20
|
twitter: 'twitter'
|
|
23
21
|
};
|
|
24
|
-
|
|
25
|
-
export default ({html}) => {
|
|
22
|
+
/** Read the export owner from a Medium export's `profile/profile.html`. */
|
|
23
|
+
export default ({ html }) => {
|
|
26
24
|
return processFragment(html, parsed => {
|
|
27
|
-
|
|
28
|
-
url: parsed.$('.u-url')[0]?.getAttribute('href'),
|
|
25
|
+
const profile = {
|
|
26
|
+
url: parsed.$('.u-url')[0]?.getAttribute('href') ?? undefined,
|
|
29
27
|
data: {
|
|
30
28
|
name: parsed.$('.p-name')[0]?.textContent || '',
|
|
31
|
-
profile_image: parsed.$('.u-photo')[0]?.getAttribute('src'),
|
|
29
|
+
profile_image: parsed.$('.u-photo')[0]?.getAttribute('src') ?? undefined,
|
|
32
30
|
roles: ['Contributor']
|
|
33
31
|
}
|
|
34
32
|
};
|
|
35
|
-
|
|
36
33
|
parsed.$('ul li').forEach(el => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const [item, value] = el.textContent.split(': ');
|
|
35
|
+
const key = mediumToGhost[item.toLowerCase()] || null;
|
|
40
36
|
if (key) {
|
|
41
37
|
profile.data[key] = value;
|
|
42
38
|
}
|
|
43
39
|
});
|
|
44
|
-
|
|
45
40
|
return profile;
|
|
46
41
|
});
|
|
47
42
|
};
|
|
43
|
+
//# sourceMappingURL=process-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-profile.js","sourceRoot":"","sources":["../../src/lib/process-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAG5C,MAAM,EAAC,eAAe,EAAC,GAAG,QAAQ,CAAC;AAEnC,yBAAyB;AACzB,UAAU;AACV,eAAe;AACf,gBAAgB;AAChB,iBAAiB;AACjB,aAAa;AACb,UAAU;AACV,qBAAqB;AACrB,wBAAwB;AACxB,sBAAsB;AACtB,eAAe;AACf,sBAAsB;AACtB,oBAAoB;AAEpB,MAAM,aAAa,GAA2B;IAC1C,eAAe,EAAE,OAAO;IACxB,YAAY,EAAE,YAAY;IAC1B,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,SAAS;CACrB,CAAC;AAEF,2EAA2E;AAC3E,eAAe,CAAC,EAAC,IAAI,EAAiB,EAAkB,EAAE;IACtD,OAAO,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;QAClC,MAAM,OAAO,GAAmB;YAC5B,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,SAAS;YAC7D,IAAI,EAAE;gBACF,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,IAAI,EAAE;gBAC/C,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,IAAI,SAAS;gBACxE,KAAK,EAAE,CAAC,aAAa,CAAC;aACzB;SACJ,CAAC;QAEF,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YAC3B,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,WAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAClD,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC;YAEtD,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export interface MediumOptions {
|
|
2
|
+
/** Add a tag with this name to every post. */
|
|
3
|
+
addTag?: string | null;
|
|
4
|
+
/** Add the `#medium` tag, and `#auto-feature-image` when an image before the content becomes the feature image. */
|
|
5
|
+
addPlatformTag?: boolean;
|
|
6
|
+
/** Use the Medium post URL as the canonical URL. */
|
|
7
|
+
mediumAsCanonical?: boolean;
|
|
8
|
+
/** The domain of generated author email addresses, such as `example.com`. */
|
|
9
|
+
email?: string | false | null;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
/** A tag or author as the content processors return it, with its Medium URL where it has one. */
|
|
13
|
+
export interface MediumRelation {
|
|
14
|
+
url?: string;
|
|
15
|
+
data: {
|
|
16
|
+
name: string;
|
|
17
|
+
slug?: string;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** A post as `processPost()` returns it. */
|
|
22
|
+
export interface MediumPost {
|
|
23
|
+
/** The post's Medium URL: its canonical link, or a draft's link. */
|
|
24
|
+
url?: string;
|
|
25
|
+
data: {
|
|
26
|
+
title: string;
|
|
27
|
+
slug: string;
|
|
28
|
+
custom_excerpt: string;
|
|
29
|
+
status: 'published' | 'draft';
|
|
30
|
+
created_at: Date;
|
|
31
|
+
updated_at: Date;
|
|
32
|
+
published_at?: Date;
|
|
33
|
+
canonical_url?: string;
|
|
34
|
+
/** The Medium post ID, such as `6d912ac65341`. */
|
|
35
|
+
comment_id: string;
|
|
36
|
+
author?: MediumRelation;
|
|
37
|
+
tags: MediumRelation[];
|
|
38
|
+
html: string;
|
|
39
|
+
feature_image?: string | null;
|
|
40
|
+
feature_image_alt?: string | null;
|
|
41
|
+
feature_image_caption?: string | null;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** A tag found by scraping a post page. */
|
|
45
|
+
export interface ScrapedTag {
|
|
46
|
+
url?: string;
|
|
47
|
+
name: string;
|
|
48
|
+
slug?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Web-scraped values for one post, after the runner's post processor. */
|
|
51
|
+
export interface ScrapedData {
|
|
52
|
+
tags?: ScrapedTag[];
|
|
53
|
+
author?: {
|
|
54
|
+
url?: string;
|
|
55
|
+
profile_image?: string;
|
|
56
|
+
};
|
|
57
|
+
[field: string]: any;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":";AAwDA,oBAAoB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { MigrateContext } from '@tryghost/mg-context';
|
|
2
|
+
/** A fixture file's contents, by its path under `fixtures/export`. */
|
|
3
|
+
export declare function fixture(path: string): Promise<string>;
|
|
4
|
+
/** A new temporary directory, removed by `cleanUp()`. */
|
|
5
|
+
export declare function tempDirectory(): Promise<string>;
|
|
6
|
+
/** Write `files` (path in the zip → contents) into a zip named `name` in `directory`, and return its path. */
|
|
7
|
+
export declare function makeZip(files: Record<string, string>, { directory, name }?: {
|
|
8
|
+
directory?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
}): Promise<string>;
|
|
11
|
+
export declare function cleanUp(): Promise<void>;
|
|
12
|
+
export declare function memoryContext(): Promise<MigrateContext>;
|
|
13
|
+
/** A context holding the ingested export at `path`, or a zip of `files`. */
|
|
14
|
+
export declare function ingested(input: string | Record<string, string>): Promise<MigrateContext>;
|
|
15
|
+
export declare function events(context: MigrateContext, type: string): {
|
|
16
|
+
details: Record<string, any>;
|
|
17
|
+
}[];
|
|
18
|
+
export interface PostPage {
|
|
19
|
+
title?: string;
|
|
20
|
+
subtitle?: string;
|
|
21
|
+
body?: string;
|
|
22
|
+
/** The author link, or `null` for none. */
|
|
23
|
+
author?: {
|
|
24
|
+
name: string;
|
|
25
|
+
url: string;
|
|
26
|
+
} | null;
|
|
27
|
+
date?: string;
|
|
28
|
+
canonical?: string;
|
|
29
|
+
tags?: string[];
|
|
30
|
+
}
|
|
31
|
+
/** A Medium export post page; published unless its file name starts with `draft_`. */
|
|
32
|
+
export declare function postPage({ title, subtitle, body, author, date, canonical, tags }?: PostPage): string;
|
|
33
|
+
/** A Medium export profile page. */
|
|
34
|
+
export declare function profilePage({ name, handle, email, photo }?: {
|
|
35
|
+
name?: string;
|
|
36
|
+
handle?: string | null;
|
|
37
|
+
email?: string | null;
|
|
38
|
+
photo?: string;
|
|
39
|
+
}): string;
|