@tryghost/mg-beehiiv 0.1.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/LICENSE +21 -0
- package/README.md +95 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/lib/mapper.d.ts +23 -0
- package/build/lib/mapper.js +106 -0
- package/build/lib/mapper.js.map +1 -0
- package/build/lib/process.d.ts +11 -0
- package/build/lib/process.js +111 -0
- package/build/lib/process.js.map +1 -0
- package/build/test/mapper.test.d.ts +1 -0
- package/build/test/mapper.test.js +180 -0
- package/build/test/mapper.test.js.map +1 -0
- package/build/test/process.test.d.ts +1 -0
- package/build/test/process.test.js +209 -0
- package/build/test/process.test.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2023 Ghost Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Migrate beehiiv `csv` Export
|
|
2
|
+
|
|
3
|
+
Converts a beehiiv `csv` export and generates a `zip` file you can import into a Ghost installation.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
To install the CLI, which is required for the Usage commands below:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install --global @tryghost/migrate
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
To use this package in your own project:
|
|
15
|
+
|
|
16
|
+
`npm install @tryghost/mg-beehiiv --save`
|
|
17
|
+
|
|
18
|
+
or
|
|
19
|
+
|
|
20
|
+
`yarn add @tryghost/mg-beehiiv`
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
To run basic beehiiv migration, the required command is this:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
migrate beehiiv --posts /path/to/posts.csv --url https://example.com
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A more complex command for a beehiiv migration looks like this:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
migrate beehiiv --posts /path/to/posts.csv --url https://example.com --default_author_name 'Author Name' --subscribeLink '/join'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
38
|
+
|
|
39
|
+
- **`--posts`** (required)
|
|
40
|
+
- Path to a zip file
|
|
41
|
+
- string - default: `null`
|
|
42
|
+
- **`--url`** (required)
|
|
43
|
+
- Site URL
|
|
44
|
+
- string - default: `null`
|
|
45
|
+
- **`--defaultAuthorName`**
|
|
46
|
+
- The name to use where no author is specified. Names with spaces should be quoted.
|
|
47
|
+
- string - default: `null`
|
|
48
|
+
- **`-s` `--scrape`**
|
|
49
|
+
- Configure scraping tasks
|
|
50
|
+
- string - default: `all`
|
|
51
|
+
- Choices: `all`, `img`, `web`, `media`, `files`, `none`
|
|
52
|
+
- **`--subscribeLink`**
|
|
53
|
+
- Provide a path that existing `/subscribe` anchors will link to e.g. `/join-us` or `#/portal/signup` (`#` characters need to be escaped with a `\`)
|
|
54
|
+
- string - default: `#/portal/signup`
|
|
55
|
+
- **`--fallBackHTMLCard`**
|
|
56
|
+
- Fall back to convert to HTMLCard, if standard Mobiledoc convert fails
|
|
57
|
+
- bool - default: `true`
|
|
58
|
+
- **`--cache`**
|
|
59
|
+
- Persist local cache after migration is complete (Only if `--zip` is `true`)
|
|
60
|
+
- bool - default: `true`
|
|
61
|
+
- **`-V` `--verbose`**
|
|
62
|
+
- Show verbose output
|
|
63
|
+
- bool - default: `false`
|
|
64
|
+
- **`--zip`**
|
|
65
|
+
- Create a zip file
|
|
66
|
+
- bool - default: `true`
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Develop
|
|
70
|
+
|
|
71
|
+
This is a mono repository, managed with [lerna](https://lerna.js.org).
|
|
72
|
+
|
|
73
|
+
Follow the instructions for the top-level repo.
|
|
74
|
+
1. `git clone` this repo & `cd` into it as usual
|
|
75
|
+
2. Run `yarn` to install top-level dependencies.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Run
|
|
79
|
+
|
|
80
|
+
To run a local development copy, `cd` into this directory, and use `yarn dev` instead of `migrate` like so:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
yarn dev beehiiv <commands>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## Test
|
|
88
|
+
|
|
89
|
+
- `yarn lint` run just eslint
|
|
90
|
+
- `yarn test` run lint and tests
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Copyright & License
|
|
94
|
+
|
|
95
|
+
Copyright (c) 2013-2023 Ghost Foundation - Released under the [MIT license](LICENSE).
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAE3C,eAAe,KAAK,EAAE,IAAS,EAAE,MAAY,EAAE,EAAE;IAC7C,IAAI,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare const parsePostsCSV: ({ pathToFile }: {
|
|
2
|
+
pathToFile: string;
|
|
3
|
+
}) => Promise<any>;
|
|
4
|
+
declare const createSlug: ({ domain, url, title }: {
|
|
5
|
+
domain?: string | undefined;
|
|
6
|
+
url: string;
|
|
7
|
+
title?: string | undefined;
|
|
8
|
+
}) => any;
|
|
9
|
+
declare const fullImageURL: (path: string) => string;
|
|
10
|
+
declare const mapPost: ({ postData, options }: {
|
|
11
|
+
postData: beehiivPostDataObject;
|
|
12
|
+
options?: any;
|
|
13
|
+
}) => mappedDataObject;
|
|
14
|
+
declare const mapPosts: ({ pathToFile, options }: {
|
|
15
|
+
pathToFile: string;
|
|
16
|
+
options: any;
|
|
17
|
+
}) => Promise<any>;
|
|
18
|
+
declare const mapContent: (args: {
|
|
19
|
+
options: any;
|
|
20
|
+
}, logger?: any) => Promise<{
|
|
21
|
+
posts: never[];
|
|
22
|
+
}>;
|
|
23
|
+
export { createSlug, fullImageURL, parsePostsCSV, mapPost, mapPosts, mapContent };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fsUtils from '@tryghost/mg-fs-utils';
|
|
2
|
+
import { processHTML, removeDuplicateFeatureImage } from './process.js';
|
|
3
|
+
import { slugify } from '@tryghost/string';
|
|
4
|
+
const parsePostsCSV = async ({ pathToFile }) => {
|
|
5
|
+
const parseCSV = fsUtils.csv.parseCSV;
|
|
6
|
+
let parsed = await parseCSV(pathToFile);
|
|
7
|
+
return parsed;
|
|
8
|
+
};
|
|
9
|
+
const createSlug = ({ domain, url, title }) => {
|
|
10
|
+
// Remove the trailing slash from the domain
|
|
11
|
+
if (domain) {
|
|
12
|
+
domain = domain.replace(/\/$/, '');
|
|
13
|
+
}
|
|
14
|
+
if (url && url.length > 0) {
|
|
15
|
+
let cleanedUrl = url.replace(/https?:\/\/[a-z-A-Z0-9]+.beehiiv.com\/p\//, '');
|
|
16
|
+
if (domain && domain.length > 0) {
|
|
17
|
+
cleanedUrl = cleanedUrl.replace(`${domain}/p/`, '');
|
|
18
|
+
}
|
|
19
|
+
return slugify(cleanedUrl);
|
|
20
|
+
}
|
|
21
|
+
else if (title) {
|
|
22
|
+
return slugify(title);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const fullImageURL = (path) => {
|
|
26
|
+
const noLeadingSlash = path.replace(/^\//, '');
|
|
27
|
+
return `https://media.beehiiv.com/cdn-cgi/image/quality=100/${noLeadingSlash}`;
|
|
28
|
+
};
|
|
29
|
+
const mapPost = ({ postData, options }) => {
|
|
30
|
+
const domain = options?.url ?? false;
|
|
31
|
+
const postSlug = createSlug({ domain, url: postData.url, title: postData.web_title });
|
|
32
|
+
const mappedData = {
|
|
33
|
+
url: postData.url,
|
|
34
|
+
data: {
|
|
35
|
+
slug: postSlug,
|
|
36
|
+
published_at: postData.created_at,
|
|
37
|
+
updated_at: postData.created_at,
|
|
38
|
+
created_at: postData.created_at,
|
|
39
|
+
title: postData.web_title,
|
|
40
|
+
type: 'post',
|
|
41
|
+
html: postData.content_html,
|
|
42
|
+
status: (postData.status === 'confirmed') ? 'published' : 'draft',
|
|
43
|
+
custom_excerpt: postData.web_subtitle ?? null,
|
|
44
|
+
visibility: 'public',
|
|
45
|
+
tags: []
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (postData.audience === 'premium') {
|
|
49
|
+
mappedData.data.visibility = 'paid';
|
|
50
|
+
}
|
|
51
|
+
else if (postData.audience === 'both') {
|
|
52
|
+
mappedData.data.visibility = 'members';
|
|
53
|
+
}
|
|
54
|
+
if (mappedData.data.status === 'draft' && options?.defaultAuthorName) {
|
|
55
|
+
const defaultAuthorName = options.defaultAuthorName;
|
|
56
|
+
const defaultAuthorSlug = slugify(defaultAuthorName);
|
|
57
|
+
const defaultAuthorEmail = `${defaultAuthorSlug}@example.com`;
|
|
58
|
+
mappedData.data.author = {
|
|
59
|
+
url: `migrator-added-author-${defaultAuthorSlug}`,
|
|
60
|
+
data: {
|
|
61
|
+
slug: defaultAuthorSlug,
|
|
62
|
+
name: defaultAuthorName,
|
|
63
|
+
email: defaultAuthorEmail
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (postData.thumbnail_url) {
|
|
68
|
+
mappedData.data.feature_image = fullImageURL(postData.thumbnail_url);
|
|
69
|
+
}
|
|
70
|
+
mappedData.data.tags.push({
|
|
71
|
+
url: 'migrator-added-tag-hash-beehiiv',
|
|
72
|
+
data: {
|
|
73
|
+
slug: 'hash-beehiiv',
|
|
74
|
+
name: '#beehiiv'
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
mappedData.data.tags.push({
|
|
78
|
+
url: `migrator-added-tag-hash-beehiiv-${postData.audience}`,
|
|
79
|
+
data: {
|
|
80
|
+
slug: `hash-beehiiv-visibility-${postData.audience}`,
|
|
81
|
+
name: `#beehiiv-visibility-${postData.audience}`
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
mappedData.data.html = processHTML({ html: mappedData.data.html, postData: mappedData, options });
|
|
85
|
+
if (mappedData.data.feature_image) {
|
|
86
|
+
mappedData.data.html = removeDuplicateFeatureImage({ html: mappedData.data.html, featureSrc: mappedData.data.feature_image });
|
|
87
|
+
}
|
|
88
|
+
return mappedData;
|
|
89
|
+
};
|
|
90
|
+
const mapPosts = async ({ pathToFile, options }) => {
|
|
91
|
+
let parsed = await parsePostsCSV({ pathToFile });
|
|
92
|
+
const mappedPosts = parsed.map((postData) => {
|
|
93
|
+
return mapPost({ postData, options });
|
|
94
|
+
});
|
|
95
|
+
return mappedPosts;
|
|
96
|
+
};
|
|
97
|
+
const mapContent = async (args, logger) => {
|
|
98
|
+
const output = {
|
|
99
|
+
posts: []
|
|
100
|
+
};
|
|
101
|
+
let mappedPosts = await mapPosts({ pathToFile: args.options.posts, options: args.options });
|
|
102
|
+
output.posts = output.posts.concat(mappedPosts);
|
|
103
|
+
return output;
|
|
104
|
+
};
|
|
105
|
+
export { createSlug, fullImageURL, parsePostsCSV, mapPost, mapPosts, mapContent };
|
|
106
|
+
//# sourceMappingURL=mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.js","sourceRoot":"","sources":["../../src/lib/mapper.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAE,2BAA2B,EAAC,MAAM,cAAc,CAAC;AACtE,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AAEzC,MAAM,aAAa,GAAG,KAAK,EAAE,EAAC,UAAU,EAAuB,EAAE,EAAE;IAC/D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACtC,IAAI,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,CAAC;IAExC,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAiD,EAAE,EAAE;IACxF,4CAA4C;IAC5C,IAAI,MAAM,EAAE;QACR,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;KACtC;IAED,IAAI,GAAG,IAAI,GAAG,CAAC,MA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F,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAEhD,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,OAAO,EACH,UAAU,EACV,YAAY,EACZ,aAAa,EACb,OAAO,EACP,QAAQ,EACR,UAAU,EACb,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const getYouTubeID: (url: string) => string;
|
|
2
|
+
declare const processHTML: ({ html, postData, options }: {
|
|
3
|
+
html: string;
|
|
4
|
+
postData?: mappedDataObject | undefined;
|
|
5
|
+
options: any;
|
|
6
|
+
}) => any;
|
|
7
|
+
declare const removeDuplicateFeatureImage: ({ html, featureSrc }: {
|
|
8
|
+
html: string;
|
|
9
|
+
featureSrc: string;
|
|
10
|
+
}) => string;
|
|
11
|
+
export { getYouTubeID, processHTML, removeDuplicateFeatureImage };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import $ from 'cheerio';
|
|
2
|
+
import sanitizeHtml from 'sanitize-html';
|
|
3
|
+
const getYouTubeID = (url) => {
|
|
4
|
+
const arr = url.split(/(vi\/|v%3D|v=|\/v\/|youtu\.be\/|\/embed\/)/);
|
|
5
|
+
return undefined !== arr[2] ? arr[2].split(/[^\w-]/i)[0] : arr[0];
|
|
6
|
+
};
|
|
7
|
+
const processHTML = ({ html, postData, options }) => {
|
|
8
|
+
// First, clean up the email HTML to remove bits we don't want or change up
|
|
9
|
+
// Let's do some regexp magic to remove some beehiiv variables
|
|
10
|
+
// https://support.beehiiv.com/hc/en-us/articles/7606088263191
|
|
11
|
+
html = html.replace(/{{subscriber_id}}/g, '#');
|
|
12
|
+
html = html.replace(/{{rp_refer_url}}/g, '#');
|
|
13
|
+
let $html = $.load(html, {
|
|
14
|
+
xmlMode: true,
|
|
15
|
+
decodeEntities: false
|
|
16
|
+
});
|
|
17
|
+
// Remove hidden elements
|
|
18
|
+
$html('[style*="display:none"]').remove();
|
|
19
|
+
$html('[style*="display: none"]').remove();
|
|
20
|
+
// Remove the share links at the top
|
|
21
|
+
$html('table.mob-block').remove();
|
|
22
|
+
// Remove the open tracking pixel element
|
|
23
|
+
$html('div[data-open-tracking="true"]:contains("{{OPEN_TRACKING_PIXEL}}")').remove();
|
|
24
|
+
$html('p:contains("{{rp_personalized_text}}")').remove();
|
|
25
|
+
$html('img[src="{{rp_next_milestone_image_url}}"]').remove();
|
|
26
|
+
$html(`a[href="{{rp_referral_hub_url}}"]`).remove();
|
|
27
|
+
// Remove unsubscribe links, social links, & email footer
|
|
28
|
+
$html('td.b').remove();
|
|
29
|
+
// Remove the 'Read online' link
|
|
30
|
+
$html('td.f').remove();
|
|
31
|
+
// Remove the post title container, otherwise it would be a duplicate
|
|
32
|
+
if (postData?.data?.title) {
|
|
33
|
+
$html(`h1:contains("${postData.data.title}")`).parentsUntil('table').remove();
|
|
34
|
+
}
|
|
35
|
+
// Convert '...' to <hr />
|
|
36
|
+
$html('p').each((i, el) => {
|
|
37
|
+
const text = $html(el).text().trim();
|
|
38
|
+
if (text === '...' || text === '…' || text === '…') {
|
|
39
|
+
$html(el).replaceWith('<hr />');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
$html('a[href*="youtube.com"]').each((i, el) => {
|
|
43
|
+
const imageCount = $html(el).find('img').length;
|
|
44
|
+
const hasPlayIcon = $html(el).find('img[src*="youtube_play_icon.png"]').length;
|
|
45
|
+
const hasThumbnail = $html(el).find('img[src*="i.ytimg.com/vi"]').length;
|
|
46
|
+
const src = $html(el).attr('href');
|
|
47
|
+
const captionText = $html(el).find('p')?.text()?.trim() || false;
|
|
48
|
+
const captionHtml = $html(el).find('p')?.html()?.trim() || false;
|
|
49
|
+
if (imageCount === 2 && hasPlayIcon && hasThumbnail && src) {
|
|
50
|
+
const videoID = getYouTubeID(src);
|
|
51
|
+
const $figure = $(`<figure></figure>`);
|
|
52
|
+
$figure.addClass('kg-card kg-embed-card');
|
|
53
|
+
const $figcaption = $(`<figcaption></figcaption>`);
|
|
54
|
+
const $iframe = $(`<iframe src="https://www.youtube.com/embed/${videoID}?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe>`);
|
|
55
|
+
$figure.append($iframe);
|
|
56
|
+
if (captionText && captionText.length > 0) {
|
|
57
|
+
$iframe.attr('title', captionText);
|
|
58
|
+
}
|
|
59
|
+
if (captionHtml) {
|
|
60
|
+
$figure.addClass('kg-card-hascaption');
|
|
61
|
+
$figcaption.html(captionHtml);
|
|
62
|
+
$figure.append($figcaption);
|
|
63
|
+
}
|
|
64
|
+
$html(el).replaceWith($figure);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (options?.url && options?.subscribeLink) {
|
|
68
|
+
$html(`a[href^="${options.url}/subscribe"]`).each((i, el) => {
|
|
69
|
+
$html(el).attr('href', options.subscribeLink);
|
|
70
|
+
$html(el).removeAttr('target');
|
|
71
|
+
$html(el).removeAttr('rel');
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Get the cleaned HTML
|
|
75
|
+
const bodyHtml = $html('body').html();
|
|
76
|
+
// Pass the cleaned HTML through the sanitizer to only include specific elements
|
|
77
|
+
const sanitizedHtml = sanitizeHtml(bodyHtml, {
|
|
78
|
+
allowedTags: [
|
|
79
|
+
'b', 'i', 'em', 'strong', 'a', 'p', 'br', 'ul', 'ol', 'li', 'blockquote',
|
|
80
|
+
'figure', 'figcaption', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
81
|
+
'div', 'hr', 'iframe'
|
|
82
|
+
],
|
|
83
|
+
allowedAttributes: {
|
|
84
|
+
a: ['href', 'title', 'rel', 'target'],
|
|
85
|
+
img: ['src', 'alt', 'title'],
|
|
86
|
+
iframe: ['width', 'height', 'src', 'title', 'frameborder', 'allow', 'allowfullscreen'],
|
|
87
|
+
figure: ['class']
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return sanitizedHtml.trim();
|
|
91
|
+
};
|
|
92
|
+
const removeDuplicateFeatureImage = ({ html, featureSrc }) => {
|
|
93
|
+
let $html = $.load(html, {
|
|
94
|
+
xmlMode: true,
|
|
95
|
+
decodeEntities: false
|
|
96
|
+
});
|
|
97
|
+
let firstElement = $html('*').first();
|
|
98
|
+
if (($(firstElement).get(0) && $(firstElement).get(0).name === 'img') || $(firstElement).find('img').length) {
|
|
99
|
+
let theElementItself = $(firstElement).get(0).name === 'img' ? firstElement : $(firstElement).find('img');
|
|
100
|
+
let firstImgSrc = $(theElementItself).attr('src');
|
|
101
|
+
if (featureSrc.length > 0 && firstImgSrc) {
|
|
102
|
+
let normalizedFirstSrc = firstImgSrc.replace('fit=scale-down,format=auto,onerror=redirect,quality=80', 'quality=100');
|
|
103
|
+
if (featureSrc === normalizedFirstSrc) {
|
|
104
|
+
$(theElementItself).remove();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return $html.html();
|
|
109
|
+
};
|
|
110
|
+
export { getYouTubeID, processHTML, removeDuplicateFeatureImage };
|
|
111
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/lib/process.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,SAAS,CAAC;AACxB,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE;IACjC,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IACpE,OAAO,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CA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AAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1G,IAAI,WAAW,GAAQ,CAAC,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEvD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,EAAE;YACtC,IAAI,kBAAkB,GAAG,WAAW,CAAC,OAAO,CAAC,wDAAwD,EAAE,aAAa,CAAC,CAAC;YAEtH,IAAI,UAAU,KAAK,kBAAkB,EAAE;gBACnC,CAAC,CAAC,gBAAgB,CAAC,CAAC,MAAM,EAAE,CAAC;aAChC;SACJ;KACJ;IAED,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,EACZ,WAAW,EACX,2BAA2B,EAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parsePostsCSV, mapPost, fullImageURL, createSlug } from '../lib/mapper.js';
|
|
4
|
+
import mapper from '../index.js';
|
|
5
|
+
const __dirname = new URL('.', import.meta.url).pathname;
|
|
6
|
+
const fixturesPath = join(__dirname, '../../src/test/fixtures');
|
|
7
|
+
const beehiivCsvObj = {
|
|
8
|
+
id: 'abcd1234-1505-4fbf-9576-f3d1bd3034cc',
|
|
9
|
+
web_title: 'Sample Post',
|
|
10
|
+
status: 'confirmed',
|
|
11
|
+
audience: 'free',
|
|
12
|
+
url: 'https://example.beehiiv.com/p/sample-post',
|
|
13
|
+
web_subtitle: 'A website subtitle',
|
|
14
|
+
email_subject_line: 'Sample Post as a subject line',
|
|
15
|
+
email_preview_text: 'Email preview text',
|
|
16
|
+
content_html: '<p>Sample HTML here</p>',
|
|
17
|
+
thumbnail_url: 'uploads/asset/file/12345678/image.png',
|
|
18
|
+
created_at: '2023-01-18 21:25:27'
|
|
19
|
+
};
|
|
20
|
+
describe('beehiiv Mapper', () => {
|
|
21
|
+
describe('Utils', () => {
|
|
22
|
+
it('Can get the slug from post URL', async () => {
|
|
23
|
+
const slug = createSlug({ url: 'https://example.beehiiv.com/p/hello-world' });
|
|
24
|
+
assert.equal(slug, 'hello-world');
|
|
25
|
+
});
|
|
26
|
+
it('Can get the slug from post URL with a custom domain', async () => {
|
|
27
|
+
const slug = createSlug({ domain: 'https://example.com/', url: 'https://example.com/p/hello-world' });
|
|
28
|
+
assert.equal(slug, 'hello-world');
|
|
29
|
+
});
|
|
30
|
+
it('Can get the slug from post title when URL is blank', async () => {
|
|
31
|
+
const slug = createSlug({ url: '', title: '👋 This! Is a post title.' });
|
|
32
|
+
assert.equal(slug, 'this-is-a-post-title');
|
|
33
|
+
});
|
|
34
|
+
it('Can convert relative image path to absolute', async () => {
|
|
35
|
+
const newPath = fullImageURL('uploads/my-path.jpg');
|
|
36
|
+
assert.equal(newPath, 'https://media.beehiiv.com/cdn-cgi/image/quality=100/uploads/my-path.jpg');
|
|
37
|
+
const slashNewPath = fullImageURL('/uploads/my-path.jpg');
|
|
38
|
+
assert.equal(slashNewPath, 'https://media.beehiiv.com/cdn-cgi/image/quality=100/uploads/my-path.jpg');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('Reads correct number of posts from CSV', async () => {
|
|
42
|
+
const parsed = await parsePostsCSV({ pathToFile: join(fixturesPath, 'posts.csv') });
|
|
43
|
+
assert.equal(parsed.length, 2);
|
|
44
|
+
});
|
|
45
|
+
it('Gets required fields', async () => {
|
|
46
|
+
const parsed = await parsePostsCSV({ pathToFile: join(fixturesPath, 'posts.csv') });
|
|
47
|
+
// Check that the fields are correct
|
|
48
|
+
const fields = ['id', 'web_title', 'status', 'audience', 'url', 'web_subtitle', 'email_subject_line', 'email_preview_text', 'content_html', 'thumbnail_url', 'created_at'];
|
|
49
|
+
assert.deepEqual(Object.keys(parsed[0]), fields);
|
|
50
|
+
assert.deepEqual(Object.keys(parsed[1]), fields);
|
|
51
|
+
});
|
|
52
|
+
it('Gets correct values for each field', async () => {
|
|
53
|
+
const parsed = await parsePostsCSV({ pathToFile: join(fixturesPath, 'posts.csv') });
|
|
54
|
+
assert.equal(parsed[0].id, 'abcd1234-1505-4fbf-9576-f3d1bd3034cc');
|
|
55
|
+
assert.equal(parsed[0].web_title, 'Sample Post');
|
|
56
|
+
assert.equal(parsed[0].status, 'confirmed');
|
|
57
|
+
assert.equal(parsed[0].audience, 'free');
|
|
58
|
+
assert.equal(parsed[0].url, 'https://example.beehiiv.com/p/sample-post');
|
|
59
|
+
assert.equal(parsed[0].web_subtitle, 'A website subtitle');
|
|
60
|
+
assert.equal(parsed[0].email_subject_line, 'Sample Post as a subject line');
|
|
61
|
+
assert.equal(parsed[0].email_preview_text, 'Email preview text');
|
|
62
|
+
assert.equal(parsed[0].thumbnail_url, 'uploads/asset/file/12345678/image.png');
|
|
63
|
+
assert.equal(parsed[0].created_at, '2023-01-18 21:25:27');
|
|
64
|
+
});
|
|
65
|
+
it('Gets map beehiiv values to Ghost values', async () => {
|
|
66
|
+
const bhObj = { ...beehiivCsvObj };
|
|
67
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
68
|
+
const fields = ['url', 'data'];
|
|
69
|
+
assert.deepEqual(Object.keys(mapped), fields);
|
|
70
|
+
const dataFields = ['slug', 'published_at', 'updated_at', 'created_at', 'title', 'type', 'html', 'status', 'custom_excerpt', 'visibility', 'tags', 'feature_image'];
|
|
71
|
+
assert.deepEqual(Object.keys(mapped.data), dataFields);
|
|
72
|
+
assert.equal(mapped.url, 'https://example.beehiiv.com/p/sample-post');
|
|
73
|
+
assert.equal(mapped.data.slug, 'sample-post');
|
|
74
|
+
assert.equal(mapped.data.published_at, '2023-01-18 21:25:27');
|
|
75
|
+
assert.equal(mapped.data.updated_at, '2023-01-18 21:25:27');
|
|
76
|
+
assert.equal(mapped.data.created_at, '2023-01-18 21:25:27');
|
|
77
|
+
assert.equal(mapped.data.created_at, '2023-01-18 21:25:27');
|
|
78
|
+
assert.equal(mapped.data.title, 'Sample Post');
|
|
79
|
+
assert.equal(mapped.data.type, 'post');
|
|
80
|
+
assert.equal(mapped.data.status, 'published');
|
|
81
|
+
assert.equal(mapped.data.custom_excerpt, 'A website subtitle');
|
|
82
|
+
assert.equal(mapped.data.visibility, 'public');
|
|
83
|
+
});
|
|
84
|
+
it('Can add featured image', async () => {
|
|
85
|
+
const bhObj = { ...beehiivCsvObj };
|
|
86
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
87
|
+
assert.equal(mapped.data.feature_image, 'https://media.beehiiv.com/cdn-cgi/image/quality=100/uploads/asset/file/12345678/image.png');
|
|
88
|
+
});
|
|
89
|
+
it('Applies default author to draft posts', async () => {
|
|
90
|
+
const bhObj = { ...beehiivCsvObj };
|
|
91
|
+
bhObj.status = 'draft';
|
|
92
|
+
const mapped = await mapPost({ postData: bhObj, options: {
|
|
93
|
+
defaultAuthorName: 'Test Author'
|
|
94
|
+
} });
|
|
95
|
+
assert.equal(mapped.data.status, 'draft');
|
|
96
|
+
assert.deepEqual(mapped.data.author, {
|
|
97
|
+
url: 'migrator-added-author-test-author',
|
|
98
|
+
data: {
|
|
99
|
+
slug: 'test-author',
|
|
100
|
+
name: 'Test Author',
|
|
101
|
+
email: 'test-author@example.com'
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
it('Can add tags', async () => {
|
|
106
|
+
const bhObj = { ...beehiivCsvObj };
|
|
107
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
108
|
+
assert.deepEqual(mapped.data.tags, [
|
|
109
|
+
{
|
|
110
|
+
url: 'migrator-added-tag-hash-beehiiv',
|
|
111
|
+
data: {
|
|
112
|
+
slug: 'hash-beehiiv',
|
|
113
|
+
name: '#beehiiv'
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
url: 'migrator-added-tag-hash-beehiiv-free',
|
|
118
|
+
data: {
|
|
119
|
+
slug: 'hash-beehiiv-visibility-free',
|
|
120
|
+
name: '#beehiiv-visibility-free'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
it('Sets custom excerpt to null if none supplied', async () => {
|
|
126
|
+
const bhObj = { ...beehiivCsvObj };
|
|
127
|
+
delete bhObj.web_subtitle;
|
|
128
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
129
|
+
assert.equal(mapped.data.custom_excerpt, null);
|
|
130
|
+
});
|
|
131
|
+
describe('Post status', () => {
|
|
132
|
+
it('Handles a confirmed post status', async () => {
|
|
133
|
+
const bhObj = { ...beehiivCsvObj };
|
|
134
|
+
bhObj.status = 'confirmed';
|
|
135
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
136
|
+
assert.equal(mapped.data.status, 'published');
|
|
137
|
+
});
|
|
138
|
+
it('Handles a draft post status', async () => {
|
|
139
|
+
const bhObj = { ...beehiivCsvObj };
|
|
140
|
+
bhObj.status = 'draft';
|
|
141
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
142
|
+
assert.equal(mapped.data.status, 'draft');
|
|
143
|
+
});
|
|
144
|
+
it('Handles an archived post status', async () => {
|
|
145
|
+
const bhObj = { ...beehiivCsvObj };
|
|
146
|
+
bhObj.status = 'archived';
|
|
147
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
148
|
+
assert.equal(mapped.data.status, 'draft');
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe('Post visibility', () => {
|
|
152
|
+
it('Handles a both post visibility', async () => {
|
|
153
|
+
const bhObj = { ...beehiivCsvObj };
|
|
154
|
+
bhObj.audience = 'both';
|
|
155
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
156
|
+
assert.equal(mapped.data.visibility, 'members');
|
|
157
|
+
});
|
|
158
|
+
it('Handles a free post visibility', async () => {
|
|
159
|
+
const bhObj = { ...beehiivCsvObj };
|
|
160
|
+
bhObj.audience = 'free';
|
|
161
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
162
|
+
assert.equal(mapped.data.visibility, 'public');
|
|
163
|
+
});
|
|
164
|
+
it('Handles an premium post visibility', async () => {
|
|
165
|
+
const bhObj = { ...beehiivCsvObj };
|
|
166
|
+
bhObj.audience = 'premium';
|
|
167
|
+
const mapped = await mapPost({ postData: bhObj });
|
|
168
|
+
assert.equal(mapped.data.visibility, 'paid');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
it('Map return array of posts', async () => {
|
|
172
|
+
const mapped = await mapper({ options: {
|
|
173
|
+
posts: join(fixturesPath, 'posts.csv')
|
|
174
|
+
} });
|
|
175
|
+
assert.equal(mapped.posts.length, 2);
|
|
176
|
+
const fields = ['url', 'data'];
|
|
177
|
+
assert.deepEqual(Object.keys(mapped.posts[0]), fields);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
//# sourceMappingURL=mapper.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.test.js","sourceRoot":"","sources":["../../src/test/mapper.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAC,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAClF,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;AACzD,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,CAAC;AAEhE,MAAM,aAAa,GAA0B;IACzC,EAAE,EAAE,sCAAsC;IAC1C,SAAS,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IAAI,EAAE;YAChD,MAAM,KAAK,GAAG,EAAC,GAAG,aAAa,EAAC,CAAC;YACjC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;YAE3B,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC,CAAC;YAEhD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,EAAC,OAAO,EAAE;gBAClC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;aACzC,EAAC,CAAC,CAAC;QAEJ,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAErC,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/B,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { getYouTubeID, processHTML, removeDuplicateFeatureImage } from '../lib/process.js';
|
|
3
|
+
const mappedObject = {
|
|
4
|
+
url: 'https://example.beehiiv.com/p/lorem-ipsum',
|
|
5
|
+
data: {
|
|
6
|
+
slug: '',
|
|
7
|
+
published_at: '',
|
|
8
|
+
updated_at: '',
|
|
9
|
+
created_at: '',
|
|
10
|
+
title: 'Example Post',
|
|
11
|
+
type: '',
|
|
12
|
+
html: '',
|
|
13
|
+
status: 'published',
|
|
14
|
+
custom_excerpt: '',
|
|
15
|
+
visibility: 'public',
|
|
16
|
+
tags: []
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
describe('beehiiv Processor', () => {
|
|
20
|
+
describe('YouTube ID Extractor', () => {
|
|
21
|
+
it('Full URL', () => {
|
|
22
|
+
const id = getYouTubeID('https://youtube.com/watch?v=1234ABCD123');
|
|
23
|
+
assert.equal(id, '1234ABCD123');
|
|
24
|
+
});
|
|
25
|
+
it('Short URL', () => {
|
|
26
|
+
const id = getYouTubeID('https://youtu.be/1234ABCD123');
|
|
27
|
+
assert.equal(id, '1234ABCD123');
|
|
28
|
+
});
|
|
29
|
+
it('Embed URL', () => {
|
|
30
|
+
const id = getYouTubeID('https://www.youtube.com/embed/1234ABCD123');
|
|
31
|
+
assert.equal(id, '1234ABCD123');
|
|
32
|
+
});
|
|
33
|
+
it('ID only', () => {
|
|
34
|
+
const id = getYouTubeID('1234ABCD123');
|
|
35
|
+
assert.equal(id, '1234ABCD123');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('Process beehiiv Post Content', () => {
|
|
39
|
+
it('Can return basic HTML', () => {
|
|
40
|
+
const processed = processHTML({ html: '<body><p>Hello</p></body>', options: {} });
|
|
41
|
+
assert.equal(processed, '<p>Hello</p>');
|
|
42
|
+
});
|
|
43
|
+
// Remove hidden elements
|
|
44
|
+
it('Remove hidden elements', () => {
|
|
45
|
+
const htmlContent = `<body><div style="display:none">Hide 1</div><div style="display: none">Hide 2</div><div style="display: none ">Hide 3</div><div style="display: none;">Hide 4</div><div style="display:none; color: red;">Hide 5</div><p>Visible</p></body>`;
|
|
46
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
47
|
+
assert.equal(processed, '<p>Visible</p>');
|
|
48
|
+
});
|
|
49
|
+
// Remove the share links at the top
|
|
50
|
+
it('Remove the share links at the top', () => {
|
|
51
|
+
const htmlContent = `<body><table class="mob-block"><tr><td>Big bunch of links</td></tr></table><p>Real content</p></body>`;
|
|
52
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
53
|
+
assert.equal(processed, '<p>Real content</p>');
|
|
54
|
+
});
|
|
55
|
+
// Remove the open tracking pixel element
|
|
56
|
+
it('Remove the open tracking pixel element', () => {
|
|
57
|
+
const htmlContent = `<body><table><tr><td style="height:0px;width:0px;"><div style="height:1px;" data-open-tracking="true"> {{OPEN_TRACKING_PIXEL}} </div></td></tr></table><p>Real content</p></body>`;
|
|
58
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
59
|
+
assert.equal(processed, '<p>Real content</p>');
|
|
60
|
+
});
|
|
61
|
+
// Remove unsubscribe links, social links, & email footer
|
|
62
|
+
it('Remove unsubscribe links, social links, & email footer', () => {
|
|
63
|
+
const htmlContent = `<body><table><tr><td class="b">Big bunch of links</td></tr></table><p>Real content</p></body>`;
|
|
64
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
65
|
+
assert.equal(processed, '<p>Real content</p>');
|
|
66
|
+
});
|
|
67
|
+
// Remove the 'Read online' link
|
|
68
|
+
it('Remove the "Read online" link', () => {
|
|
69
|
+
const htmlContent = `<body><table><tr><td class="f"><p> July 10, 2023 | <a href="https://example.beehiiv.com/p/news-premium-subscribers">Read Online</a></p></td></tr></table><p>Real content</p></body>`;
|
|
70
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
71
|
+
assert.equal(processed, '<p>Real content</p>');
|
|
72
|
+
});
|
|
73
|
+
// Remove the post title container, otherwise it would be a duplicate
|
|
74
|
+
it('Remove the post title container', () => {
|
|
75
|
+
const htmlContent = `<body><table>
|
|
76
|
+
<tr>
|
|
77
|
+
<td align="center" valign="top">
|
|
78
|
+
<h1>Example Post </h1>
|
|
79
|
+
<p>An example subheader</p>
|
|
80
|
+
</td>
|
|
81
|
+
</tr>
|
|
82
|
+
</table>
|
|
83
|
+
<p>Real content</p>
|
|
84
|
+
</body>`;
|
|
85
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
86
|
+
assert.equal(processed, '<p>Real content</p>');
|
|
87
|
+
});
|
|
88
|
+
// Convert '...' to <hr />
|
|
89
|
+
it('Convert ... to <hr />', () => {
|
|
90
|
+
const htmlContent = `<body><p>...</p><p>…</p><p>…</p></body>`;
|
|
91
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
92
|
+
assert.equal(processed, '<hr /><hr /><hr />');
|
|
93
|
+
});
|
|
94
|
+
it('Converts YouTube links to embeds with no caption', () => {
|
|
95
|
+
const htmlContent = `<body>
|
|
96
|
+
<a href="https://youtube.com/watch?v=1234ABCD123">
|
|
97
|
+
<table>
|
|
98
|
+
<tr>
|
|
99
|
+
<td>
|
|
100
|
+
<table>
|
|
101
|
+
<tr>
|
|
102
|
+
<td>
|
|
103
|
+
<div>
|
|
104
|
+
<div>
|
|
105
|
+
<img src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/static_assets/youtube_play_icon.png" />
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
<img src=" https://i.ytimg.com/vi/Ay043v5Hhho/maxresdefault.jpg" />
|
|
109
|
+
</td>
|
|
110
|
+
</tr>
|
|
111
|
+
</table>
|
|
112
|
+
</td>
|
|
113
|
+
</tr>
|
|
114
|
+
</table>
|
|
115
|
+
</a>
|
|
116
|
+
<p><a href="https://youtube.com/watch?v=1234ABCD123">Regular YouTube link</a></p>
|
|
117
|
+
</body>`;
|
|
118
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
119
|
+
assert.equal(processed, `<figure class="kg-card kg-embed-card"><iframe src="https://www.youtube.com/embed/1234ABCD123?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></figure>
|
|
120
|
+
<p><a href="https://youtube.com/watch?v=1234ABCD123">Regular YouTube link</a></p>`);
|
|
121
|
+
});
|
|
122
|
+
it('Converts YouTube links to embeds with caption', () => {
|
|
123
|
+
const htmlContent = `<body>
|
|
124
|
+
<a href="https://youtube.com/watch?v=1234ABCD123">
|
|
125
|
+
<table>
|
|
126
|
+
<tr>
|
|
127
|
+
<td>
|
|
128
|
+
<table>
|
|
129
|
+
<tr>
|
|
130
|
+
<td>
|
|
131
|
+
<div>
|
|
132
|
+
<div>
|
|
133
|
+
<img src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/static_assets/youtube_play_icon.png" />
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
<img src=" https://i.ytimg.com/vi/Ay043v5Hhho/maxresdefault.jpg" />
|
|
137
|
+
</td>
|
|
138
|
+
</tr>
|
|
139
|
+
<tr>
|
|
140
|
+
<td>
|
|
141
|
+
<p>Example YouTube caption. Watch <a href="https://youtube.com/watch?v=1234ABCD123">here</a></p>
|
|
142
|
+
</td>
|
|
143
|
+
</tr>
|
|
144
|
+
</table>
|
|
145
|
+
</td>
|
|
146
|
+
</tr>
|
|
147
|
+
</table>
|
|
148
|
+
</a>
|
|
149
|
+
<p><a href="https://youtube.com/watch?v=1234ABCD123">Regular YouTube link</a></p>
|
|
150
|
+
</body>`;
|
|
151
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {} });
|
|
152
|
+
assert.equal(processed, `<figure class="kg-card kg-embed-card kg-card-hascaption"><iframe src="https://www.youtube.com/embed/1234ABCD123?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen title="Example YouTube caption. Watch here"><figcaption>Example YouTube caption. Watch <a href="https://youtube.com/watch?v=1234ABCD123">here</a></figcaption></iframe></figure>
|
|
153
|
+
<p><a href="https://youtube.com/watch?v=1234ABCD123">Regular YouTube link</a></p>`);
|
|
154
|
+
});
|
|
155
|
+
it('Updates subscribe links', () => {
|
|
156
|
+
const htmlContent = `<body><p>Stay updated! Be sure to <a class="link" href="https://example.beehiiv.com/subscribe?utm_source=example.beehiiv.com&utm_medium=newsletter" target="_blank" rel="noopener noreferrer nofollow">subscribe to our newsletter</a>.</p></body>`;
|
|
157
|
+
const processed = processHTML({ html: htmlContent, postData: mappedObject, options: {
|
|
158
|
+
url: 'https://example.beehiiv.com',
|
|
159
|
+
subscribeLink: '#/portal/signup'
|
|
160
|
+
} });
|
|
161
|
+
assert.equal(processed, '<p>Stay updated! Be sure to <a href="#/portal/signup">subscribe to our newsletter</a>.</p>');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
describe('Feature image deduplication', () => {
|
|
165
|
+
it('Can return basic HTML', () => {
|
|
166
|
+
const newHtml = removeDuplicateFeatureImage({
|
|
167
|
+
html: '<p>Hi</p>',
|
|
168
|
+
featureSrc: ''
|
|
169
|
+
});
|
|
170
|
+
assert.equal(newHtml, '<p>Hi</p>');
|
|
171
|
+
});
|
|
172
|
+
it('Does remove first image if it is a match', () => {
|
|
173
|
+
const newHtml = removeDuplicateFeatureImage({
|
|
174
|
+
html: '<img src="https://example.com/the-target.png" /><p>Hi</p>',
|
|
175
|
+
featureSrc: 'https://example.com/the-target.png'
|
|
176
|
+
});
|
|
177
|
+
assert.equal(newHtml, '<p>Hi</p>');
|
|
178
|
+
});
|
|
179
|
+
it('Does remove first image if it is a match 2', () => {
|
|
180
|
+
const newHtml = removeDuplicateFeatureImage({
|
|
181
|
+
html: '<figure><img src="https://example.com/the-target.png" /></figure><p>Hi</p>',
|
|
182
|
+
featureSrc: 'https://example.com/the-target.png'
|
|
183
|
+
});
|
|
184
|
+
assert.equal(newHtml, '<figure/><p>Hi</p>');
|
|
185
|
+
});
|
|
186
|
+
it('Does remove first image if it is a match 3', () => {
|
|
187
|
+
const newHtml = removeDuplicateFeatureImage({
|
|
188
|
+
html: '<div><figure><img src="https://example.com/the-target.png" /></figure></div><p>Hi</p>',
|
|
189
|
+
featureSrc: 'https://example.com/the-target.png'
|
|
190
|
+
});
|
|
191
|
+
assert.equal(newHtml, '<div><figure/></div><p>Hi</p>');
|
|
192
|
+
});
|
|
193
|
+
it('Does remove first image if it is a match 4', () => {
|
|
194
|
+
const newHtml = removeDuplicateFeatureImage({
|
|
195
|
+
html: '<div><figure><img src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/12345678/image.png" /></figure></div><p>Hi</p>',
|
|
196
|
+
featureSrc: 'https://media.beehiiv.com/cdn-cgi/image/quality=100/uploads/asset/file/12345678/image.png'
|
|
197
|
+
});
|
|
198
|
+
assert.equal(newHtml, '<div><figure/></div><p>Hi</p>');
|
|
199
|
+
});
|
|
200
|
+
it('Does not remove first image if is not a match', () => {
|
|
201
|
+
const newHtml = removeDuplicateFeatureImage({
|
|
202
|
+
html: '<img src="https://example.com/not-a-match.png" /><p>Hi</p>',
|
|
203
|
+
featureSrc: 'https://example.com/the-target.png'
|
|
204
|
+
});
|
|
205
|
+
assert.equal(newHtml, '<img src="https://example.com/not-a-match.png"/><p>Hi</p>');
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
//# sourceMappingURL=process.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.test.js","sourceRoot":"","sources":["../../src/test/process.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,YAAY,EAAE,WAAW,EAAE,2BAA2B,EAAC,MAAM,mBAAmB,CAAC;AAEzF,MAAM,YAAY,GAAqB;IACnC,GAAG,EAAE,2CAA2C;IAChD,IAAI,EAAE;QACF,IAAI,EAAE,EAAE;QACR,YAAY,EAAE,EAAE;QAChB,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,EAAE;QACd,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,EAAE;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.com/TryGhost/migrate/tree/main/packages/mg-beehiiv",
|
|
5
|
+
"author": "Ghost Foundation",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "build/index.js",
|
|
9
|
+
"types": "build/types.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "echo \"Implement me!\"",
|
|
12
|
+
"build:watch": "tsc --watch --preserveWatchOutput --sourceMap",
|
|
13
|
+
"build": "rm -rf build && rm -rf tsconfig.tsbuildinfo && tsc --build --sourceMap",
|
|
14
|
+
"prepare": "yarn build",
|
|
15
|
+
"lint": "eslint src/ --ext .ts --cache",
|
|
16
|
+
"posttest": "yarn lint",
|
|
17
|
+
"test": "rm -rf build && yarn build --force && NODE_OPTIONS=--experimental-vm-modules c8 --src src --all --check-coverage --100 --reporter text --reporter cobertura jest build/test"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"build"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/jest": "^29.5.3",
|
|
27
|
+
"@types/sinon": "^10.0.15",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
29
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
30
|
+
"c8": "8.0.1",
|
|
31
|
+
"dotenv": "16.3.1",
|
|
32
|
+
"eslint": "8.48.0",
|
|
33
|
+
"jest": "29.6.4",
|
|
34
|
+
"sinon": "^15.2.0",
|
|
35
|
+
"typescript": "5.2.2"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@tryghost/debug": "0.1.26",
|
|
39
|
+
"@tryghost/errors": "1.2.26",
|
|
40
|
+
"@tryghost/mg-fs-utils": "0.12.14",
|
|
41
|
+
"@tryghost/string": "0.2.8",
|
|
42
|
+
"cheerio": "1.0.0-rc.12",
|
|
43
|
+
"sanitize-html": "2.11.0"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "05dbefe144850acde9a05b7e25fc84dbf766be88"
|
|
46
|
+
}
|