@tryghost/mg-substack 0.3.16 → 0.3.18
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 +24 -1
- 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
|
@@ -77,7 +77,7 @@ const largestSrc = ($imageElem) => {
|
|
|
77
77
|
|
|
78
78
|
const processContent = (post, siteUrl, options) => {
|
|
79
79
|
const {substackPodcastURL} = post;
|
|
80
|
-
const {useMetaImage} = options;
|
|
80
|
+
const {useMetaImage, useFirstImage} = options;
|
|
81
81
|
|
|
82
82
|
let html = post.data?.html;
|
|
83
83
|
|
|
@@ -131,6 +131,29 @@ const processContent = (post, siteUrl, options) => {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
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
|
+
|
|
134
157
|
// If we have a podcast URL, embed an audio card at the start of the document
|
|
135
158
|
if (substackPodcastURL) {
|
|
136
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.18",
|
|
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.
|
|
25
|
-
"jest-extended": "
|
|
23
|
+
"eslint": "8.48.0",
|
|
24
|
+
"jest": "29.6.4",
|
|
25
|
+
"jest-extended": "4.0.1"
|
|
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.4",
|
|
31
|
+
"@tryghost/mg-fs-utils": "^0.12.16",
|
|
32
|
+
"@tryghost/string": "0.2.8",
|
|
33
33
|
"date-fns": "2.30.0",
|
|
34
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": "05dbefe144850acde9a05b7e25fc84dbf766be88"
|
|
40
40
|
}
|