@tryghost/mg-beehiiv 0.13.8-0 → 0.14.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/README.md +87 -5
- package/build/index.d.ts +7 -4
- package/build/index.js +4 -5
- package/build/index.js.map +1 -1
- package/build/lib/entities.d.ts +24 -0
- package/build/lib/entities.js +72 -0
- package/build/lib/entities.js.map +1 -0
- package/build/lib/ingest.d.ts +14 -0
- package/build/lib/ingest.js +33 -0
- package/build/lib/ingest.js.map +1 -0
- package/build/lib/map.d.ts +28 -0
- package/build/lib/map.js +153 -0
- package/build/lib/map.js.map +1 -0
- package/build/lib/process.d.ts +25 -6
- package/build/lib/process.js +262 -26
- package/build/lib/process.js.map +1 -1
- package/build/lib/types.d.ts +48 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/test/helpers.d.ts +15 -0
- package/build/test/helpers.js +70 -0
- package/build/test/helpers.js.map +1 -0
- package/build/test/ingest.test.js +78 -0
- package/build/test/ingest.test.js.map +1 -0
- package/build/test/map.test.d.ts +1 -0
- package/build/test/map.test.js +292 -0
- package/build/test/map.test.js.map +1 -0
- package/build/test/process.test.js +46 -54
- package/build/test/process.test.js.map +1 -1
- package/build/test/web-process.test.d.ts +1 -0
- package/build/test/web-process.test.js +328 -0
- package/build/test/web-process.test.js.map +1 -0
- package/package.json +8 -6
- package/build/lib/mapper.d.ts +0 -18
- package/build/lib/mapper.js +0 -123
- package/build/lib/mapper.js.map +0 -1
- package/build/test/mapper.test.js +0 -256
- package/build/test/mapper.test.js.map +0 -1
- /package/build/test/{mapper.test.d.ts → ingest.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -31,13 +31,13 @@ migrate beehiiv --posts /path/to/posts.csv --url https://example.com
|
|
|
31
31
|
A more complex command for a beehiiv migration looks like this:
|
|
32
32
|
|
|
33
33
|
```sh
|
|
34
|
-
migrate beehiiv --posts /path/to/posts.csv --url https://example.com --
|
|
34
|
+
migrate beehiiv --posts /path/to/posts.csv --url https://example.com --defaultAuthorName 'Author Name' --subscribeLink '/join'
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
38
38
|
|
|
39
39
|
- **`--posts`** (required)
|
|
40
|
-
- Path to
|
|
40
|
+
- Path to the posts CSV file
|
|
41
41
|
- string - default: `null`
|
|
42
42
|
- **`--url`** (required)
|
|
43
43
|
- Site URL
|
|
@@ -56,18 +56,100 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
56
56
|
- **`--subscribeLink`**
|
|
57
57
|
- Provide a path that existing `/subscribe` anchors will link to e.g. `/join-us` or `#/portal/signup` (`#` characters need to be escaped with a `\`)
|
|
58
58
|
- string - default: `#/portal/signup`
|
|
59
|
-
- **`--
|
|
60
|
-
-
|
|
61
|
-
- bool - default: `true`
|
|
59
|
+
- **`--comments`**
|
|
60
|
+
- Keep comment buttons
|
|
61
|
+
- bool - default: `true`
|
|
62
|
+
- **`--commentLink`**
|
|
63
|
+
- Provide a path that existing comment anchors will link to e.g. `#ghost-comments-root` (`#` characters need to be escaped with a `\`)
|
|
64
|
+
- string - default: `#ghost-comments-root`
|
|
65
|
+
- **`--wait_after_scrape`**
|
|
66
|
+
- Time in ms to wait after a URL is scraped
|
|
67
|
+
- number - default: `200`
|
|
68
|
+
- **`--rereadSource`**
|
|
69
|
+
- Read the posts CSV again, replacing the stored source while preserving downloaded assets
|
|
70
|
+
- bool - default: `false`
|
|
71
|
+
- **`--postsPerFile`**
|
|
72
|
+
- Maximum posts written per Ghost import JSON file
|
|
73
|
+
- number - default: `2000`
|
|
62
74
|
- **`--cache`**
|
|
63
75
|
- Persist local cache after migration is complete (Only if `--zip` is `true`)
|
|
64
76
|
- bool - default: `true`
|
|
77
|
+
- **`--tmpPath`**
|
|
78
|
+
- Specify the full path where the temporary files will be stored (Defaults a hidden tmp dir)
|
|
79
|
+
- string - default: `null`
|
|
80
|
+
- **`--outputPath`**
|
|
81
|
+
- Specify the full path where the final zip file will be saved to (Defaults to CWD)
|
|
82
|
+
- string - default: `null`
|
|
83
|
+
- **`--cacheName`**
|
|
84
|
+
- Provide a unique name for the cache directory
|
|
85
|
+
- string - default: one based on the CSV's full path
|
|
65
86
|
- **`-V` `--verbose`**
|
|
66
87
|
- Show verbose output
|
|
67
88
|
- bool - default: `false`
|
|
68
89
|
- **`--zip`**
|
|
69
90
|
- Create a zip file
|
|
70
91
|
- bool - default: `true`
|
|
92
|
+
- **`--report`**
|
|
93
|
+
- Write a `.report.json` migration report beside the import, or a `.failed-report.json` if the run fails
|
|
94
|
+
- bool - default: `false`
|
|
95
|
+
- **`--ghostApiUrl`**, **`--ghostAdminKey`**
|
|
96
|
+
- Match authors to existing Ghost users by email
|
|
97
|
+
- string - default: `null`
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
## Output
|
|
101
|
+
|
|
102
|
+
The import contains HTML; Ghost's importer converts it. `--fallBackHTMLCard` has been removed. A small migration writes `ghost-import.json`, and larger ones write `ghost-import-1.json`, `ghost-import-2.json` and so on, `--postsPerFile` posts each. With `--report`, a `.report.json` beside the ZIP (or in the workspace when `--zip false`) lists imported and skipped counts with diagnostics for duplicate rows, skipped posts, field changes, slug changes and optional scraping failures. Rows without an `id`, with an invalid `created_at` or with more than 500 tags are skipped and reported. When every selected post is invalid, or the run fails, `--report` writes a `.failed-report.json` instead. An empty CSV succeeds.
|
|
103
|
+
|
|
104
|
+
Each post gets its content tags, `#beehiiv`, and a `#beehiiv-visibility-<audience>` tag, with internal `#` tags last. Drafts (and archived posts) are given the default author. Published posts get their authors from their web page when it is scraped, or the default author when the page lists none; without web scraping they have no author, so Ghost assigns them to the importing staff user. Authors are identified by name, with a `<slug>@example.com` email that `--ghostApiUrl`/`--ghostAdminKey` can match to an existing Ghost user.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
## Source storage
|
|
108
|
+
|
|
109
|
+
The first run stores the CSV in an `mg-context` SQLite database in the workspace; later runs map the stored rows again without reading the CSV, even if it has moved. Use `--rereadSource` to read it again. Without `--cacheName`, the workspace is keyed by the CSV's full path, so CSVs that share a file name do not share stored data.
|
|
110
|
+
|
|
111
|
+
Each CSV row is stored as a `post` record keyed by its `id`, read one row at a time. An `id` that appears twice keeps its first row and reports a `source:conflict`.
|
|
112
|
+
|
|
113
|
+
Every option applies when the stored records are mapped, so changing `--url`, `--defaultAuthorName` or a content option needs no new read. Mapping follows the CSV's order. Ghost IDs derive from `--url` and the row `id`, tag slug or author slug, so they stay the same across runs. beehiiv writes `created_at` without a time zone; it is read as UTC.
|
|
114
|
+
|
|
115
|
+
Web scraping happens after mapping, for published posts with a URL. The scraped metadata and authors are applied to the mapped post. Scraped pages are cached in the workspace.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Programmatic API
|
|
119
|
+
|
|
120
|
+
The package exports `parse`, `ingest`, `map` and `applyScrapedData` for use with `@tryghost/mg-context`. The caller owns the context, scraping, export and closure:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import {MigrateContext} from '@tryghost/mg-context';
|
|
124
|
+
import {ingest, map} from '@tryghost/mg-beehiiv';
|
|
125
|
+
|
|
126
|
+
const context = new MigrateContext({dbPath: './migration.sqlite'});
|
|
127
|
+
const rereadSource = process.argv.includes('--rereadSource');
|
|
128
|
+
await context.init();
|
|
129
|
+
try {
|
|
130
|
+
if (!context.sources.hasCompletedIngestion || rereadSource) {
|
|
131
|
+
await ingest('/path/to/posts.csv', context, {replace: rereadSource});
|
|
132
|
+
}
|
|
133
|
+
const summary = await map({url: 'https://example.beehiiv.com', defaultAuthorName: 'Jane Doe'}, context);
|
|
134
|
+
for await (const file of context.writeGhostJsonStream('./output', {filename: 'ghost-import'})) {
|
|
135
|
+
// Consume one file descriptor at a time.
|
|
136
|
+
}
|
|
137
|
+
await context.writeMigrationReport('./migration.report.json', summary);
|
|
138
|
+
} finally {
|
|
139
|
+
await context.close();
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- `ingest(pathToCsv, context, {replace})` reads the CSV into `context.sources` inside `context.sources.ingest()`. Explicit `replace: true` is required when completed source data exists; a failed read keeps the previous data.
|
|
144
|
+
- `parse(pathToCsv)` yields the same records as `SourceRecordInput` values, one at a time, without storing them.
|
|
145
|
+
- `map(options, context, {ghostUsers?})` rebuilds mapped content and returns `{selected, imported, skipped}`. `options.url` is required; `defaultAuthorName`, `subscribeLink`, `comments` and `commentLink` are the CLI's options, without its defaults. `ghostUsers` may be an iterable or async iterable of existing Ghost users; an author whose email matches keeps that user's Ghost ID.
|
|
146
|
+
- `applyScrapedData(post, scraped, options)` applies post-processed scrape results (schema fields and `authors`) to a mapped post, as the CLI's scrape step does. The caller saves the post.
|
|
147
|
+
- `processHTML({html, title, options})` converts the email HTML in the CSV's `content_html` column, and `processWebHTML({html, url, options})` the web HTML that beehiiv's API returns. `removeDuplicateFeatureImage({html, featureSrc})` removes a leading image that repeats the feature image. `@tryghost/mg-beehiiv-api` uses these and the shared `namedAuthor`, `namedTag`, `publicFirst` and `rememberGhostUsers` helpers.
|
|
148
|
+
- `createSlug({url, title})` and `fullImageURL(path)` derive a post slug and an absolute beehiiv image URL.
|
|
149
|
+
|
|
150
|
+
The previous default export (`mapContent({options})`, which built an array of posts in memory) has been removed.
|
|
151
|
+
|
|
152
|
+
The CLI's programmatic `outputStorage.upload({body, fileName, size})` receives a Node readable stream as `body`, for the ZIP and, with `--report`, the report, and must consume it before resolving to the remote path. The uploaded ZIP is named like the local one, such as `gh-beehiiv-posts-1700000000000.zip`.
|
|
71
153
|
|
|
72
154
|
|
|
73
155
|
## Develop
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
export { ingest, parse } from './lib/ingest.js';
|
|
2
|
+
export { applyScrapedData, createSlug, fullImageURL, ghostId, map } from './lib/map.js';
|
|
3
|
+
export { getYouTubeID, isURL, processHTML, processWebHTML, removeDuplicateFeatureImage } from './lib/process.js';
|
|
4
|
+
export { namedAuthor, namedTag, publicFirst, rememberGhostUsers } from './lib/entities.js';
|
|
5
|
+
export type { IdFor } from './lib/entities.js';
|
|
6
|
+
export type { MappingServices, MappingSummary } from './lib/map.js';
|
|
7
|
+
export type { BeehiivOptions, BeehiivRow, ContentOptions, ScrapedData, ScrapedRelation } from './lib/types.js';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
export { ingest, parse } from './lib/ingest.js';
|
|
2
|
+
export { applyScrapedData, createSlug, fullImageURL, ghostId, map } from './lib/map.js';
|
|
3
|
+
export { getYouTubeID, isURL, processHTML, processWebHTML, removeDuplicateFeatureImage } from './lib/process.js';
|
|
4
|
+
export { namedAuthor, namedTag, publicFirst, rememberGhostUsers } from './lib/entities.js';
|
|
6
5
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,cAAc,CAAC;AACtF,OAAO,EAAC,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,2BAA2B,EAAC,MAAM,kBAAkB,CAAC;AAC/G,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AuthorContext, TagContext } from '@tryghost/mg-context';
|
|
2
|
+
import type { MappingState } from '@tryghost/mg-context';
|
|
3
|
+
import type { GhostUser } from '@tryghost/mg-ghost-authors';
|
|
4
|
+
/** The stable Ghost ID for an entity of `kind` with source `key`, scoped to one adapter and site. */
|
|
5
|
+
export type IdFor = (kind: 'post' | 'tag' | 'author', key: string) => string;
|
|
6
|
+
/** Reserve existing Ghost users' slugs and remember them by lowercase email, for `namedAuthor()` to match. */
|
|
7
|
+
export declare function rememberGhostUsers(state: MappingState, users?: Iterable<GhostUser> | AsyncIterable<GhostUser>): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* The saved author for a beehiiv author name. beehiiv names authors without an ID or email, so names with the
|
|
10
|
+
* same slug are one author, with a `<slug>@example.com` email. A Ghost user remembered with that email supplies
|
|
11
|
+
* its ID, name and slug; otherwise the slug is suffixed around Ghost users' slugs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function namedAuthor(state: MappingState, name: string, idFor: IdFor): AuthorContext;
|
|
14
|
+
/**
|
|
15
|
+
* A tag for a beehiiv tag name. beehiiv tags are identified by slug, so tags that share a slug are one Ghost tag.
|
|
16
|
+
* Names starting with `#` are internal tags, with a `hash-` slug.
|
|
17
|
+
*/
|
|
18
|
+
export declare function namedTag(name: string, idFor: IdFor, slug?: any): TagContext;
|
|
19
|
+
/** Order tags public first, then internal (`#`) tags, keeping their order otherwise. */
|
|
20
|
+
export declare function publicFirst<T extends {
|
|
21
|
+
data: {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
24
|
+
}>(tags: T[]): T[];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { AuthorContext, TagContext } from '@tryghost/mg-context';
|
|
2
|
+
import { mergeUsersWithGhost } from '@tryghost/mg-ghost-authors';
|
|
3
|
+
import { slugify } from '@tryghost/string';
|
|
4
|
+
const ROLES = ['Contributor', 'Author', 'Editor', 'Administrator'];
|
|
5
|
+
/** Reserve existing Ghost users' slugs and remember them by lowercase email, for `namedAuthor()` to match. */
|
|
6
|
+
export async function rememberGhostUsers(state, users = []) {
|
|
7
|
+
for await (const user of users) {
|
|
8
|
+
state.reserveSlug('author', user.slug, user.id);
|
|
9
|
+
if (user.email) {
|
|
10
|
+
state.set('ghost-user', user.email.toLowerCase(), user);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The saved author for a beehiiv author name. beehiiv names authors without an ID or email, so names with the
|
|
16
|
+
* same slug are one author, with a `<slug>@example.com` email. A Ghost user remembered with that email supplies
|
|
17
|
+
* its ID, name and slug; otherwise the slug is suffixed around Ghost users' slugs.
|
|
18
|
+
*/
|
|
19
|
+
export function namedAuthor(state, name, idFor) {
|
|
20
|
+
const context = state.context;
|
|
21
|
+
const slug = slugify(name) || 'author';
|
|
22
|
+
const key = `slug:${slug}`;
|
|
23
|
+
const binding = state.getBinding('author', key);
|
|
24
|
+
if (binding) {
|
|
25
|
+
return AuthorContext.fromRow(context.db.stmts.findAuthorById.get(binding));
|
|
26
|
+
}
|
|
27
|
+
let data = { name: name.trim(), slug, email: `${slug}@example.com` };
|
|
28
|
+
const match = state.get('ghost-user', data.email);
|
|
29
|
+
if (match) {
|
|
30
|
+
data = { ...mergeUsersWithGhost([{ url: '', data: data }], [match])[0].data };
|
|
31
|
+
}
|
|
32
|
+
const id = data.id || idFor('author', key);
|
|
33
|
+
delete data.id;
|
|
34
|
+
if (data.roles?.some((role) => !ROLES.includes(role))) {
|
|
35
|
+
context.recordDiagnostic('operation:warning', {
|
|
36
|
+
author: key,
|
|
37
|
+
reason: 'Unsupported author roles replaced by supported Ghost roles'
|
|
38
|
+
});
|
|
39
|
+
data.roles = data.roles.filter((role) => ROLES.includes(role));
|
|
40
|
+
if (!data.roles.length) {
|
|
41
|
+
data.roles = ['Contributor'];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
data.slug = state.uniqueSlug('author', data.slug, id);
|
|
45
|
+
const entity = new AuthorContext();
|
|
46
|
+
for (const [field, value] of Object.entries(data)) {
|
|
47
|
+
if (value !== undefined) {
|
|
48
|
+
entity.set(field, value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
entity.ghostId = id;
|
|
52
|
+
entity.save(context.db);
|
|
53
|
+
state.bind('author', key, entity.dbId);
|
|
54
|
+
return entity;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A tag for a beehiiv tag name. beehiiv tags are identified by slug, so tags that share a slug are one Ghost tag.
|
|
58
|
+
* Names starting with `#` are internal tags, with a `hash-` slug.
|
|
59
|
+
*/
|
|
60
|
+
export function namedTag(name, idFor, slug = slugify(name)) {
|
|
61
|
+
if (name.startsWith('#') && !slug.startsWith('hash-')) {
|
|
62
|
+
slug = `hash-${slug}`;
|
|
63
|
+
}
|
|
64
|
+
const tag = new TagContext({ name, slug });
|
|
65
|
+
tag.ghostId = idFor('tag', `slug:${slug}`);
|
|
66
|
+
return tag;
|
|
67
|
+
}
|
|
68
|
+
/** Order tags public first, then internal (`#`) tags, keeping their order otherwise. */
|
|
69
|
+
export function publicFirst(tags) {
|
|
70
|
+
return [...tags].sort((a, b) => Number(a.data.name.startsWith('#')) - Number(b.data.name.startsWith('#')));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/lib/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AAEzC,MAAM,KAAK,GAAG,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;AAKnE,8GAA8G;AAC9G,MAAM,CAAC,KAAK,UAAU,kBA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AK,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,IAAK,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAY,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IACrE,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,IAAI,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;IACzC,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC;AACf,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,WAAW,CAAmC,IAAS;IACnE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC/G,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MigrateContext, SourceRecordInput } from '@tryghost/mg-context';
|
|
2
|
+
/**
|
|
3
|
+
* Yield each row of a beehiiv posts CSV as a `post` record keyed by its `id`, one row at a time and without
|
|
4
|
+
* storing it. Rows without an `id` are yielded unkeyed.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parse(pathToCsv: string): AsyncGenerator<SourceRecordInput>;
|
|
7
|
+
/**
|
|
8
|
+
* Read a beehiiv posts CSV into `context.sources`. An `id` that appears twice keeps its first row, and a differing
|
|
9
|
+
* duplicate is reported as a `source:conflict`. Explicit `replace: true` is required when completed source data
|
|
10
|
+
* exists; a failed read keeps the previous data.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ingest(pathToCsv: string, context: MigrateContext, { replace }?: {
|
|
13
|
+
replace?: boolean;
|
|
14
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import fsUtils from '@tryghost/mg-fs-utils';
|
|
3
|
+
/**
|
|
4
|
+
* Yield each row of a beehiiv posts CSV as a `post` record keyed by its `id`, one row at a time and without
|
|
5
|
+
* storing it. Rows without an `id` are yielded unkeyed.
|
|
6
|
+
*/
|
|
7
|
+
export async function* parse(pathToCsv) {
|
|
8
|
+
const file = basename(pathToCsv);
|
|
9
|
+
let row = 0;
|
|
10
|
+
for await (const data of fsUtils.csv.streamRows(pathToCsv)) {
|
|
11
|
+
row += 1;
|
|
12
|
+
yield {
|
|
13
|
+
kind: 'post',
|
|
14
|
+
key: data.id || undefined,
|
|
15
|
+
content: JSON.stringify(data),
|
|
16
|
+
format: 'json',
|
|
17
|
+
metadata: { file, row }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Read a beehiiv posts CSV into `context.sources`. An `id` that appears twice keeps its first row, and a differing
|
|
23
|
+
* duplicate is reported as a `source:conflict`. Explicit `replace: true` is required when completed source data
|
|
24
|
+
* exists; a failed read keeps the previous data.
|
|
25
|
+
*/
|
|
26
|
+
export async function ingest(pathToCsv, context, { replace = false } = {}) {
|
|
27
|
+
await context.sources.ingest({ replace, metadata: { adapter: 'beehiiv', file: basename(pathToCsv) } }, async (stage) => {
|
|
28
|
+
for await (const record of parse(pathToCsv)) {
|
|
29
|
+
stage.reconcile(record);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=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,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MigrateContext, PostContext } from '@tryghost/mg-context';
|
|
2
|
+
import type { MappingSummary } from '@tryghost/mg-context';
|
|
3
|
+
import type { GhostUser } from '@tryghost/mg-ghost-authors';
|
|
4
|
+
import type { BeehiivOptions, ScrapedData } from './types.js';
|
|
5
|
+
export type { MappingSummary };
|
|
6
|
+
export interface MappingServices {
|
|
7
|
+
/** Existing Ghost users; an author whose placeholder email matches one keeps that user's ID. */
|
|
8
|
+
ghostUsers?: Iterable<GhostUser> | AsyncIterable<GhostUser>;
|
|
9
|
+
}
|
|
10
|
+
export declare function ghostId(site: string, kind: string, key: string): string;
|
|
11
|
+
/** The slug in a beehiiv post URL (`/p/<slug>`), or the title's slug when there is no URL. */
|
|
12
|
+
export declare function createSlug({ url, title }: {
|
|
13
|
+
url?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
}): string;
|
|
16
|
+
/** Make a beehiiv `uploads/` path an absolute image URL; other values are returned unchanged. */
|
|
17
|
+
export declare function fullImageURL(path: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Rebuild posts, tags and authors from the stored CSV rows. Content options apply here, so changing one needs no
|
|
20
|
+
* new read of the export. Drafts are given the default author; published posts get their authors when scraped.
|
|
21
|
+
* Rows without an `id` or with an invalid `created_at` are skipped with a `record:skipped` diagnostic.
|
|
22
|
+
*/
|
|
23
|
+
export declare function map(options: BeehiivOptions, context: MigrateContext, services?: MappingServices): Promise<MappingSummary>;
|
|
24
|
+
/**
|
|
25
|
+
* Apply a scraped post page to a mapped post: schema fields such as `meta_description` and `og_title`, and the
|
|
26
|
+
* page's authors, identified by slug as mapped authors are. The caller saves the post.
|
|
27
|
+
*/
|
|
28
|
+
export declare function applyScrapedData(post: PostContext, scraped: ScrapedData, options: BeehiivOptions): void;
|
package/build/lib/map.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { PostContext, AuthorContext, MappingState, RecordDataError, ghostId as coreGhostId } from '@tryghost/mg-context';
|
|
2
|
+
import { slugify } from '@tryghost/string';
|
|
3
|
+
import { dateUtils, stringUtils, urlUtils } from '@tryghost/mg-utils';
|
|
4
|
+
import { processHTML, removeDuplicateFeatureImage } from './process.js';
|
|
5
|
+
import { namedAuthor, namedTag, publicFirst, rememberGhostUsers } from './entities.js';
|
|
6
|
+
/** Ghost's limit on tags per post. */
|
|
7
|
+
const MAX_TAGS = 500;
|
|
8
|
+
export function ghostId(site, kind, key) {
|
|
9
|
+
return coreGhostId('mg-beehiiv:1', site, kind, key);
|
|
10
|
+
}
|
|
11
|
+
/** The site URL without trailing slashes. */
|
|
12
|
+
function siteUrl(value) {
|
|
13
|
+
if (!urlUtils.httpUrl(value)) {
|
|
14
|
+
throw new Error('beehiiv migrations need the site URL (--url) as an HTTP or HTTPS URL.');
|
|
15
|
+
}
|
|
16
|
+
return urlUtils.trimTrailingSlashes(value.trim());
|
|
17
|
+
}
|
|
18
|
+
/** The slug in a beehiiv post URL (`/p/<slug>`), or the title's slug when there is no URL. */
|
|
19
|
+
export function createSlug({ url, title }) {
|
|
20
|
+
if (url) {
|
|
21
|
+
return slugify(url.split('/p/')[1]);
|
|
22
|
+
}
|
|
23
|
+
return slugify(title);
|
|
24
|
+
}
|
|
25
|
+
/** Make a beehiiv `uploads/` path an absolute image URL; other values are returned unchanged. */
|
|
26
|
+
export function fullImageURL(path) {
|
|
27
|
+
if (path.startsWith('uploads/') || path.startsWith('/uploads/')) {
|
|
28
|
+
return `https://media.beehiiv.com/cdn-cgi/image/quality=100/${path.replace(/^\//, '')}`;
|
|
29
|
+
}
|
|
30
|
+
return path;
|
|
31
|
+
}
|
|
32
|
+
/** beehiiv writes zoneless timestamps such as `2023-01-18 21:25:27`; they are read as UTC. */
|
|
33
|
+
function rowDate(row) {
|
|
34
|
+
const date = dateUtils.parseDate(row.created_at);
|
|
35
|
+
if (!date) {
|
|
36
|
+
throw new RecordDataError('Invalid beehiiv post date');
|
|
37
|
+
}
|
|
38
|
+
return date;
|
|
39
|
+
}
|
|
40
|
+
/** The post's audience, from `audience` or the newer `web_audiences` column. */
|
|
41
|
+
function audience(row) {
|
|
42
|
+
return row.audience || row.web_audiences || '';
|
|
43
|
+
}
|
|
44
|
+
function visibility(row) {
|
|
45
|
+
const value = audience(row);
|
|
46
|
+
if (['premium', 'All premium subscribers', 'All paid subscribers'].includes(value)) {
|
|
47
|
+
return 'paid';
|
|
48
|
+
}
|
|
49
|
+
return value === 'both' ? 'members' : 'public';
|
|
50
|
+
}
|
|
51
|
+
/** The content tags, `#beehiiv`, and a `#beehiiv-visibility-<audience>` tag. */
|
|
52
|
+
function rowTags(row) {
|
|
53
|
+
const tags = (row.content_tags ?? '')
|
|
54
|
+
.split(';')
|
|
55
|
+
.map(name => name.trim())
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.map(name => ({ name, slug: slugify(name) }));
|
|
58
|
+
tags.push({ name: '#beehiiv', slug: 'hash-beehiiv' });
|
|
59
|
+
const value = audience(row);
|
|
60
|
+
if (value) {
|
|
61
|
+
const slug = slugify(value);
|
|
62
|
+
tags.push({ name: `#beehiiv-visibility-${slug}`, slug: `hash-beehiiv-visibility-${slug}` });
|
|
63
|
+
}
|
|
64
|
+
return tags;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Rebuild posts, tags and authors from the stored CSV rows. Content options apply here, so changing one needs no
|
|
68
|
+
* new read of the export. Drafts are given the default author; published posts get their authors when scraped.
|
|
69
|
+
* Rows without an `id` or with an invalid `created_at` are skipped with a `record:skipped` diagnostic.
|
|
70
|
+
*/
|
|
71
|
+
export async function map(options, context, services = {}) {
|
|
72
|
+
if (!context.sources.hasCompletedIngestion) {
|
|
73
|
+
throw new Error('Ingest a complete beehiiv posts CSV before mapping.');
|
|
74
|
+
}
|
|
75
|
+
const resolved = { ...options, url: siteUrl(options.url) };
|
|
76
|
+
const site = urlUtils.canonicalSite(resolved.url);
|
|
77
|
+
const idFor = (kind, key) => ghostId(site, kind, key);
|
|
78
|
+
const state = new MappingState(context, 'mg-beehiiv');
|
|
79
|
+
return context.rebuildMappedContent(async () => {
|
|
80
|
+
await rememberGhostUsers(state, services.ghostUsers);
|
|
81
|
+
return context.mapRecords(context.sources.records({ kind: 'post' }), async (record) => {
|
|
82
|
+
const row = JSON.parse(record.content);
|
|
83
|
+
if (!record.key) {
|
|
84
|
+
throw new RecordDataError('Row has no id');
|
|
85
|
+
}
|
|
86
|
+
const date = rowDate(row);
|
|
87
|
+
const tags = rowTags(row).map(({ name, slug }) => namedTag(name, idFor, slug));
|
|
88
|
+
if (tags.length > MAX_TAGS) {
|
|
89
|
+
throw new RecordDataError('Post exceeds Ghost tag relationship limit');
|
|
90
|
+
}
|
|
91
|
+
const post = new PostContext({ lookupKey: record.key });
|
|
92
|
+
post.ghostId = idFor('post', record.key);
|
|
93
|
+
post.set('title', row.web_title ?? '');
|
|
94
|
+
post.set('slug', createSlug({ url: row.url, title: row.web_title }) || slugify(record.key));
|
|
95
|
+
post.set('created_at', date);
|
|
96
|
+
post.set('updated_at', date);
|
|
97
|
+
post.set('published_at', date);
|
|
98
|
+
post.set('type', 'post');
|
|
99
|
+
post.set('status', row.status === 'confirmed' ? 'published' : 'draft');
|
|
100
|
+
post.set('custom_excerpt', row.web_subtitle || null);
|
|
101
|
+
post.set('visibility', visibility(row));
|
|
102
|
+
const featureImage = row.thumbnail_url ? fullImageURL(row.thumbnail_url) : null;
|
|
103
|
+
post.set('feature_image', featureImage);
|
|
104
|
+
let html = processHTML({ html: row.content_html ?? '', title: row.web_title, options: resolved });
|
|
105
|
+
if (featureImage) {
|
|
106
|
+
html = removeDuplicateFeatureImage({ html, featureSrc: featureImage });
|
|
107
|
+
}
|
|
108
|
+
post.set('html', html);
|
|
109
|
+
if (post.get('status') === 'draft') {
|
|
110
|
+
const author = namedAuthor(state, resolved.defaultAuthorName || 'Author', idFor);
|
|
111
|
+
post.addAuthor(author);
|
|
112
|
+
context.sources.link(record.id, { type: 'author', id: author.dbId });
|
|
113
|
+
}
|
|
114
|
+
for (const tag of publicFirst(tags)) {
|
|
115
|
+
tag.save(context.db);
|
|
116
|
+
post.addTag(tag);
|
|
117
|
+
context.sources.link(record.id, { type: 'tag', id: tag.dbId });
|
|
118
|
+
}
|
|
119
|
+
post.save(context.db);
|
|
120
|
+
context.sources.link(record.id, { type: 'post', id: post.dbId });
|
|
121
|
+
if (row.url) {
|
|
122
|
+
context.addLink(stringUtils.cleanURL(row.url), `/${post.get('slug')}/`);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Apply a scraped post page to a mapped post: schema fields such as `meta_description` and `og_title`, and the
|
|
129
|
+
* page's authors, identified by slug as mapped authors are. The caller saves the post.
|
|
130
|
+
*/
|
|
131
|
+
export function applyScrapedData(post, scraped, options) {
|
|
132
|
+
const site = urlUtils.canonicalSite(siteUrl(options.url));
|
|
133
|
+
for (const [field, value] of Object.entries(scraped)) {
|
|
134
|
+
if (field !== 'authors' &&
|
|
135
|
+
field in post.schema.shape &&
|
|
136
|
+
value !== null &&
|
|
137
|
+
value !== undefined &&
|
|
138
|
+
value !== '') {
|
|
139
|
+
post.set(field, value);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
for (const { data } of scraped.authors ?? []) {
|
|
143
|
+
const slug = data.slug || slugify(data.name) || 'author';
|
|
144
|
+
const author = new AuthorContext({
|
|
145
|
+
name: data.name,
|
|
146
|
+
slug,
|
|
147
|
+
email: data.email || `${slug}@example.com`
|
|
148
|
+
});
|
|
149
|
+
author.ghostId = ghostId(site, 'author', `slug:${slug}`);
|
|
150
|
+
post.addAuthor(author);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/lib/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,W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K,IAAI;YACd,KAAK,KAAK,SAAS;YACnB,KAAK,KAAK,EAAE,EACd,CAAC;YACC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;IACD,KAAK,MAAM,EAAC,IAAI,EAAC,IAAI,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QACzC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC;QACzD,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,GAAG,IAAI,cAAc;SAC7C,CAAC,CAAC;QACH,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;AACL,CAAC"}
|
package/build/lib/process.d.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
|
+
import type { ContentOptions } from './types.js';
|
|
1
2
|
declare const getYouTubeID: (videoUrl: string | null | undefined) => string;
|
|
2
|
-
declare const
|
|
3
|
+
declare const isURL: (urlString: string | undefined | null) => boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Convert the email HTML in a beehiiv CSV export's `content_html` column. Only the content inside
|
|
6
|
+
* `#content-blocks` is kept; email chrome, tracking and template variables are removed, and the result is
|
|
7
|
+
* sanitized to the elements Ghost imports. A heading containing `title` is removed as a duplicate title.
|
|
8
|
+
*/
|
|
9
|
+
declare const processHTML: ({ html, title, options }: {
|
|
3
10
|
html: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
title?: string;
|
|
12
|
+
options?: ContentOptions;
|
|
13
|
+
}) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Convert the web HTML that beehiiv's API returns in `content.premium.web`. Only the content inside
|
|
16
|
+
* `#content-blocks` is kept. `url` is the post's web URL; comment links on its origin are rewritten or removed.
|
|
17
|
+
*/
|
|
18
|
+
declare const processWebHTML: ({ html, url, options }: {
|
|
19
|
+
html?: string | null;
|
|
20
|
+
url?: string;
|
|
21
|
+
options?: ContentOptions;
|
|
22
|
+
}) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Remove the first element of `html` when it is, or holds, an image matching the feature image: the same
|
|
25
|
+
* beehiiv `/uploads/asset/` path, or the same URL once beehiiv's resizing parameters are normalized.
|
|
26
|
+
*/
|
|
8
27
|
declare const removeDuplicateFeatureImage: ({ html, featureSrc }: {
|
|
9
28
|
html: string;
|
|
10
29
|
featureSrc: string;
|
|
11
30
|
}) => string;
|
|
12
|
-
export { getYouTubeID, processHTML, removeDuplicateFeatureImage };
|
|
31
|
+
export { getYouTubeID, isURL, processHTML, processWebHTML, removeDuplicateFeatureImage };
|