@tryghost/mg-substack 0.7.10 → 0.8.1
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/mapper.js +2 -56
- package/lib/process.js +117 -0
- package/package.json +9 -9
package/lib/mapper.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
1
|
import errors from '@tryghost/errors';
|
|
3
2
|
import {slugify} from '@tryghost/string';
|
|
4
3
|
import {_base as debugFactory} from '@tryghost/debug';
|
|
@@ -7,13 +6,12 @@ import he from 'he';
|
|
|
7
6
|
const debug = debugFactory('migrate:substack:mapper');
|
|
8
7
|
|
|
9
8
|
const mapConfig = (data, options) => {
|
|
10
|
-
const {url, email, useMetaAuthor
|
|
9
|
+
const {url, email, useMetaAuthor} = options;
|
|
11
10
|
const slug = data.post_id.replace(/^(?:\d{1,10}\.)(\S*)/gm, '$1');
|
|
12
11
|
|
|
13
12
|
const dateNow = new Date();
|
|
14
13
|
|
|
15
14
|
const typeSlug = slugify(data.type);
|
|
16
|
-
const visibilitySlug = slugify(data.audience);
|
|
17
15
|
|
|
18
16
|
const contentType = (typeSlug === 'page') ? 'page' : 'post';
|
|
19
17
|
|
|
@@ -21,6 +19,7 @@ const mapConfig = (data, options) => {
|
|
|
21
19
|
url: `${url}/p/${slug}`,
|
|
22
20
|
substackId: data.post_id,
|
|
23
21
|
substackPodcastURL: data.podcast_url || false,
|
|
22
|
+
substackData: data,
|
|
24
23
|
data: {
|
|
25
24
|
slug: slug,
|
|
26
25
|
published_at: data.post_date || dateNow,
|
|
@@ -36,59 +35,6 @@ const mapConfig = (data, options) => {
|
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
37
|
|
|
39
|
-
let typeSlugSlugify = slugify(typeSlug);
|
|
40
|
-
mappedData.data.tags.push({
|
|
41
|
-
url: `${url}/tag/${typeSlugSlugify}`,
|
|
42
|
-
data: {
|
|
43
|
-
slug: typeSlugSlugify,
|
|
44
|
-
name: _.startCase(typeSlug)
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
if (addTag) {
|
|
49
|
-
let trimmedTag = addTag.trim();
|
|
50
|
-
let trimmedTagSlug = slugify(trimmedTag);
|
|
51
|
-
mappedData.data.tags.push({
|
|
52
|
-
url: `${url}/tag/${trimmedTagSlug}`,
|
|
53
|
-
data: {
|
|
54
|
-
slug: trimmedTagSlug,
|
|
55
|
-
name: trimmedTag
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (addPlatformTag) {
|
|
61
|
-
mappedData.data.tags.push({
|
|
62
|
-
url: `migrator-added-tag`,
|
|
63
|
-
data: {
|
|
64
|
-
slug: `hash-substack`,
|
|
65
|
-
name: `#substack`
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Add an internal tag based on the type of post
|
|
71
|
-
if (addTypeTag) {
|
|
72
|
-
mappedData.data.tags.push({
|
|
73
|
-
url: `migrator-added-tag-substack-type-${typeSlug}`,
|
|
74
|
-
data: {
|
|
75
|
-
slug: `hash-substack-type-${typeSlug}`,
|
|
76
|
-
name: `#substack-type-${typeSlug}`
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Add tags based on post visibility
|
|
82
|
-
if (addAccessTag) {
|
|
83
|
-
mappedData.data.tags.push({
|
|
84
|
-
url: `migrator-added-tag-substack-access-${visibilitySlug}`,
|
|
85
|
-
data: {
|
|
86
|
-
slug: `hash-substack-access-${visibilitySlug}`,
|
|
87
|
-
name: `#substack-access-${visibilitySlug}`
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
38
|
if (email && !useMetaAuthor) {
|
|
93
39
|
const authorSlug = email.replace(/(^[\w_-]*)(@[\w_-]*\.\w*(?:\.\w{0,2})?)/, '$1');
|
|
94
40
|
|
package/lib/process.js
CHANGED
|
@@ -8,9 +8,12 @@ import imageCard from '@tryghost/kg-default-cards/lib/cards/image.js';
|
|
|
8
8
|
import audioCard from '@tryghost/kg-default-cards/lib/cards/audio.js';
|
|
9
9
|
import galleryCard from '@tryghost/kg-default-cards/lib/cards/gallery.js';
|
|
10
10
|
import bookmarkCard from '@tryghost/kg-default-cards/lib/cards/bookmark.js';
|
|
11
|
+
import fileCard from '@tryghost/kg-default-cards/lib/cards/file.js';
|
|
11
12
|
import {decode} from 'html-entities';
|
|
12
13
|
import {parseSrcset} from 'srcset';
|
|
13
14
|
import {_base as debugFactory} from '@tryghost/debug';
|
|
15
|
+
import {slugify} from '@tryghost/string';
|
|
16
|
+
import _ from 'lodash';
|
|
14
17
|
|
|
15
18
|
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
|
|
16
19
|
const debug = debugFactory('migrate:substack:process');
|
|
@@ -132,6 +135,12 @@ const processContent = (post, siteUrl, options) => {
|
|
|
132
135
|
}
|
|
133
136
|
});
|
|
134
137
|
|
|
138
|
+
// Wrap these in a HTML card so they can be handled by publishers as needed
|
|
139
|
+
$html('div.latex-rendered').each((i, el) => {
|
|
140
|
+
$(el).before('<!--kg-card-begin: html-->');
|
|
141
|
+
$(el).after('<!--kg-card-end: html-->');
|
|
142
|
+
});
|
|
143
|
+
|
|
135
144
|
$html('.image3').each((i, el) => {
|
|
136
145
|
const attrs = $(el).attr('data-attrs');
|
|
137
146
|
const attrsObj = JSON.parse(attrs);
|
|
@@ -404,6 +413,49 @@ const processContent = (post, siteUrl, options) => {
|
|
|
404
413
|
$(anchor).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
|
|
405
414
|
});
|
|
406
415
|
|
|
416
|
+
$html('.file-embed-wrapper').each((i, el) => {
|
|
417
|
+
const fileSrc = $(el).find('.file-embed-button').attr('href');
|
|
418
|
+
const fileTitle = $(el).find('.file-embed-details-h1').text();
|
|
419
|
+
const fileDetails = $(el).find('.file-embed-details-h2').text();
|
|
420
|
+
|
|
421
|
+
const fileSizeMatch = fileDetails.match(/([\d.]+)([KMGT]B)/i);
|
|
422
|
+
let fileSizeBytes = 0;
|
|
423
|
+
|
|
424
|
+
if (fileSizeMatch) {
|
|
425
|
+
const size = parseFloat(fileSizeMatch[1]);
|
|
426
|
+
const unit = fileSizeMatch[2].toUpperCase();
|
|
427
|
+
|
|
428
|
+
switch (unit) {
|
|
429
|
+
case 'KB':
|
|
430
|
+
fileSizeBytes = size * 1024;
|
|
431
|
+
break;
|
|
432
|
+
case 'MB':
|
|
433
|
+
fileSizeBytes = size * 1024 * 1024;
|
|
434
|
+
break;
|
|
435
|
+
case 'GB':
|
|
436
|
+
fileSizeBytes = size * 1024 * 1024 * 1024;
|
|
437
|
+
break;
|
|
438
|
+
case 'TB':
|
|
439
|
+
fileSizeBytes = size * 1024 * 1024 * 1024 * 1024;
|
|
440
|
+
break;
|
|
441
|
+
default:
|
|
442
|
+
fileSizeBytes = size;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const cardOpts = {
|
|
447
|
+
env: {dom: new SimpleDom.Document()},
|
|
448
|
+
payload: {
|
|
449
|
+
src: fileSrc,
|
|
450
|
+
fileTitle: fileTitle,
|
|
451
|
+
fileName: fileTitle,
|
|
452
|
+
fileSize: fileSizeBytes
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
$(el).replaceWith(serializer.serialize(fileCard.render(cardOpts)));
|
|
457
|
+
});
|
|
458
|
+
|
|
407
459
|
$html('.comment').each((i, el) => {
|
|
408
460
|
$(el).remove();
|
|
409
461
|
});
|
|
@@ -670,6 +722,68 @@ const processContent = (post, siteUrl, options) => {
|
|
|
670
722
|
};
|
|
671
723
|
|
|
672
724
|
const processPost = (post, siteUrl, options) => {
|
|
725
|
+
// Add tags to the post
|
|
726
|
+
const typeSlug = slugify(post.substackData.type);
|
|
727
|
+
const visibilitySlug = slugify(post.substackData.audience);
|
|
728
|
+
const {addTag, addPlatformTag, addTypeTag, addAccessTag} = options;
|
|
729
|
+
|
|
730
|
+
// Add a type tag, e.g. Newsletter, Podcast, etc.
|
|
731
|
+
const typeSlugSlugify = slugify(typeSlug);
|
|
732
|
+
post.data.tags.push({
|
|
733
|
+
url: `${siteUrl}/tag/${typeSlugSlugify}`,
|
|
734
|
+
data: {
|
|
735
|
+
slug: typeSlugSlugify,
|
|
736
|
+
name: _.startCase(typeSlug)
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
// Add a custom tag if one is provided
|
|
741
|
+
if (addTag) {
|
|
742
|
+
let trimmedTag = addTag.trim();
|
|
743
|
+
let trimmedTagSlug = slugify(trimmedTag);
|
|
744
|
+
post.data.tags.push({
|
|
745
|
+
url: `${siteUrl}/tag/${trimmedTagSlug}`,
|
|
746
|
+
data: {
|
|
747
|
+
slug: trimmedTagSlug,
|
|
748
|
+
name: trimmedTag
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Add a platform tag
|
|
754
|
+
if (addPlatformTag) {
|
|
755
|
+
post.data.tags.push({
|
|
756
|
+
url: `migrator-added-tag`,
|
|
757
|
+
data: {
|
|
758
|
+
slug: `hash-substack`,
|
|
759
|
+
name: `#substack`
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// Add an internal tag based on the type of post
|
|
765
|
+
if (addTypeTag) {
|
|
766
|
+
post.data.tags.push({
|
|
767
|
+
url: `migrator-added-tag-substack-type-${typeSlug}`,
|
|
768
|
+
data: {
|
|
769
|
+
slug: `hash-substack-type-${typeSlug}`,
|
|
770
|
+
name: `#substack-type-${typeSlug}`
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// Add tags based on post visibility
|
|
776
|
+
if (addAccessTag) {
|
|
777
|
+
post.data.tags.push({
|
|
778
|
+
url: `migrator-added-tag-substack-access-${visibilitySlug}`,
|
|
779
|
+
data: {
|
|
780
|
+
slug: `hash-substack-access-${visibilitySlug}`,
|
|
781
|
+
name: `#substack-access-${visibilitySlug}`
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// And now process the HTML
|
|
673
787
|
post = processContent(post, siteUrl, options);
|
|
674
788
|
|
|
675
789
|
return post;
|
|
@@ -680,6 +794,9 @@ export default async (input, ctx) => {
|
|
|
680
794
|
let {url: siteUrl} = options;
|
|
681
795
|
const output = {};
|
|
682
796
|
|
|
797
|
+
// console.log('in default');
|
|
798
|
+
// console.log(input.posts);
|
|
799
|
+
|
|
683
800
|
if (postsDir) {
|
|
684
801
|
try {
|
|
685
802
|
let postFiles = await getFiles(postsDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"eslint": "8.57.0",
|
|
24
|
-
"jest": "
|
|
25
|
-
"jest-extended": "
|
|
24
|
+
"jest": "30.0.3",
|
|
25
|
+
"jest-extended": "6.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tryghost/debug": "0.1.
|
|
29
|
-
"@tryghost/errors": "1.3.
|
|
30
|
-
"@tryghost/kg-default-cards": "10.1.
|
|
31
|
-
"@tryghost/mg-fs-utils": "0.15.
|
|
32
|
-
"@tryghost/string": "0.2.
|
|
28
|
+
"@tryghost/debug": "0.1.35",
|
|
29
|
+
"@tryghost/errors": "1.3.8",
|
|
30
|
+
"@tryghost/kg-default-cards": "10.1.5",
|
|
31
|
+
"@tryghost/mg-fs-utils": "0.15.6",
|
|
32
|
+
"@tryghost/string": "0.2.17",
|
|
33
33
|
"cheerio": "1.0.0-rc.12",
|
|
34
34
|
"he": "1.2.0",
|
|
35
35
|
"html-entities": "2.6.0",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"simple-dom": "1.4.0",
|
|
38
38
|
"srcset": "5.0.1"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "cd90e134738bec4e87cf7e60e7e170af1d7171d4"
|
|
41
41
|
}
|