@tryghost/mg-medium-export 0.14.12 → 0.15.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 +3 -0
- package/index.js +1 -1
- package/lib/process-content.js +1 -1
- package/lib/process-post.js +17 -10
- package/lib/process-profile.js +1 -1
- package/lib/process.js +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,6 +51,9 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
51
51
|
- **`-e` `--email`**
|
|
52
52
|
- string - default: `false`
|
|
53
53
|
- Provide an email domain for users e.g. example.com
|
|
54
|
+
- **`--mediumAsCanonical`**
|
|
55
|
+
- bool - default: `false`
|
|
56
|
+
- Use medium article as canonical URL
|
|
54
57
|
- **`--fallBackHTMLCard`**
|
|
55
58
|
- bool - default: `true`
|
|
56
59
|
- Fall back to convert to HTMLCard, if standard Mobiledoc convert fails
|
package/index.js
CHANGED
package/lib/process-content.js
CHANGED
|
@@ -7,7 +7,7 @@ const equivalentTitles = (title1, title2) => {
|
|
|
7
7
|
return title1 === title2;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export default (content, post) => {
|
|
10
|
+
export default ({content, post}) => {
|
|
11
11
|
let $content = $(content);
|
|
12
12
|
|
|
13
13
|
// Medium usually has an hr divider at the very beginning of the content
|
package/lib/process-post.js
CHANGED
|
@@ -5,7 +5,9 @@ import processContent from './process-content.js';
|
|
|
5
5
|
|
|
6
6
|
const sectionTags = ['aside', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'img'];
|
|
7
7
|
|
|
8
|
-
const processMeta = (name, $post) => {
|
|
8
|
+
const processMeta = ({name, $post, options}) => {
|
|
9
|
+
const mediumAsCanonical = options?.mediumAsCanonical ?? false;
|
|
10
|
+
|
|
9
11
|
let urlInfo;
|
|
10
12
|
|
|
11
13
|
// Get an ISO 8601 date - https://date-fns.org/docs/formatISO
|
|
@@ -33,6 +35,11 @@ const processMeta = (name, $post) => {
|
|
|
33
35
|
post.data.updated_at = $post('.dt-published').attr('datetime') || dateNow;
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
if (mediumAsCanonical) {
|
|
39
|
+
const canonicalUrl = $post('.p-canonical').attr('href');
|
|
40
|
+
post.data.canonical_url = canonicalUrl;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
// $('img').map(async (i, el) => {
|
|
37
44
|
// let $image = $(el);
|
|
38
45
|
// let type = $image.attr('src') === undefined ? 'data-src' : 'src';
|
|
@@ -48,7 +55,7 @@ const processMeta = (name, $post) => {
|
|
|
48
55
|
return post;
|
|
49
56
|
};
|
|
50
57
|
|
|
51
|
-
const processAuthor = ($author) => {
|
|
58
|
+
const processAuthor = ({$author}) => {
|
|
52
59
|
return {
|
|
53
60
|
url: $author.attr('href'),
|
|
54
61
|
data: {
|
|
@@ -61,7 +68,7 @@ const processAuthor = ($author) => {
|
|
|
61
68
|
};
|
|
62
69
|
};
|
|
63
70
|
|
|
64
|
-
const processTags = ($tags) => {
|
|
71
|
+
const processTags = ({$tags}) => {
|
|
65
72
|
const tags = [];
|
|
66
73
|
$tags.each((i, tag) => {
|
|
67
74
|
let $tag = $(tag);
|
|
@@ -76,7 +83,7 @@ const processTags = ($tags) => {
|
|
|
76
83
|
return tags;
|
|
77
84
|
};
|
|
78
85
|
|
|
79
|
-
const processFeatureImage = (html, post) => {
|
|
86
|
+
const processFeatureImage = ({html, post}) => {
|
|
80
87
|
const $html = $.load(html, {
|
|
81
88
|
decodeEntities: false
|
|
82
89
|
});
|
|
@@ -121,19 +128,19 @@ const processFeatureImage = (html, post) => {
|
|
|
121
128
|
return $html.html().trim();
|
|
122
129
|
};
|
|
123
130
|
|
|
124
|
-
export default (name, html, globalUser) => {
|
|
131
|
+
export default ({name, html, globalUser, options}) => {
|
|
125
132
|
const $post = $.load(html, {
|
|
126
133
|
decodeEntities: false
|
|
127
134
|
});
|
|
128
135
|
|
|
129
|
-
const post = processMeta(name, $post);
|
|
136
|
+
const post = processMeta({name, $post, options});
|
|
130
137
|
|
|
131
138
|
// Process content
|
|
132
|
-
post.data.html = processContent($post('.e-content'), post);
|
|
139
|
+
post.data.html = processContent({content: $post('.e-content'), post});
|
|
133
140
|
|
|
134
141
|
// Process author
|
|
135
142
|
if ($post('.p-author').length) {
|
|
136
|
-
post.data.author = processAuthor($post('.p-author'));
|
|
143
|
+
post.data.author = processAuthor({$author: $post('.p-author')});
|
|
137
144
|
// @TODO check if this is the global user and use that?
|
|
138
145
|
} else if (globalUser) {
|
|
139
146
|
post.data.author = globalUser;
|
|
@@ -141,7 +148,7 @@ export default (name, html, globalUser) => {
|
|
|
141
148
|
|
|
142
149
|
// Process tags
|
|
143
150
|
if ($post('.p-tags a').length) {
|
|
144
|
-
post.data.tags = processTags($post('.p-tags a'));
|
|
151
|
+
post.data.tags = processTags({$tags: $post('.p-tags a')});
|
|
145
152
|
} else {
|
|
146
153
|
post.data.tags = [];
|
|
147
154
|
}
|
|
@@ -152,7 +159,7 @@ export default (name, html, globalUser) => {
|
|
|
152
159
|
|
|
153
160
|
// Grab the featured image
|
|
154
161
|
// Do this last so that we can add tags to indicate feature image style
|
|
155
|
-
post.data.html = processFeatureImage(post.data.html, post);
|
|
162
|
+
post.data.html = processFeatureImage({html: post.data.html, post});
|
|
156
163
|
|
|
157
164
|
return post;
|
|
158
165
|
};
|
package/lib/process-profile.js
CHANGED
package/lib/process.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import processPost from './process-post.js';
|
|
2
2
|
import processProfile from './process-profile.js';
|
|
3
3
|
|
|
4
|
-
export default (input) => {
|
|
4
|
+
export default (input, options) => {
|
|
5
5
|
let output = {};
|
|
6
6
|
|
|
7
7
|
if (input.profile || input.profiles) {
|
|
8
|
-
output.users = [processProfile(input.profile || input.profiles)];
|
|
8
|
+
output.users = [processProfile({html: input.profile || input.profiles})];
|
|
9
9
|
}
|
|
10
10
|
|
|
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(post.name, post.html, globalUser));
|
|
14
|
+
output.posts = input.posts.map(post => processPost({name: post.name, html: post.html, globalUser, options}));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
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.15.0",
|
|
4
4
|
"description": "tbc",
|
|
5
5
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-medium-export",
|
|
6
6
|
"author": "Ghost Foundation",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"cheerio": "0.22.0",
|
|
33
33
|
"date-fns": "2.30.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "981152083f74323453f79e4e2fb4668742500dda"
|
|
36
36
|
}
|