@tryghost/mg-substack 0.3.11 → 0.3.13
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/README.md +13 -1
- package/lib/mapper.js +37 -23
- package/lib/process.js +35 -2
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -61,11 +61,23 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
61
61
|
- **`--addTag`**
|
|
62
62
|
- string - default: `null`
|
|
63
63
|
- Provide a tag name which should be added to every post in this migration (Wrap in single quotes if tag name has spaces `'Like This'`)
|
|
64
|
+
- **`--addPlatformTag`**
|
|
65
|
+
- Add #substack tag to migrated content
|
|
66
|
+
- bool - default: `true`
|
|
67
|
+
- **`--addTypeTag`**
|
|
68
|
+
- Add #substack-{type} tag to migrated content (post, podcast, etc)
|
|
69
|
+
- bool - default: `true`
|
|
70
|
+
- **`--addAccessTag`**
|
|
71
|
+
- Add #substack-{access} tag to migrated content (public, paid, etc)
|
|
72
|
+
- bool - default: `true`
|
|
64
73
|
- **`--drafts`**
|
|
65
74
|
- Import draft posts
|
|
66
75
|
- bool - default: `true`
|
|
76
|
+
- **`--pages`**
|
|
77
|
+
- Import pages
|
|
78
|
+
- bool - default: `true`
|
|
67
79
|
- **`--threads`**
|
|
68
|
-
- Import
|
|
80
|
+
- Import threads
|
|
69
81
|
- bool - default: `false`
|
|
70
82
|
- **`--subscribeLink`**
|
|
71
83
|
- Provide a path that existing `/subscribe` anchors will link to e.g. `/join-us` or `#/portal/signup` (`#` characters need to be escaped with a `\`)
|
package/lib/mapper.js
CHANGED
|
@@ -6,7 +6,8 @@ import {_base as debugFactory} from '@tryghost/debug';
|
|
|
6
6
|
|
|
7
7
|
const debug = debugFactory('migrate:substack:mapper');
|
|
8
8
|
|
|
9
|
-
const mapConfig = (data,
|
|
9
|
+
const mapConfig = (data, options) => {
|
|
10
|
+
const {url, email, useMetaAuthor, addTag, addPlatformTag, addTypeTag, addAccessTag} = options;
|
|
10
11
|
const slug = data.post_id.replace(/^(?:\d{1,10}\.)(\S*)/gm, '$1');
|
|
11
12
|
|
|
12
13
|
// Get an ISO 8601 date - https://date-fns.org/docs/formatISO
|
|
@@ -15,6 +16,8 @@ const mapConfig = (data, {url, email, useMetaAuthor, addTag}) => {
|
|
|
15
16
|
const typeSlug = slugify(data.type);
|
|
16
17
|
const visibilitySlug = slugify(data.audience);
|
|
17
18
|
|
|
19
|
+
const contentType = (typeSlug === 'page') ? 'page' : 'post';
|
|
20
|
+
|
|
18
21
|
const mappedData = {
|
|
19
22
|
url: `${url}/p/${slug}`,
|
|
20
23
|
substackId: data.post_id,
|
|
@@ -26,7 +29,7 @@ const mapConfig = (data, {url, email, useMetaAuthor, addTag}) => {
|
|
|
26
29
|
created_at: data.post_date || dateNow,
|
|
27
30
|
title: data.title || slug,
|
|
28
31
|
custom_excerpt: data.subtitle,
|
|
29
|
-
type:
|
|
32
|
+
type: contentType,
|
|
30
33
|
html: data.html || null,
|
|
31
34
|
status: data.is_published.toLowerCase() === `true` ? 'published' : 'draft',
|
|
32
35
|
visibility: data.audience === 'only_paid' ? 'paid' : data.audience === 'only_free' ? 'members' : 'public',
|
|
@@ -55,31 +58,37 @@ const mapConfig = (data, {url, email, useMetaAuthor, addTag}) => {
|
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (addPlatformTag) {
|
|
62
|
+
mappedData.data.tags.push({
|
|
63
|
+
url: `migrator-added-tag`,
|
|
64
|
+
data: {
|
|
65
|
+
slug: `hash-substack`,
|
|
66
|
+
name: `#substack`
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
65
70
|
|
|
66
71
|
// Add an internal tag based on the type of post
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
if (addTypeTag) {
|
|
73
|
+
mappedData.data.tags.push({
|
|
74
|
+
url: `migrator-added-tag-substack-type-${typeSlug}`,
|
|
75
|
+
data: {
|
|
76
|
+
slug: `hash-substack-type-${typeSlug}`,
|
|
77
|
+
name: `#substack-type-${typeSlug}`
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
74
81
|
|
|
75
82
|
// Add tags based on post visibility
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
if (addAccessTag) {
|
|
84
|
+
mappedData.data.tags.push({
|
|
85
|
+
url: `migrator-added-tag-substack-access-${visibilitySlug}`,
|
|
86
|
+
data: {
|
|
87
|
+
slug: `hash-substack-access-${visibilitySlug}`,
|
|
88
|
+
name: `#substack-access-${visibilitySlug}`
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
83
92
|
|
|
84
93
|
if (email && !useMetaAuthor) {
|
|
85
94
|
const authorSlug = email.replace(/(^[\w_-]*)(@[\w_-]*\.\w*(?:\.\w{0,2})?)/, '$1');
|
|
@@ -135,6 +144,11 @@ export default async (input, options) => {
|
|
|
135
144
|
input = input.filter(data => data.is_published.toLowerCase() === `true`);
|
|
136
145
|
}
|
|
137
146
|
|
|
147
|
+
if (!options.pages) {
|
|
148
|
+
debug(`Ignoring pages`);
|
|
149
|
+
input = input.filter(data => data.type.toLowerCase() !== `page`);
|
|
150
|
+
}
|
|
151
|
+
|
|
138
152
|
if (!options.threads) {
|
|
139
153
|
debug(`Ignoring threads`);
|
|
140
154
|
input = input.filter(data => data.type.toLowerCase() !== `thread`);
|
package/lib/process.js
CHANGED
|
@@ -282,8 +282,15 @@ const processContent = (post, siteUrl, options) => {
|
|
|
282
282
|
let footnotesCount = 0;
|
|
283
283
|
$html('.footnote').each((i, el) => {
|
|
284
284
|
let footnoteBodyAnchor = $(el).find('a').attr('href');
|
|
285
|
-
|
|
286
|
-
let
|
|
285
|
+
|
|
286
|
+
let footnoteID = null;
|
|
287
|
+
if ($(el).attr('id')) {
|
|
288
|
+
footnoteID = $(el).attr('id');
|
|
289
|
+
} else {
|
|
290
|
+
footnoteID = $(el).find('a').attr('id');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
let footnoteNumber = footnoteID.replace('footnote-', '');
|
|
287
294
|
let footnoteContent = $(el).find('.footnote-content');
|
|
288
295
|
|
|
289
296
|
footnoteContent.find('p').last().append(` <a href="${footnoteBodyAnchor}" title="Jump back to footnote ${footnoteNumber} in the text.">↩</a>`);
|
|
@@ -360,6 +367,32 @@ const processContent = (post, siteUrl, options) => {
|
|
|
360
367
|
$bookmark.after('<!--kg-card-end: html-->');
|
|
361
368
|
});
|
|
362
369
|
|
|
370
|
+
$html('div.instagram').each((i, el) => {
|
|
371
|
+
let src = $(el).find('a.instagram-image').attr('href');
|
|
372
|
+
|
|
373
|
+
if (!src) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
let parsed = url.parse(src);
|
|
378
|
+
|
|
379
|
+
if (parsed.search) {
|
|
380
|
+
// remove possible query params
|
|
381
|
+
parsed.search = null;
|
|
382
|
+
}
|
|
383
|
+
src = url.format(parsed, {search: false});
|
|
384
|
+
|
|
385
|
+
let $iframe = $('<iframe class="instagram-media instagram-media-rendered" id="instagram-embed-0" allowtransparency="true" allowfullscreen="true" frameborder="0" height="968" data-instgrm-payload-id="instagram-media-payload-0" scrolling="no" style="background: white; max-width: 658px; width: calc(100% - 2px); border-radius: 3px; border: 1px solid rgb(219, 219, 219); box-shadow: none; display: block; margin: 0px 0px 12px; min-width: 326px; padding: 0px;"></iframe>');
|
|
386
|
+
let $script = $('<script async="" src="//www.instagram.com/embed.js"></script>');
|
|
387
|
+
let $figure = $('<figure class="instagram"></figure>');
|
|
388
|
+
|
|
389
|
+
$iframe.attr('src', `${src}embed/captioned/`);
|
|
390
|
+
$figure.append($iframe);
|
|
391
|
+
$figure.append($script);
|
|
392
|
+
|
|
393
|
+
$(el).replaceWith($figure);
|
|
394
|
+
});
|
|
395
|
+
|
|
363
396
|
// convert HTML back to a string
|
|
364
397
|
html = $html('body').html();
|
|
365
398
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-substack",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-substack",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,21 +20,21 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
23
|
+
"eslint": "8.39.0",
|
|
24
24
|
"jest": "29.5.0",
|
|
25
25
|
"jest-extended": "3.2.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tryghost/debug": "0.1.
|
|
29
|
-
"@tryghost/errors": "1.2.
|
|
30
|
-
"@tryghost/kg-default-cards": "
|
|
31
|
-
"@tryghost/mg-fs-utils": "^0.12.
|
|
32
|
-
"@tryghost/string": "0.2.
|
|
33
|
-
"date-fns": "2.
|
|
28
|
+
"@tryghost/debug": "0.1.24",
|
|
29
|
+
"@tryghost/errors": "1.2.24",
|
|
30
|
+
"@tryghost/kg-default-cards": "9.0.1",
|
|
31
|
+
"@tryghost/mg-fs-utils": "^0.12.11",
|
|
32
|
+
"@tryghost/string": "0.2.5",
|
|
33
|
+
"date-fns": "2.30.0",
|
|
34
34
|
"html-entities": "2.3.3",
|
|
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": "d65f2805bbe5aa743af77e5c33b1909f467a1725"
|
|
40
40
|
}
|