@tryghost/mg-substack 1.6.0 → 1.8.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.
Files changed (2) hide show
  1. package/lib/process.js +13 -6
  2. 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
- if (path.includes('https://substackcdn.com/image/fetch/')) {
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
- if (path.includes('https://bucketeer-')) {
51
- path = path.replace(/https:\/\/.*.s3.amazonaws.com/gmi, 'https://substack-post-media.s3.amazonaws.com');
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;
@@ -135,6 +138,10 @@ const processContent = (post, siteUrl, options) => {
135
138
  }
136
139
  });
137
140
 
141
+ parsed.$('h1 strong, h2 strong, h3 strong, h4 strong, h5 strong, h6 strong, h1 b, h2 b, h3 b, h4 b, h5 b, h6 b').forEach((el) => {
142
+ replaceWith(el, serializeChildren(el));
143
+ });
144
+
138
145
  // Wrap these in a HTML card so they can be handled by publishers as needed
139
146
  parsed.$('div.latex-rendered').forEach((el) => {
140
147
  insertBefore(el, '<!--kg-card-begin: html-->');
@@ -585,7 +592,7 @@ const processContent = (post, siteUrl, options) => {
585
592
  parsed.$('p.button-wrapper').forEach((button) => {
586
593
  let buttons = parsed.$(':scope > a.button', button);
587
594
  if (buttons.length === 1 && siteUrl) {
588
- let siteRegex = new RegExp(`^(?:${siteUrl}(?:\\/?)(?:p\\/)?)([a-zA-Z-_\\d]*)(?:\\/?)`, 'gi');
595
+ let siteRegex = new RegExp(`^(?:${escapeStringRegexp(siteUrl)}(?:\\/?)(?:p\\/)?)([a-zA-Z-_\\d]*)(?:\\/?)`, 'gi');
589
596
  let buttonLink = buttons[0];
590
597
  let buttonHref = attr(buttonLink, 'href');
591
598
  let buttonText = buttonLink.textContent;
@@ -673,7 +680,7 @@ const processContent = (post, siteUrl, options) => {
673
680
  if (options.noSubscribeButtons) {
674
681
  parsed.$('a').forEach((anchor) => {
675
682
  let href = attr(anchor, 'href');
676
- let linkRegex = new RegExp(`^(${siteUrl})?(/subscribe)(.*)`, 'gi');
683
+ let linkRegex = new RegExp(`^(${escapeStringRegexp(siteUrl)})?(/subscribe)(.*)`, 'gi');
677
684
 
678
685
  if (!href) {
679
686
  return;
@@ -688,7 +695,7 @@ const processContent = (post, siteUrl, options) => {
688
695
  } else if (options.subscribeLink) {
689
696
  parsed.$('a').forEach((anchor) => {
690
697
  let href = attr(anchor, 'href');
691
- let linkRegex = new RegExp(`^(${siteUrl})?(/subscribe)(.*)`, 'gi');
698
+ let linkRegex = new RegExp(`^(${escapeStringRegexp(siteUrl)})?(/subscribe)(.*)`, 'gi');
692
699
 
693
700
  if (!href) {
694
701
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "1.6.0",
3
+ "version": "1.8.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-fs-utils": "0.26.0",
32
- "@tryghost/mg-utils": "0.11.0"
32
+ "@tryghost/mg-fs-utils": "0.26.2",
33
+ "@tryghost/mg-utils": "0.11.2"
33
34
  },
34
35
  "scripts": {
35
36
  "dev": "echo \"Implement me!\"",