@tryghost/mg-substack 0.7.9 → 0.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.
- package/lib/mapper.js +2 -56
- package/lib/process.js +111 -0
- package/package.json +10 -10
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');
|
|
@@ -404,6 +407,49 @@ const processContent = (post, siteUrl, options) => {
|
|
|
404
407
|
$(anchor).replaceWith(serializer.serialize(imageCard.render(cardOpts)));
|
|
405
408
|
});
|
|
406
409
|
|
|
410
|
+
$html('.file-embed-wrapper').each((i, el) => {
|
|
411
|
+
const fileSrc = $(el).find('.file-embed-button').attr('href');
|
|
412
|
+
const fileTitle = $(el).find('.file-embed-details-h1').text();
|
|
413
|
+
const fileDetails = $(el).find('.file-embed-details-h2').text();
|
|
414
|
+
|
|
415
|
+
const fileSizeMatch = fileDetails.match(/([\d.]+)([KMGT]B)/i);
|
|
416
|
+
let fileSizeBytes = 0;
|
|
417
|
+
|
|
418
|
+
if (fileSizeMatch) {
|
|
419
|
+
const size = parseFloat(fileSizeMatch[1]);
|
|
420
|
+
const unit = fileSizeMatch[2].toUpperCase();
|
|
421
|
+
|
|
422
|
+
switch (unit) {
|
|
423
|
+
case 'KB':
|
|
424
|
+
fileSizeBytes = size * 1024;
|
|
425
|
+
break;
|
|
426
|
+
case 'MB':
|
|
427
|
+
fileSizeBytes = size * 1024 * 1024;
|
|
428
|
+
break;
|
|
429
|
+
case 'GB':
|
|
430
|
+
fileSizeBytes = size * 1024 * 1024 * 1024;
|
|
431
|
+
break;
|
|
432
|
+
case 'TB':
|
|
433
|
+
fileSizeBytes = size * 1024 * 1024 * 1024 * 1024;
|
|
434
|
+
break;
|
|
435
|
+
default:
|
|
436
|
+
fileSizeBytes = size;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const cardOpts = {
|
|
441
|
+
env: {dom: new SimpleDom.Document()},
|
|
442
|
+
payload: {
|
|
443
|
+
src: fileSrc,
|
|
444
|
+
fileTitle: fileTitle,
|
|
445
|
+
fileName: fileTitle,
|
|
446
|
+
fileSize: fileSizeBytes
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
$(el).replaceWith(serializer.serialize(fileCard.render(cardOpts)));
|
|
451
|
+
});
|
|
452
|
+
|
|
407
453
|
$html('.comment').each((i, el) => {
|
|
408
454
|
$(el).remove();
|
|
409
455
|
});
|
|
@@ -670,6 +716,68 @@ const processContent = (post, siteUrl, options) => {
|
|
|
670
716
|
};
|
|
671
717
|
|
|
672
718
|
const processPost = (post, siteUrl, options) => {
|
|
719
|
+
// Add tags to the post
|
|
720
|
+
const typeSlug = slugify(post.substackData.type);
|
|
721
|
+
const visibilitySlug = slugify(post.substackData.audience);
|
|
722
|
+
const {addTag, addPlatformTag, addTypeTag, addAccessTag} = options;
|
|
723
|
+
|
|
724
|
+
// Add a type tag, e.g. Newsletter, Podcast, etc.
|
|
725
|
+
const typeSlugSlugify = slugify(typeSlug);
|
|
726
|
+
post.data.tags.push({
|
|
727
|
+
url: `${siteUrl}/tag/${typeSlugSlugify}`,
|
|
728
|
+
data: {
|
|
729
|
+
slug: typeSlugSlugify,
|
|
730
|
+
name: _.startCase(typeSlug)
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
// Add a custom tag if one is provided
|
|
735
|
+
if (addTag) {
|
|
736
|
+
let trimmedTag = addTag.trim();
|
|
737
|
+
let trimmedTagSlug = slugify(trimmedTag);
|
|
738
|
+
post.data.tags.push({
|
|
739
|
+
url: `${siteUrl}/tag/${trimmedTagSlug}`,
|
|
740
|
+
data: {
|
|
741
|
+
slug: trimmedTagSlug,
|
|
742
|
+
name: trimmedTag
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// Add a platform tag
|
|
748
|
+
if (addPlatformTag) {
|
|
749
|
+
post.data.tags.push({
|
|
750
|
+
url: `migrator-added-tag`,
|
|
751
|
+
data: {
|
|
752
|
+
slug: `hash-substack`,
|
|
753
|
+
name: `#substack`
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Add an internal tag based on the type of post
|
|
759
|
+
if (addTypeTag) {
|
|
760
|
+
post.data.tags.push({
|
|
761
|
+
url: `migrator-added-tag-substack-type-${typeSlug}`,
|
|
762
|
+
data: {
|
|
763
|
+
slug: `hash-substack-type-${typeSlug}`,
|
|
764
|
+
name: `#substack-type-${typeSlug}`
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// Add tags based on post visibility
|
|
770
|
+
if (addAccessTag) {
|
|
771
|
+
post.data.tags.push({
|
|
772
|
+
url: `migrator-added-tag-substack-access-${visibilitySlug}`,
|
|
773
|
+
data: {
|
|
774
|
+
slug: `hash-substack-access-${visibilitySlug}`,
|
|
775
|
+
name: `#substack-access-${visibilitySlug}`
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// And now process the HTML
|
|
673
781
|
post = processContent(post, siteUrl, options);
|
|
674
782
|
|
|
675
783
|
return post;
|
|
@@ -680,6 +788,9 @@ export default async (input, ctx) => {
|
|
|
680
788
|
let {url: siteUrl} = options;
|
|
681
789
|
const output = {};
|
|
682
790
|
|
|
791
|
+
// console.log('in default');
|
|
792
|
+
// console.log(input.posts);
|
|
793
|
+
|
|
683
794
|
if (postsDir) {
|
|
684
795
|
try {
|
|
685
796
|
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.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,21 +21,21 @@
|
|
|
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
|
-
"html-entities": "2.
|
|
35
|
+
"html-entities": "2.6.0",
|
|
36
36
|
"lodash": "4.17.21",
|
|
37
37
|
"simple-dom": "1.4.0",
|
|
38
38
|
"srcset": "5.0.1"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "958389c2c9667c0e7e44f983d4fd1aa256caff4d"
|
|
41
41
|
}
|