@tryghost/mg-substack 1.6.0 → 1.7.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/lib/process.js +9 -6
- package/package.json +4 -3
package/lib/process.js
CHANGED
|
@@ -8,6 +8,7 @@ import {decode} from 'html-entities';
|
|
|
8
8
|
import {parseSrcset} from 'srcset';
|
|
9
9
|
import {_base as debugFactory} from '@tryghost/debug';
|
|
10
10
|
import {slugify} from '@tryghost/string';
|
|
11
|
+
import escapeStringRegexp from 'escape-string-regexp';
|
|
11
12
|
|
|
12
13
|
const {parseFragment, serializeChildren, replaceWith, insertBefore, insertAfter, attr, parents} = domUtils;
|
|
13
14
|
|
|
@@ -43,12 +44,14 @@ const readFiles = async (files, postsDir) => {
|
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
const largeImageUrl = (path) => {
|
|
46
|
-
|
|
47
|
+
const substackCdnUrl = URL.parse(path);
|
|
48
|
+
if (substackCdnUrl?.hostname === 'substackcdn.com' && substackCdnUrl.pathname.startsWith('/image/fetch/')) {
|
|
47
49
|
path = decodeURIComponent(path.split('/').pop());
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
const bucketeerUrl = URL.parse(path);
|
|
53
|
+
if (bucketeerUrl?.hostname.startsWith('bucketeer-')) {
|
|
54
|
+
path = path.replace(/https:\/\/.*\.s3\.amazonaws\.com/gmi, 'https://substack-post-media.s3.amazonaws.com');
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
return path;
|
|
@@ -585,7 +588,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
585
588
|
parsed.$('p.button-wrapper').forEach((button) => {
|
|
586
589
|
let buttons = parsed.$(':scope > a.button', button);
|
|
587
590
|
if (buttons.length === 1 && siteUrl) {
|
|
588
|
-
let siteRegex = new RegExp(`^(?:${siteUrl}(?:\\/?)(?:p\\/)?)([a-zA-Z-_\\d]*)(?:\\/?)`, 'gi');
|
|
591
|
+
let siteRegex = new RegExp(`^(?:${escapeStringRegexp(siteUrl)}(?:\\/?)(?:p\\/)?)([a-zA-Z-_\\d]*)(?:\\/?)`, 'gi');
|
|
589
592
|
let buttonLink = buttons[0];
|
|
590
593
|
let buttonHref = attr(buttonLink, 'href');
|
|
591
594
|
let buttonText = buttonLink.textContent;
|
|
@@ -673,7 +676,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
673
676
|
if (options.noSubscribeButtons) {
|
|
674
677
|
parsed.$('a').forEach((anchor) => {
|
|
675
678
|
let href = attr(anchor, 'href');
|
|
676
|
-
let linkRegex = new RegExp(`^(${siteUrl})?(/subscribe)(.*)`, 'gi');
|
|
679
|
+
let linkRegex = new RegExp(`^(${escapeStringRegexp(siteUrl)})?(/subscribe)(.*)`, 'gi');
|
|
677
680
|
|
|
678
681
|
if (!href) {
|
|
679
682
|
return;
|
|
@@ -688,7 +691,7 @@ const processContent = (post, siteUrl, options) => {
|
|
|
688
691
|
} else if (options.subscribeLink) {
|
|
689
692
|
parsed.$('a').forEach((anchor) => {
|
|
690
693
|
let href = attr(anchor, 'href');
|
|
691
|
-
let linkRegex = new RegExp(`^(${siteUrl})?(/subscribe)(.*)`, 'gi');
|
|
694
|
+
let linkRegex = new RegExp(`^(${escapeStringRegexp(siteUrl)})?(/subscribe)(.*)`, 'gi');
|
|
692
695
|
|
|
693
696
|
if (!href) {
|
|
694
697
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/migrate.git",
|
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
"@tryghost/debug": "2.2.3",
|
|
25
25
|
"@tryghost/errors": "3.2.4",
|
|
26
26
|
"@tryghost/string": "0.3.5",
|
|
27
|
+
"escape-string-regexp": "5.0.0",
|
|
27
28
|
"he": "1.2.0",
|
|
28
29
|
"html-entities": "2.6.0",
|
|
29
30
|
"simple-dom": "1.4.0",
|
|
30
31
|
"srcset": "5.0.3",
|
|
31
|
-
"@tryghost/mg-
|
|
32
|
-
"@tryghost/mg-utils": "0.
|
|
32
|
+
"@tryghost/mg-utils": "0.11.1",
|
|
33
|
+
"@tryghost/mg-fs-utils": "0.26.1"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
36
|
"dev": "echo \"Implement me!\"",
|