@tryghost/mg-beehiiv-api 0.1.2

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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +178 -0
  3. package/build/index.d.ts +9 -0
  4. package/build/index.js +9 -0
  5. package/build/index.js.map +1 -0
  6. package/build/lib/client.d.ts +2 -0
  7. package/build/lib/client.js +17 -0
  8. package/build/lib/client.js.map +1 -0
  9. package/build/lib/fetch.d.ts +6 -0
  10. package/build/lib/fetch.js +70 -0
  11. package/build/lib/fetch.js.map +1 -0
  12. package/build/lib/list-pubs.d.ts +2 -0
  13. package/build/lib/list-pubs.js +17 -0
  14. package/build/lib/list-pubs.js.map +1 -0
  15. package/build/lib/mapper.d.ts +6 -0
  16. package/build/lib/mapper.js +94 -0
  17. package/build/lib/mapper.js.map +1 -0
  18. package/build/lib/process.d.ts +11 -0
  19. package/build/lib/process.js +268 -0
  20. package/build/lib/process.js.map +1 -0
  21. package/build/test/client.test.d.ts +1 -0
  22. package/build/test/client.test.js +47 -0
  23. package/build/test/client.test.js.map +1 -0
  24. package/build/test/fetch.test.d.ts +1 -0
  25. package/build/test/fetch.test.js +292 -0
  26. package/build/test/fetch.test.js.map +1 -0
  27. package/build/test/index.test.d.ts +1 -0
  28. package/build/test/index.test.js +15 -0
  29. package/build/test/index.test.js.map +1 -0
  30. package/build/test/list-pubs.test.d.ts +1 -0
  31. package/build/test/list-pubs.test.js +66 -0
  32. package/build/test/list-pubs.test.js.map +1 -0
  33. package/build/test/mapper.test.d.ts +1 -0
  34. package/build/test/mapper.test.js +243 -0
  35. package/build/test/mapper.test.js.map +1 -0
  36. package/build/test/process.test.d.ts +1 -0
  37. package/build/test/process.test.js +300 -0
  38. package/build/test/process.test.js.map +1 -0
  39. package/package.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013-2026 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,178 @@
