@tryghost/mg-substack 0.3.15 → 0.3.17
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/LICENSE +1 -1
- package/README.md +5 -2
- package/lib/process.js +35 -4
- package/package.json +11 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -91,6 +91,9 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
91
91
|
- **`--useMetaImage`**
|
|
92
92
|
- Use `og:image` value as the feature image
|
|
93
93
|
- bool - default: `true`
|
|
94
|
+
- **`--useFirstImage`**
|
|
95
|
+
- Use the first image in content as the feature image (useMetaImage takes priority)
|
|
96
|
+
- bool - default: `true`
|
|
94
97
|
- **`--useMetaAuthor`**
|
|
95
98
|
- Use the author field from `ld+json` (useful for posts with multiple authors)
|
|
96
99
|
- bool - default: `true`
|
|
@@ -98,7 +101,7 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
98
101
|
- Only migrate posts before and including a given date e.g. 'March 20 2018'
|
|
99
102
|
- string - default: `null`
|
|
100
103
|
- **`--postsAfter`**
|
|
101
|
-
- Only migrate posts after and including a given date e.g. 'August 16
|
|
104
|
+
- Only migrate posts after and including a given date e.g. 'August 16 2023'
|
|
102
105
|
- string - default: `null`
|
|
103
106
|
- **`--fallBackHTMLCard`**
|
|
104
107
|
- Fall back to convert to HTMLCard, if standard Mobiledoc convert fails
|
|
@@ -136,4 +139,4 @@ yarn dev substack <pathToZip>
|
|
|
136
139
|
|
|
137
140
|
# Copyright & License
|
|
138
141
|
|
|
139
|
-
Copyright (c) 2013-
|
|
142
|
+
Copyright (c) 2013-2023 Ghost Foundation - Released under the [MIT license](LICENSE).
|
package/lib/process.js
CHANGED
|
@@ -34,6 +34,10 @@ const readFiles = async (files, postsDir) => {
|
|
|
34
34
|
return postContent;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
const largeImageUrl = (src) => {
|
|
38
|
+
return src.replace(/w_[0-9]{2,5},h_[0-9]{2,5}/, 'w_2000,h_2000');
|
|
39
|
+
};
|
|
40
|
+
|
|
37
41
|
const getUnsizedImageName = (str) => {
|
|
38
42
|
const noSizeRegex = /(.*)(_[0-9]{1,4}x[0-9]{1,4}.[a-z]{2,4})/gmi;
|
|
39
43
|
let srcParts = str.split(/\/|%2F/);
|
|
@@ -72,8 +76,8 @@ const largestSrc = ($imageElem) => {
|
|
|
72
76
|
};
|
|
73
77
|
|
|
74
78
|
const processContent = (post, siteUrl, options) => {
|
|
75
|
-
const {substackPodcastURL
|
|
76
|
-
const
|
|
79
|
+
const {substackPodcastURL} = post;
|
|
80
|
+
const {useMetaImage, useFirstImage} = options;
|
|
77
81
|
|
|
78
82
|
let html = post.data?.html;
|
|
79
83
|
|
|
@@ -99,7 +103,11 @@ const processContent = (post, siteUrl, options) => {
|
|
|
99
103
|
});
|
|
100
104
|
|
|
101
105
|
// We use the `'og:image` as the feature image. If the first item in the content is an image and is the same as the `og:image`, remove it
|
|
102
|
-
if (
|
|
106
|
+
if (post.data?.og_image) {
|
|
107
|
+
if (useMetaImage) {
|
|
108
|
+
post.data.feature_image = largeImageUrl(post.data.og_image);
|
|
109
|
+
}
|
|
110
|
+
|
|
103
111
|
let firstElement = $html('body *').first();
|
|
104
112
|
|
|
105
113
|
if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
|
|
@@ -109,7 +117,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
109
117
|
if (firstImgSrc.length > 0) {
|
|
110
118
|
let unsizedFirstSrc = getUnsizedImageName(firstImgSrc);
|
|
111
119
|
|
|
112
|
-
let ogImgSrc =
|
|
120
|
+
let ogImgSrc = post.data.og_image;
|
|
113
121
|
let unsizedOgSrc = getUnsizedImageName(ogImgSrc);
|
|
114
122
|
|
|
115
123
|
if (unsizedFirstSrc === unsizedOgSrc) {
|
|
@@ -123,6 +131,29 @@ const processContent = (post, siteUrl, options) => {
|
|
|
123
131
|
}
|
|
124
132
|
}
|
|
125
133
|
|
|
134
|
+
if (useFirstImage && !post.data.feature_image) {
|
|
135
|
+
let firstElement = $html('body *').first();
|
|
136
|
+
|
|
137
|
+
if (firstElement.tagName === 'img' || ($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
|
|
138
|
+
let theElementItself = (firstElement.tagName === 'img' || $(firstElement).get(0).name === 'img') ? firstElement : $(firstElement).find('img');
|
|
139
|
+
let firstImgSrc = $(theElementItself).attr('src');
|
|
140
|
+
|
|
141
|
+
if (firstImgSrc.length > 0) {
|
|
142
|
+
let unsizedFirstSrc = largeImageUrl(firstImgSrc);
|
|
143
|
+
|
|
144
|
+
if (unsizedFirstSrc) {
|
|
145
|
+
post.data.feature_image = unsizedFirstSrc;
|
|
146
|
+
|
|
147
|
+
if ($(firstElement).find('figcaption').length) {
|
|
148
|
+
post.data.feature_image_caption = $(firstElement).find('figcaption').html();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
$(firstElement).remove();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
126
157
|
// If we have a podcast URL, embed an audio card at the start of the document
|
|
127
158
|
if (substackPodcastURL) {
|
|
128
159
|
debug(`Post ${post.data.slug} has podcast episode`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "echo \"Implement me!\"",
|
|
11
|
-
"test": "
|
|
11
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
12
12
|
"lint": "eslint . --ext .js --cache",
|
|
13
13
|
"posttest": "yarn lint"
|
|
14
14
|
},
|
|
@@ -20,21 +20,21 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
24
|
-
"jest": "29.
|
|
23
|
+
"eslint": "8.47.0",
|
|
24
|
+
"jest": "29.6.2",
|
|
25
25
|
"jest-extended": "3.2.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tryghost/debug": "0.1.
|
|
29
|
-
"@tryghost/errors": "1.2.
|
|
30
|
-
"@tryghost/kg-default-cards": "9.1.
|
|
31
|
-
"@tryghost/mg-fs-utils": "^0.12.
|
|
32
|
-
"@tryghost/string": "0.2.
|
|
28
|
+
"@tryghost/debug": "0.1.26",
|
|
29
|
+
"@tryghost/errors": "1.2.26",
|
|
30
|
+
"@tryghost/kg-default-cards": "9.1.1",
|
|
31
|
+
"@tryghost/mg-fs-utils": "^0.12.15",
|
|
32
|
+
"@tryghost/string": "0.2.8",
|
|
33
33
|
"date-fns": "2.30.0",
|
|
34
|
-
"html-entities": "2.
|
|
34
|
+
"html-entities": "2.4.0",
|
|
35
35
|
"lodash": "4.17.21",
|
|
36
36
|
"simple-dom": "1.4.0",
|
|
37
37
|
"srcset": "5.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "0df990176ed00c9076d1bec7ddafa2a6b2ddd967"
|
|
40
40
|
}
|