1
+ # Migrate beehiiv API
2
+
3
+ > [!IMPORTANT]
4
+ > This package is a work in progress, and is not ready for production use yet.
5
+
6
+ Migrate content from beehiiv to Ghost using the beehiiv API, and generate a `zip` file you can import into a Ghost installation.
7
+
8
+
9
+ ## Install
10
+
11
+ To install the CLI, which is required for the Usage commands below:
12
+
13
+ ```sh
14
+ npm install --global @tryghost/migrate
15
+ ```
16
+
17
+ To use this package in your own project:
18
+
19
+ `npm install @tryghost/mg-beehiiv-api --save`
20
+
21
+ or
22
+
23
+ `pnpm add @tryghost/mg-beehiiv-api`
24
+
25
+
26
+ ## Usage
27
+
28
+ To run a beehiiv API migration, the required command is:
29
+
30
+ ```sh
31
+ migrate beehiiv-api --key 1234abcd
32
+ ```
33
+
34
+ If no `--id` is provided, a list of available publications will be shown. Use the publication ID to run the full migration:
35
+
36
+ ```sh
37
+ migrate beehiiv-api --key 1234abcd --id pub_abcd1234
38
+ ```
39
+
40
+ It's possible to pass more options, in order to achieve a better migration file for Ghost:
41
+
42
+ - **`--key`** (required)
43
+ - beehiiv API key
44
+ - string - default: `null`
45
+ - **`--id`**
46
+ - beehiiv publication ID
47
+ - string - default: `null`
48
+ - **`--postsAfter`**
49
+ - Only migrate posts published on or after this date
50
+ - string - default: `null`
51
+ - Format: `YYYY-MM-DD`
52
+ - **`--postsBefore`**
53
+ - Only migrate posts published on or before this date
54
+ - string - default: `null`
55
+ - Format: `YYYY-MM-DD`
56
+ - **`-s` `--scrape`**
57
+ - Configure scraping tasks
58
+ - string - default: `all`
59
+ - Choices: `all`, `web`, `assets`, `none`
60
+ - `all`: Scrape web metadata and download assets
61
+ - `web`: Only scrape metadata from web pages
62
+ - `assets`: Only download assets (images, media, files)
63
+ - `none`: Skip all scraping tasks
64
+ - **`--subscribeLink`**
65
+ - Provide a path that existing `/subscribe` anchors will link to e.g. `/join-us` or `#/portal/signup` (`#` characters need to be escaped with a `\`)
66
+ - string - default: `#/portal/signup`
67
+ - **`--comments`**
68
+ - Keep comment buttons
69
+ - bool - default: `true`
70
+ - **`--commentLink`**
71
+ - Provide a path that existing comment anchors will link to e.g. `#ghost-comments-root` (`#` characters need to be escaped with a `\`)
72
+ - string - default: `#ghost-comments-root`
73
+ - **`--cache`**
74
+ - Persist local cache after migration is complete (Only if `--zip` is `true`)
75
+ - bool - default: `true`
76
+ - **`--tmpPath`**
77
+ - Specify the full path where the temporary files will be stored (Defaults a hidden tmp dir)
78
+ - string - default: `null`
79
+ - **`--outputPath`**
80
+ - Specify the full path where the final zip file will be saved to (Defaults to CWD)
81
+ - string - default: `null`
82
+ - **`--cacheName`**
83
+ - Provide a unique name for the cache directory (defaults to a UUID)
84
+ - string - default: `null`
85
+ - **`-V` `--verbose`**
86
+ - Show verbose output
87
+ - bool - default: `false`
88
+ - **`--zip`**
89
+ - Create a zip file (set to false to skip)
90
+ - bool - default: `true`
91
+
92
+ A more complex migration command could look like this:
93
+
94
+ ```sh
95
+ migrate beehiiv-api --key 1234abcd --id pub_abcd1234 --postsAfter 2024-01-01 --postsBefore 2024-12-31 --verbose
96
+ ```
97
+
98
+ This will migrate only posts published in 2024, and show all available output in the console.
99
+
100
+
101
+ ## HTML Processing
102
+
103
+ The `processHTML` function transforms beehiiv email HTML into clean, Ghost-compatible HTML. It applies the following transformations in order:
104
+
105
+ 1. **Variable replacement** — Removes beehiiv template variables (`{{subscriber_id}}`, `{{rp_refer_url}}`, etc.)
106
+ 2. **Content extraction** — Extracts content from `#content-blocks`
107
+ 3. **Horizontal rules** — Converts empty `div[style*="border-top"]` to `<hr>`
108
+ 4. **Sponsored content** — Converts tables containing "Sponsored Content" to Ghost HTML cards (see below)
109
+ 5. **Images** — Converts `<img>` to Ghost image cards with captions
110
+ 6. **Blockquotes** — Converts nested `padding-left` divs to `<blockquote>`
111
+ 7. **Buttons** — Converts `<a><button>` to Ghost button cards
112
+ 8. **Subscribe links** — Rewrites `/subscribe` links to the configured `--subscribeLink`
113
+ 9. **Comment links** — Rewrites or removes comment links based on `--comments` and `--commentLink`
114
+ 10. **Bookmark cards** — Converts `.generic-embed--root` to Ghost bookmark cards
115
+ 11. **Audio** — Unwraps audio iframes from table wrappers
116
+ 12. **YouTube** — Converts YouTube iframes to Ghost embed cards
117
+ 13. **Cleanup** — Removes empty paragraphs, `<style>` tags, mobile ads, style attributes, and heading formatting
118
+
119
+
120
+ ### Sponsored Content
121
+
122
+ beehiiv sponsored content blocks (styled `<table>` elements containing "Sponsored Content" text) are converted to Ghost HTML cards:
123
+
124
+ ```html
125
+ <!--kg-card-begin: html-->
126
+ <div class="mg-sponsored" data-mg-skip="image-card">
127
+ <p> Sponsored Content </p>
128
+ <h2> Ad Heading </h2>
129
+ <div><a href="..."><img src="..."></a></div>
130
+ <p> Ad body text </p>
131
+ <a href="...">Learn more</a>
132
+ </div>
133
+ <!--kg-card-end: html-->
134
+ ```
135
+
136
+ - Inner `<div>` elements containing text are converted to `<p>` tags
137
+ - Inner `<div>` elements containing images are preserved as-is
138
+ - Bare `<br>` elements between blocks are removed
139
+
140
+
141
+ ### `data-mg-skip`
142
+
143
+ The `data-mg-skip` attribute controls which processing steps are skipped for elements and their descendants. This prevents content inside marked elements from being transformed by later processing steps.
144
+
145
+ Supported values:
146
+
147
+ | Value | Effect |
148
+ |---|---|
149
+ | `image-card` | Images inside this element are not converted to Ghost image cards |
150
+
151
+
152
+ ## Develop
153
+
154
+ This is a mono repository, managed with [Nx](https://nx.dev/) and pnpm workspaces.
155
+
156
+ Follow the instructions for the top-level repo.
157
+ 1. `git clone` this repo & `cd` into it as usual
158
+ 2. Run `pnpm install` to install top-level dependencies.
159
+
160
+
161
+ ### Run
162
+
163
+ To run a local development copy, `cd` into this directory, and use `pnpm dev` instead of `migrate` like so:
164
+
165
+ ```sh
166
+ pnpm dev beehiiv-api --key 1234abcd --id pub_abcd1234
167
+ ```
168
+
169
+
170
+ ## Test
171
+
172
+ - `pnpm lint` run just eslint
173
+ - `pnpm test` run lint and tests
174
+
175
+
176
+ # Copyright & License
177
+
178
+ Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE).
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ listPublications: (apiKey: string) => Promise<any>;
3
+ fetchTasks: (options: any, ctx: any) => Promise<{
4
+ title: string;
5
+ task: (_: any, task: any) => Promise<void>;
6
+ }[]>;
7
+ mapPostsTasks: (options: any, ctx: any) => Promise<any>;
8
+ };
9
+ export default _default;
package/build/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { listPublications } from './lib/list-pubs.js';
2
+ import { mapPostsTasks } from './lib/mapper.js';
3
+ import { fetchTasks } from './lib/fetch.js';
4
+ export default {
5
+ listPublications,
6
+ fetchTasks,
7
+ mapPostsTasks
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAE1C,eAAe;IACX,gBAAgB;IAChB,UAAU;IACV,aAAa;CAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const client: (apiKey: string) => Promise<any>;
2
+ export { client };
@@ -0,0 +1,17 @@
1
+ import errors from '@tryghost/errors';
2
+ const client = async (apiKey) => {
3
+ const url = new URL(`https://api.beehiiv.com/v2/publications`);
4
+ const response = await fetch(url, {
5
+ method: 'GET',
6
+ headers: {
7
+ Authorization: `Bearer ${apiKey}`
8
+ }
9
+ });
10
+ if (!response.ok) {
11
+ throw new errors.InternalServerError({ message: `Request failed: ${response.status} ${response.statusText}` });
12
+ }
13
+ const data = await response.json();
14
+ return data.data;
15
+ };
16
+ export { client };
17
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,MAAM,MAAM,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IACpC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,yCAAyC,CAAC,CAAC;IAE/D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC9B,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACL,aAAa,EAAE,UAAU,MAAM,EAAE;SACpC;KACJ,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,MAAM,CAAC,mBAAmB,CAAC,EAAC,OAAO,EAAE,mBAAmB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,EAAC,CAAC,CAAC;IACjH,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEnC,OAAO,IAAI,CAAC,IAAI,CAAC;AACrB,CAAC,CAAC;AAEF,OAAO,EACH,MAAM,EACT,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const authedClient: (apiKey: string, theUrl: URL) => Promise<Response>;
2
+ export declare const fetchTasks: (options: any, ctx: any) => Promise<{
3
+ title: string;
4
+ task: (_: any, task: any) => Promise<void>;
5
+ }[]>;
6
+ export { authedClient };
@@ -0,0 +1,70 @@
1
+ import errors from '@tryghost/errors';
2
+ const API_LIMIT = 10;
3
+ const authedClient = async (apiKey, theUrl) => {
4
+ return fetch(theUrl, {
5
+ method: 'GET',
6
+ headers: {
7
+ Authorization: `Bearer ${apiKey}`
8
+ }
9
+ });
10
+ };
11
+ const discover = async (key, pubId) => {
12
+ const url = new URL(`https://api.beehiiv.com/v2/publications/${pubId}/posts`);
13
+ url.searchParams.append('limit', '1');
14
+ const response = await authedClient(key, url);
15
+ if (!response.ok) {
16
+ throw new errors.InternalServerError({ message: `Request failed: ${response.status} ${response.statusText}` });
17
+ }
18
+ const data = await response.json();
19
+ return data.total_results;
20
+ };
21
+ const cachedFetch = async ({ fileCache, key, pubId, limit = API_LIMIT, page }) => {
22
+ let filename = `beehiiv_api_${limit}_${page}.json`;
23
+ if (fileCache.hasFile(filename, 'tmp')) {
24
+ return await fileCache.readTmpJSONFile(filename);
25
+ }
26
+ const url = new URL(`https://api.beehiiv.com/v2/publications/${pubId}/posts`);
27
+ url.searchParams.append('limit', limit.toString());
28
+ url.searchParams.append('expand', 'free_web_content');
29
+ url.searchParams.append('expand', 'premium_web_content');
30
+ url.searchParams.append('page', page.toString());
31
+ const response = await authedClient(key, url);
32
+ if (!response.ok) {
33
+ throw new errors.InternalServerError({ message: `Request failed: ${response.status} ${response.statusText}` });
34
+ }
35
+ const data = await response.json();
36
+ await fileCache.writeTmpFile(data, filename);
37
+ return data;
38
+ };
39
+ export const fetchTasks = async (options, ctx) => {
40
+ const numberOfPosts = await discover(options.key, options.id);
41
+ const totalPages = Math.ceil(numberOfPosts / API_LIMIT);
42
+ let tasks = [];
43
+ for (let page = 1; page <= totalPages; page++) {
44
+ tasks.push({
45
+ title: `Fetching posts page ${page} of ${totalPages}`,
46
+ task: async (_, task) => {
47
+ try {
48
+ let response = await cachedFetch({ fileCache: ctx.fileCache, key: options.key, pubId: options.id, page: page });
49
+ ctx.result.posts = ctx.result.posts.concat(response.data);
50
+ if (options.postsAfter) {
51
+ const afterTimestamp = new Date(options.postsAfter).getTime() / 1000;
52
+ ctx.result.posts = ctx.result.posts.filter((post) => post.publish_date >= afterTimestamp);
53
+ }
54
+ if (options.postsBefore) {
55
+ const beforeTimestamp = new Date(options.postsBefore).getTime() / 1000;
56
+ ctx.result.posts = ctx.result.posts.filter((post) => post.publish_date <= beforeTimestamp);
57
+ }
58
+ }
59
+ catch (error) {
60
+ const errorMessage = error instanceof Error ? error.message : String(error);
61
+ task.output = errorMessage;
62
+ throw error;
63
+ }
64
+ }
65
+ });
66
+ }
67
+ return tasks;
68
+ };
69
+ export { authedClient };
70
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/lib/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,MAAM,YAAY,GAAG,KAAK,EAAE,MAAc,EAAE,MAAW,EAAE,EAAE;IACvD,OAAO,KAAK,CAAC,MAAM,EAAE;QACjB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACL,aAAa,EAAE,UAAU,MAAM,EAAE;SACpC;KACJ,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAW,EAAE,KAAa,EAAE,EAAE;IAClD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,2CAA2C,KAAK,QAAQ,CAAC,CAAC;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AC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAE1D,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;wBACrB,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;wBACrE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CACtC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,IAAI,cAAc,CACrD,CAAC;oBACN,CAAC;oBACD,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;wBACtB,MAAM,eAAe,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;wBACvE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CACtC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,IAAI,eAAe,CACtD,CAAC;oBACN,CAAC;gBACL,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC5E,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;oBAC3B,MAAM,KAAK,CAAC;gBAChB,CAAC;YACL,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EACH,YAAY,EACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const listPublications: (apiKey: string) => Promise<any>;
2
+ export { listPublications };
@@ -0,0 +1,17 @@
1
+ import errors from '@tryghost/errors';
2
+ import { authedClient } from './fetch.js';
3
+ const listPublications = async (apiKey) => {
4
+ const url = new URL(`https://api.beehiiv.com/v2/publications`);
5
+ url.searchParams.append('expand[]', 'stats');
6
+ const response = await authedClient(apiKey, url);
7
+ if (!response.ok) {
8
+ throw new errors.InternalServerError({
9
+ message: `Request failed: ${response.status} ${response.statusText}`,
10
+ context: `GET ${new URL(response.url).pathname}`
11
+ });
12
+ }
13
+ const data = await response.json();
14
+ return data.data;
15
+ };
16
+ export { listPublications };
17
+ //# sourceMappingURL=list-pubs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-pubs.js","sourceRoot":"","sources":["../../src/lib/list-pubs.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAExC,MAAM,gBAAgB,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IAC9C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,yCAAyC,CAAC,CAAC;IAC/D,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAE7C,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEjD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,MAAM,CAAC,mBAAmB,CAAC;YACjC,OAAO,EAAE,mBAAmB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE;YACpE,OAAO,EAAE,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;SACnD,CAAC,CAAC;IACP,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEnC,OAAO,IAAI,CAAC,IAAI,CAAC;AACrB,CAAC,CAAC;AAEF,OAAO,EACH,gBAAgB,EACnB,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const mapPost: ({ postData, options }: {
2
+ postData: beehiivPostDataObject;
3
+ options?: any;
4
+ }) => mappedDataObject;
5
+ declare const mapPostsTasks: (options: any, ctx: any) => Promise<any>;
6
+ export { mapPost, mapPostsTasks };
@@ -0,0 +1,94 @@
1
+ // import fsUtils from '@tryghost/mg-fs-utils';
2
+ import { slugify } from '@tryghost/string';
3
+ import { processHTML, removeDuplicateFeatureImage } from './process.js';
4
+ const mapPost = ({ postData, options }) => {
5
+ const mappedData = {
6
+ url: postData.web_url,
7
+ data: {
8
+ comment_id: postData.id,
9
+ slug: postData.slug,
10
+ published_at: new Date(postData.publish_date * 1000),
11
+ updated_at: new Date(postData.publish_date * 1000),
12
+ created_at: new Date(postData.created * 1000),
13
+ title: postData.title,
14
+ type: 'post',
15
+ html: postData.content.premium.web,
16
+ status: (postData.status === 'confirmed') ? 'published' : 'draft',
17
+ custom_excerpt: postData.subtitle ?? null,
18
+ visibility: (postData.audience === 'premium') ? 'paid' : 'public',
19
+ authors: [],
20
+ tags: []
21
+ }
22
+ };
23
+ if (postData.thumbnail_url) {
24
+ mappedData.data.feature_image = postData.thumbnail_url;
25
+ }
26
+ if (postData.meta_default_title) {
27
+ mappedData.data.og_title = postData.meta_default_title;
28
+ }
29
+ if (postData.meta_default_description) {
30
+ mappedData.data.og_description = postData.meta_default_description;
31
+ }
32
+ mappedData.data.html = processHTML({
33
+ post: mappedData,
34
+ options
35
+ });
36
+ if (mappedData.data.feature_image) {
37
+ mappedData.data.html = removeDuplicateFeatureImage({
38
+ html: mappedData.data.html,
39
+ featureSrc: mappedData.data.feature_image
40
+ });
41
+ }
42
+ postData.authors.forEach((author) => {
43
+ const authorSlug = slugify(author);
44
+ mappedData.data.authors.push({
45
+ url: `migrator-added-author-${authorSlug}`,
46
+ data: {
47
+ slug: authorSlug,
48
+ name: author,
49
+ email: `${authorSlug}@example.com`
50
+ }
51
+ });
52
+ });
53
+ postData.content_tags.forEach((tag) => {
54
+ const tagSlug = slugify(tag);
55
+ mappedData.data.tags.push({
56
+ url: `migrator-added-tag-${tagSlug}`,
57
+ data: {
58
+ slug: tagSlug,
59
+ name: tag
60
+ }
61
+ });
62
+ });
63
+ mappedData.data.tags.push({
64
+ url: 'migrator-added-tag-hash-beehiiv',
65
+ data: {
66
+ slug: 'hash-beehiiv',
67
+ name: '#beehiiv'
68
+ }
69
+ });
70
+ return mappedData;
71
+ };
72
+ const mapPostsTasks = async (options, ctx) => {
73
+ let tasks = [];
74
+ ctx.result.posts.forEach((postData, index) => {
75
+ tasks.push({
76
+ title: `Mapping post: ${postData.title}`,
77
+ task: async (_, task) => {
78
+ try {
79
+ const mappedPost = mapPost({ postData, options });
80
+ ctx.result.posts[index] = mappedPost;
81
+ }
82
+ catch (error) {
83
+ /* c8 ignore next */
84
+ const errorMessage = error instanceof Error ? error.message : String(error);
85
+ task.output = errorMessage;
86
+ throw error;
87
+ }
88
+ }
89
+ });
90
+ });
91
+ return tasks;
92
+ };
93
+ export { mapPost, mapPostsTasks };
94
+ //# sourceMappingURL=mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.js","sourceRoot":"","sources":["../../src/lib/mapper.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,WAAW,EAAE,2BAA2B,EAAC,MAAM,cAAc,CAAC;AAEtE,MAAM,OAAO,GAAG,CAAC,EAAC,QAAQ,EAAE,OAAO,EAAmD,EAAE,EAAE;IACtF,MAAM,UAAU,GAAqB;QACjC,GAAG,EAAE,QAAQ,CAAC,OAAO;QACrB,IAAI,EAAE;YACF,UAAU,EAAE,QAAQ,CAAC,EAAE;YACvB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,YAAY,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,GAAG,IAAI,CAAC;YACpD,UAAU,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,GAAG,IAAI,CAAC;YAClD,UAAU,EAAE,IA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,IAAS,EAAE,EAAE;gBAC9B,IAAI,CAAC;oBACD,MAAM,UAAU,GAAG,OAAO,CAAC,EAAC,QAAQ,EAAE,OAAO,EAAC,CAAC,CAAC;oBAChD,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC;gBACzC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,oBAAoB;oBACpB,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC5E,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;oBAC3B,MAAM,KAAK,CAAC;gBAChB,CAAC;YACL,CAAC;SACJ,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EACH,OAAO,EACP,aAAa,EAChB,CAAC"}
@@ -0,0 +1,11 @@
1
+ declare const getYouTubeID: (url: string) => string;
2
+ declare const isURL: (urlString: string | undefined) => boolean;
3
+ declare const processHTML: ({ post, options }: {
4
+ post?: mappedDataObject;
5
+ options?: any;
6
+ }) => string;
7
+ declare const removeDuplicateFeatureImage: ({ html, featureSrc }: {
8
+ html: string;
9
+ featureSrc: string;
10
+ }) => string;
11
+ export { getYouTubeID, isURL, processHTML, removeDuplicateFeatureImage };