@tryghost/mg-medium-export 0.27.8-0 → 0.28.0-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 +83 -10
- package/build/index.d.ts +7 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/lib/ingest.d.ts +22 -0
- package/build/lib/ingest.js +66 -0
- package/build/lib/ingest.js.map +1 -0
- package/build/lib/map.d.ts +23 -0
- package/build/lib/map.js +245 -0
- package/build/lib/map.js.map +1 -0
- package/build/lib/process-content.d.ts +21 -0
- package/{lib → build/lib}/process-content.js +14 -47
- package/build/lib/process-content.js.map +1 -0
- package/build/lib/process-post.d.ts +17 -0
- package/build/lib/process-post.js +176 -0
- package/build/lib/process-post.js.map +1 -0
- package/build/lib/process-profile.d.ts +6 -0
- package/{lib → build/lib}/process-profile.js +10 -14
- package/build/lib/process-profile.js.map +1 -0
- package/build/lib/types.d.ts +58 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/test/helpers.d.ts +39 -0
- package/build/test/helpers.js +78 -0
- package/build/test/helpers.js.map +1 -0
- package/build/test/ingest.test.d.ts +1 -0
- package/build/test/ingest.test.js +115 -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 +286 -0
- package/build/test/map.test.js.map +1 -0
- package/build/test/process-profile.test.d.ts +1 -0
- package/build/test/process-profile.test.js +70 -0
- package/build/test/process-profile.test.js.map +1 -0
- package/build/test/process.test.d.ts +1 -0
- package/build/test/process.test.js +505 -0
- package/build/test/process.test.js.map +1 -0
- package/package.json +22 -12
- package/index.js +0 -11
- package/lib/process-post.js +0 -182
- package/lib/process.js +0 -24
- package/lib/read-zip.js +0 -83
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ migrate medium --pathToZip /path/to/my-export.zip
|
|
|
33
33
|
It's possible to pass more options, in order to achieve a better migration file for Ghost:
|
|
34
34
|
|
|
35
35
|
- **`--pathToZip`** (required)
|
|
36
|
-
- Path to a zip file
|
|
36
|
+
- Path to a zip file, or a folder of zip files
|
|
37
37
|
- string - default: `null`
|
|
38
38
|
- **`-V` `--verbose`**
|
|
39
39
|
- bool - default: `false`
|
|
@@ -41,9 +41,12 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
41
41
|
- **`--zip`**
|
|
42
42
|
- bool - default: `true`
|
|
43
43
|
- Create a zip file
|
|
44
|
-
-
|
|
44
|
+
- **`--report`**
|
|
45
|
+
- Write a `.report.json` migration report beside the import, or a `.failed-report.json` if the run fails
|
|
46
|
+
- bool - default: `false`
|
|
47
|
+
- **`--scrape`**
|
|
45
48
|
- Configure scraping tasks
|
|
46
|
-
- string - default: `all`
|
|
49
|
+
- string - default: `all`
|
|
47
50
|
- Choices: `all`, `web`, `assets`, `none`
|
|
48
51
|
- `all`: Scrape web metadata and download assets
|
|
49
52
|
- `web`: Only scrape metadata from web pages
|
|
@@ -55,18 +58,33 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
55
58
|
- **`--addTag`**
|
|
56
59
|
- string - default: `null`
|
|
57
60
|
- Provide a tag name which should be added to every post in this migration (Wrap in single quotes if tag name has spaces `'Like This'`)
|
|
58
|
-
- **`--addPlatformTag`**
|
|
61
|
+
- **`--addPlatformTag`**
|
|
59
62
|
- Add #medium tag to migrated content
|
|
60
63
|
- bool - default: `true`
|
|
61
64
|
- **`--mediumAsCanonical`**
|
|
62
65
|
- bool - default: `false`
|
|
63
66
|
- Use medium article as canonical URL
|
|
64
|
-
- **`--
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
- **`--
|
|
67
|
+
- **`--rereadSource`**
|
|
68
|
+
- Read the export zip again, replacing the stored source while preserving downloaded assets
|
|
69
|
+
- bool - default: `false`
|
|
70
|
+
- **`--postsPerFile`**
|
|
71
|
+
- Maximum posts written per Ghost import JSON file
|
|
72
|
+
- number - default: `2000`
|
|
73
|
+
- **`--cache`**
|
|
68
74
|
- Persist local cache after migration is complete (Only if `--zip` is `true`)
|
|
69
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
|
|
84
|
+
- string - default: one based on the export's full path
|
|
85
|
+
- **`--ghostApiUrl`**, **`--ghostAdminKey`**
|
|
86
|
+
- Match authors to existing Ghost users by email
|
|
87
|
+
- string - default: `null`
|
|
70
88
|
|
|
71
89
|
A more complex migration command could look like this:
|
|
72
90
|
|
|
@@ -74,7 +92,62 @@ A more complex migration command could look like this:
|
|
|
74
92
|
migrate medium --pathToZip /path/to/my-export.zip --email example.com
|
|
75
93
|
```
|
|
76
94
|
|
|
77
|
-
This will process all posts from the zip file, and
|
|
95
|
+
This will process all posts from the zip file, and authors without an email address in the export will have one ending in 'example.com'
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## Output
|
|
99
|
+
|
|
100
|
+
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 files, skipped posts, field changes, slug changes and optional scraping failures. Posts without a Medium post ID or with an invalid publish date, and a second file for a Medium post already imported, are skipped and reported. When every post is invalid, or the run fails, `--report` writes a `.failed-report.json` instead. An export without posts succeeds.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Source storage
|
|
104
|
+
|
|
105
|
+
The first run stores the export in an `mg-context` SQLite database in the workspace; later runs map the stored export again without reading the zip, even if it has moved. Use `--rereadSource` to read it again. Without `--cacheName`, the workspace is keyed by the export's full path, so exports that share a file name do not share stored data.
|
|
106
|
+
|
|
107
|
+
Each zip's `profile/profile.html` is stored as a `profile` record keyed by the zip's name, and each `posts/*.html` file as a `post` record keyed by its path, such as `posts/2022-12-11_Full-Test-6d912ac65341.html`. A folder's zips are read in name order, one entry at a time, and each may hold its files inside a single top-level directory. A post path found in two zips keeps its first record and reports a `source:conflict`. Other files in the export are not read.
|
|
108
|
+
|
|
109
|
+
Every option applies when the stored records are mapped, so changing a tag, canonical URL or email option needs no new read. Ghost IDs derive from the Medium post ID, tag slug or author handle, so they stay the same across runs. Drafts, and posts without a publish date, are dated when the export was read, so their dates also stay the same across runs.
|
|
110
|
+
|
|
111
|
+
Authors are identified by their Medium handle. The export's profile supplies the name, email, profile image and Twitter handle of the posts whose author link has its handle, and writes the posts that name no author, such as drafts. With a folder of zips, those posts use the profile in their own zip, or the only profile when there is just one. Authors without an email get `<slug>@<--email domain>`, `example.com` by default.
|
|
112
|
+
|
|
113
|
+
Web scraping happens after mapping. Each post with a canonical Medium URL (drafts have none) is scraped; its metadata, its tags (placed before internal `#` tags) and, for an author without one, the author's profile image are applied to the mapped post. Scraped pages are cached in the workspace.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## Programmatic API
|
|
117
|
+
|
|
118
|
+
The package exports `parse`, `ingest`, `map` and `applyScrapedData` for use with `@tryghost/mg-context`. The caller owns the context, scraping, export and closure:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
import {MigrateContext} from '@tryghost/mg-context';
|
|
122
|
+
import {ingest, map} from '@tryghost/mg-medium-export';
|
|
123
|
+
|
|
124
|
+
const context = new MigrateContext({dbPath: './migration.sqlite'});
|
|
125
|
+
const rereadSource = process.argv.includes('--rereadSource');
|
|
126
|
+
await context.init();
|
|
127
|
+
try {
|
|
128
|
+
if (!context.sources.hasCompletedIngestion || rereadSource) {
|
|
129
|
+
await ingest('/path/to/export.zip', context, {replace: rereadSource});
|
|
130
|
+
}
|
|
131
|
+
const summary = await map({addTag: 'From Medium'}, context);
|
|
132
|
+
for await (const file of context.writeGhostJsonStream('./output', {filename: 'ghost-import'})) {
|
|
133
|
+
// Consume one file descriptor at a time.
|
|
134
|
+
}
|
|
135
|
+
await context.writeMigrationReport('./migration.report.json', summary);
|
|
136
|
+
} finally {
|
|
137
|
+
await context.close();
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- `ingest(pathToZip, context, {replace})` reads an export zip, or a folder of them, into `context.sources` inside `context.sources.ingest()`. Explicit `replace: true` is required when completed source data exists; a failed read keeps the previous data. A folder without zips, or an export without a profile or posts, is rejected.
|
|
142
|
+
- `parse(pathToZip)` yields the same records as `SourceRecordInput` values, one at a time, without storing them.
|
|
143
|
+
- `map(options, context, {ghostUsers?})` rebuilds mapped content and returns `{selected, imported, skipped}`. The options are the CLI's, with the CLI's defaults. `ghostUsers` may be an iterable or async iterable of existing Ghost users; an author whose email matches keeps that user's Ghost ID, slug and roles, and Ghost users' slugs are reserved for them.
|
|
144
|
+
- `applyScrapedData(post, scraped, context)` applies post-processed scrape results to a mapped post, as the CLI's scrape step does. The caller saves the post.
|
|
145
|
+
- `postUrl(html)` returns a post's canonical Medium URL from its export HTML, `mediumHandle(url)` the lower-case Medium username in a URL, `ghostId(kind, key)` the stable Ghost ID the mapping assigns, and `contentStats(pathToZip)` counts the export's posts and profiles.
|
|
146
|
+
- `processPost`, `processContent` and `processProfile` convert one export file's HTML.
|
|
147
|
+
|
|
148
|
+
The previous default export (`(pathToZip, options)`, which read every file into memory and returned arrays of posts and users) has been removed.
|
|
149
|
+
|
|
150
|
+
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-medium-my-export-1700000000000.zip`.
|
|
78
151
|
|
|
79
152
|
|
|
80
153
|
## Develop
|
|
@@ -97,7 +170,7 @@ pnpm dev medium --pathToZip /path/to/my-export.zip
|
|
|
97
170
|
|
|
98
171
|
## Test
|
|
99
172
|
|
|
100
|
-
- `pnpm test`
|
|
173
|
+
- `pnpm test:local` builds the package and runs its tests with 100% coverage
|
|
101
174
|
- Linting and formatting are run from the repo root (`pnpm lint`, `pnpm format`)
|
|
102
175
|
|
|
103
176
|
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { contentStats, ingest, parse } from './lib/ingest.js';
|
|
2
|
+
export { applyScrapedData, ghostId, map } from './lib/map.js';
|
|
3
|
+
export { default as processPost, mediumHandle, postUrl } from './lib/process-post.js';
|
|
4
|
+
export { default as processContent } from './lib/process-content.js';
|
|
5
|
+
export { default as processProfile } from './lib/process-profile.js';
|
|
6
|
+
export type { MappingServices, MappingSummary } from './lib/map.js';
|
|
7
|
+
export type { MediumOptions, MediumPost, MediumRelation, ScrapedData, ScrapedTag } from './lib/types.js';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { contentStats, ingest, parse } from './lib/ingest.js';
|
|
2
|
+
export { applyScrapedData, ghostId, map } from './lib/map.js';
|
|
3
|
+
export { default as processPost, mediumHandle, postUrl } from './lib/process-post.js';
|
|
4
|
+
export { default as processContent } from './lib/process-content.js';
|
|
5
|
+
export { default as processProfile } from './lib/process-profile.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,GAAG,EAAC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,OAAO,IAAI,WAAW,EAAE,YAAY,EAAE,OAAO,EAAC,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MigrateContext, SourceRecordInput } from '@tryghost/mg-context';
|
|
2
|
+
/** Count the posts and profiles in a Medium export zip, or a directory of them, without reading them. */
|
|
3
|
+
export declare function contentStats(pathToZip: string): Promise<{
|
|
4
|
+
posts: number;
|
|
5
|
+
users: number;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Yield the export's originals one at a time without storing them: each zip's `profile/profile.html` as a `profile`
|
|
9
|
+
* record keyed by the zip's name, and each `posts/*.html` file as a `post` record keyed by its `posts/` path, without
|
|
10
|
+
* any directory the export is inside.
|
|
11
|
+
* `pathToZip` may be a directory of export zips, which are read in name order. Rejects when no zip holds a profile
|
|
12
|
+
* or a post.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parse(pathToZip: string): AsyncGenerator<SourceRecordInput>;
|
|
15
|
+
/**
|
|
16
|
+
* Read a Medium export zip, or a directory of them, into `context.sources`. A post path that appears in two zips
|
|
17
|
+
* keeps its first record, and a differing duplicate is reported as a `source:conflict`. Explicit `replace: true`
|
|
18
|
+
* is required when completed source data exists; a failed read keeps the previous data.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ingest(pathToZip: string, context: MigrateContext, { replace }?: {
|
|
21
|
+
replace?: boolean;
|
|
22
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import fsUtils from '@tryghost/mg-fs-utils';
|
|
3
|
+
// A Medium export holds `profile/profile.html` and `posts/*.html`, among files the migration does not use. Entries
|
|
4
|
+
// are matched by their full path: `zip.entries()` drops a directory that holds every entry from names, which for a
|
|
5
|
+
// zip of only `posts/` would drop `posts/` itself.
|
|
6
|
+
const PROFILE = /(?:^|\/)profile\/profile\.html$/;
|
|
7
|
+
const POST = /(?:^|\/)(posts\/[^/]+\.html)$/;
|
|
8
|
+
const isContent = (entry) => !entry.isDirectory && (PROFILE.test(entry.path) || POST.test(entry.path));
|
|
9
|
+
/** The export zips to read: `pathToZip` itself, or the `*.zip` files in a directory, in name order. */
|
|
10
|
+
async function exportFiles(pathToZip) {
|
|
11
|
+
const files = await fsUtils.listInputFiles(pathToZip, '*.zip');
|
|
12
|
+
if (!files.length) {
|
|
13
|
+
throw new Error(`No zip files found in ${resolve(pathToZip)}`);
|
|
14
|
+
}
|
|
15
|
+
return files;
|
|
16
|
+
}
|
|
17
|
+
/** Count the posts and profiles in a Medium export zip, or a directory of them, without reading them. */
|
|
18
|
+
export async function contentStats(pathToZip) {
|
|
19
|
+
const stats = { posts: 0, users: 0 };
|
|
20
|
+
for (const file of await exportFiles(pathToZip)) {
|
|
21
|
+
for await (const entry of fsUtils.zip.entries(file.path, { filter: isContent })) {
|
|
22
|
+
stats[PROFILE.test(entry.path) ? 'users' : 'posts'] += 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return stats;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Yield the export's originals one at a time without storing them: each zip's `profile/profile.html` as a `profile`
|
|
29
|
+
* record keyed by the zip's name, and each `posts/*.html` file as a `post` record keyed by its `posts/` path, without
|
|
30
|
+
* any directory the export is inside.
|
|
31
|
+
* `pathToZip` may be a directory of export zips, which are read in name order. Rejects when no zip holds a profile
|
|
32
|
+
* or a post.
|
|
33
|
+
*/
|
|
34
|
+
export async function* parse(pathToZip) {
|
|
35
|
+
let found = false;
|
|
36
|
+
for (const file of await exportFiles(pathToZip)) {
|
|
37
|
+
for await (const entry of fsUtils.zip.entries(file.path, { filter: isContent })) {
|
|
38
|
+
found = true;
|
|
39
|
+
const profile = PROFILE.test(entry.path);
|
|
40
|
+
yield {
|
|
41
|
+
kind: profile ? 'profile' : 'post',
|
|
42
|
+
key: profile ? file.name : entry.path.match(POST)[1],
|
|
43
|
+
content: (await entry.read()).toString('utf8'),
|
|
44
|
+
format: 'html',
|
|
45
|
+
metadata: { file: file.name, path: entry.path }
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!found) {
|
|
50
|
+
throw new Error(`${pathToZip}: No Medium profile or posts found in the export`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Read a Medium export zip, or a directory of them, into `context.sources`. A post path that appears in two zips
|
|
55
|
+
* keeps its first record, and a differing duplicate is reported as a `source:conflict`. Explicit `replace: true`
|
|
56
|
+
* is required when completed source data exists; a failed read keeps the previous data.
|
|
57
|
+
*/
|
|
58
|
+
export async function ingest(pathToZip, context, { replace = false } = {}) {
|
|
59
|
+
const files = (await exportFiles(pathToZip)).map(file => file.name);
|
|
60
|
+
await context.sources.ingest({ replace, metadata: { adapter: 'medium', files } }, async (stage) => {
|
|
61
|
+
for await (const record of parse(pathToZip)) {
|
|
62
|
+
stage.reconcile(record);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=ingest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../src/lib/ingest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAQ5C,mHAAmH;AACnH,mHAAmH;AACnH,mDAAmD;AACnD,MAAM,OAAO,GAAG,iCAAiC,CAAC;AAClD,MAAM,IAAI,GAAG,+BAA+B,CAAC;AAC7C,MAAM,SAAS,GAAG,CAAC,KAA2C,EAAE,EAAE,CAC9D,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAE9E,uGAAuG;AACvG,KAAK,UAAU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AC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { MediumOptions, ScrapedData } from './types.js';
|
|
5
|
+
export type { MappingSummary };
|
|
6
|
+
export interface MappingServices {
|
|
7
|
+
/** Existing Ghost users; an author with a matching email keeps that user's ID, slug and roles. */
|
|
8
|
+
ghostUsers?: Iterable<GhostUser> | AsyncIterable<GhostUser>;
|
|
9
|
+
}
|
|
10
|
+
/** A stable Ghost ID for a Medium post ID, tag slug or author key. */
|
|
11
|
+
export declare function ghostId(kind: string, key: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Rebuild posts, tags and authors from the stored export. Every option applies here, so changing one needs no new
|
|
14
|
+
* read of the export. Posts without a Medium post ID or with an invalid publish date, and a second file for the
|
|
15
|
+
* same Medium post, are skipped with a `record:skipped` diagnostic.
|
|
16
|
+
*/
|
|
17
|
+
export declare function map(options: MediumOptions, context: MigrateContext, services?: MappingServices): Promise<MappingSummary>;
|
|
18
|
+
/**
|
|
19
|
+
* Apply a scraped post page to a mapped post: schema fields such as `meta_description` and `og_image`, the scraped
|
|
20
|
+
* tags (public tags before internal ones), and the author's profile image when the author has none. The caller
|
|
21
|
+
* saves the post, which saves its tags and authors.
|
|
22
|
+
*/
|
|
23
|
+
export declare function applyScrapedData(post: PostContext, scraped: ScrapedData, context: MigrateContext): void;
|
package/build/lib/map.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { PostContext, TagContext, AuthorContext, MappingState, RecordDataError, ghostId as coreGhostId } from '@tryghost/mg-context';
|
|
2
|
+
import { mergeUsersWithGhost } from '@tryghost/mg-ghost-authors';
|
|
3
|
+
import { slugify } from '@tryghost/string';
|
|
4
|
+
import { stringUtils } from '@tryghost/mg-utils';
|
|
5
|
+
import processPost, { mediumHandle } from './process-post.js';
|
|
6
|
+
import processProfile from './process-profile.js';
|
|
7
|
+
const ROLES = ['Contributor', 'Author', 'Editor', 'Administrator'];
|
|
8
|
+
const AUTHOR_FIELDS = ['name', 'slug', 'email', 'profile_image', 'twitter'];
|
|
9
|
+
/** The CLI's defaults, used for options the caller leaves undefined. */
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
addPlatformTag: true,
|
|
12
|
+
mediumAsCanonical: false
|
|
13
|
+
};
|
|
14
|
+
function resolveOptions(options) {
|
|
15
|
+
const resolved = { ...DEFAULTS };
|
|
16
|
+
for (const [key, value] of Object.entries(options)) {
|
|
17
|
+
if (value !== undefined) {
|
|
18
|
+
resolved[key] = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return resolved;
|
|
22
|
+
}
|
|
23
|
+
/** A stable Ghost ID for a Medium post ID, tag slug or author key. */
|
|
24
|
+
export function ghostId(kind, key) {
|
|
25
|
+
return coreGhostId('mg-medium-export:1', 'medium.com', kind, key);
|
|
26
|
+
}
|
|
27
|
+
/** A profile record's author, keyed by its Medium handle so the same person's posts share it. */
|
|
28
|
+
function profileAuthor(record) {
|
|
29
|
+
const { url, data } = processProfile({ html: record.content });
|
|
30
|
+
const handle = mediumHandle(url);
|
|
31
|
+
return {
|
|
32
|
+
key: handle ? `handle:${handle}` : `profile:${record.key}`,
|
|
33
|
+
url,
|
|
34
|
+
data: { ...data, slug: handle },
|
|
35
|
+
recordId: record.id
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A post's author: the export profile when the post's author link names the same Medium handle, otherwise the
|
|
40
|
+
* author link itself. A post without an author link, such as a draft, is written by the profile in its zip, or by
|
|
41
|
+
* the only profile in the export.
|
|
42
|
+
*/
|
|
43
|
+
function postAuthor(state, record, author) {
|
|
44
|
+
if (author) {
|
|
45
|
+
const handle = mediumHandle(author.url);
|
|
46
|
+
const profile = handle ? state.get('profile-handle', handle) : undefined;
|
|
47
|
+
return (profile ?? {
|
|
48
|
+
key: handle ? `handle:${handle}` : `name:${author.data.name}`,
|
|
49
|
+
url: author.url,
|
|
50
|
+
data: author.data
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return state.get('profile-file', String(record.metadata.file)) ?? state.get('profile-file', '');
|
|
54
|
+
}
|
|
55
|
+
function mappedAuthor(state, source, options) {
|
|
56
|
+
const context = state.context;
|
|
57
|
+
const binding = state.getBinding('author', source.key);
|
|
58
|
+
if (binding) {
|
|
59
|
+
return AuthorContext.fromRow(context.db.stmts.findAuthorById.get(binding));
|
|
60
|
+
}
|
|
61
|
+
let data = {};
|
|
62
|
+
for (const field of AUTHOR_FIELDS) {
|
|
63
|
+
if (source.data[field]) {
|
|
64
|
+
data[field] = source.data[field];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
data.name ||= data.slug ? stringUtils.startCase(data.slug) : 'Example User';
|
|
68
|
+
data.slug ||= slugify(data.name);
|
|
69
|
+
data.email ||= `${data.slug.slice(0, 50).replace(/-+$/, '')}@${options.email || 'example.com'}`;
|
|
70
|
+
data.roles = ['Contributor'];
|
|
71
|
+
const match = state.get('ghost-user', data.email.toLowerCase());
|
|
72
|
+
if (match) {
|
|
73
|
+
data = { ...mergeUsersWithGhost([{ url: '', data: data }], [match])[0].data };
|
|
74
|
+
}
|
|
75
|
+
const id = data.id || ghostId('author', source.key);
|
|
76
|
+
delete data.id;
|
|
77
|
+
if (data.roles.some((role) => !ROLES.includes(role))) {
|
|
78
|
+
context.recordDiagnostic('operation:warning', {
|
|
79
|
+
author: source.key,
|
|
80
|
+
reason: 'Unsupported author roles replaced by supported Ghost roles'
|
|
81
|
+
});
|
|
82
|
+
data.roles = data.roles.filter((role) => ROLES.includes(role));
|
|
83
|
+
if (!data.roles.length) {
|
|
84
|
+
data.roles = ['Contributor'];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
data.slug = state.uniqueSlug('author', data.slug, id);
|
|
88
|
+
const entity = new AuthorContext();
|
|
89
|
+
for (const [field, value] of Object.entries(data)) {
|
|
90
|
+
if (value !== undefined) {
|
|
91
|
+
entity.set(field, value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
entity.ghostId = id;
|
|
95
|
+
entity.save(context.db);
|
|
96
|
+
state.bind('author', source.key, entity.dbId);
|
|
97
|
+
if (source.recordId) {
|
|
98
|
+
context.sources.link(source.recordId, { type: 'author', id: entity.dbId });
|
|
99
|
+
}
|
|
100
|
+
if (source.url) {
|
|
101
|
+
context.addLink(stringUtils.cleanURL(source.url), `/author/${entity.get('slug')}/`);
|
|
102
|
+
}
|
|
103
|
+
return entity;
|
|
104
|
+
}
|
|
105
|
+
/** Medium tags are identified by slug, so tags that share a slug are one Ghost tag. */
|
|
106
|
+
function tagEntity(name, slug) {
|
|
107
|
+
slug ||= slugify(name);
|
|
108
|
+
if (name.startsWith('#') && !slug.startsWith('hash-')) {
|
|
109
|
+
slug = `hash-${slug}`;
|
|
110
|
+
}
|
|
111
|
+
const tag = new TagContext({ name, slug });
|
|
112
|
+
tag.ghostId = ghostId('tag', slug);
|
|
113
|
+
return tag;
|
|
114
|
+
}
|
|
115
|
+
/** Public tags first, then internal `#` tags, each in their existing order. */
|
|
116
|
+
function sortTags(post) {
|
|
117
|
+
post.setTagOrder(tags => [...tags].sort((a, b) => Number(a.data.name.startsWith('#')) - Number(b.data.name.startsWith('#'))));
|
|
118
|
+
}
|
|
119
|
+
/** Add a tag to a post, mapping its Medium tag page to the Ghost tag page. */
|
|
120
|
+
function addTag(context, post, name, slug, url) {
|
|
121
|
+
const tag = tagEntity(name, slug);
|
|
122
|
+
tag.save(context.db);
|
|
123
|
+
post.addTag(tag);
|
|
124
|
+
if (url && /^https?:\/\//.test(url)) {
|
|
125
|
+
context.addLink(stringUtils.cleanURL(url), `/tag/${tag.get('slug')}/`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Rebuild posts, tags and authors from the stored export. Every option applies here, so changing one needs no new
|
|
130
|
+
* read of the export. Posts without a Medium post ID or with an invalid publish date, and a second file for the
|
|
131
|
+
* same Medium post, are skipped with a `record:skipped` diagnostic.
|
|
132
|
+
*/
|
|
133
|
+
export async function map(options, context, services = {}) {
|
|
134
|
+
if (!context.sources.hasCompletedIngestion) {
|
|
135
|
+
throw new Error('Ingest a complete Medium export before mapping.');
|
|
136
|
+
}
|
|
137
|
+
const resolved = resolveOptions(options);
|
|
138
|
+
// Drafts and posts without a publish date are dated when the export was read, so remapping keeps their dates.
|
|
139
|
+
const readAt = new Date(context.sources.currentIngestion.completedAt);
|
|
140
|
+
const state = new MappingState(context, 'mg-medium-export');
|
|
141
|
+
return context.rebuildMappedContent(async () => {
|
|
142
|
+
for await (const user of services.ghostUsers ?? []) {
|
|
143
|
+
state.reserveSlug('author', user.slug, user.id);
|
|
144
|
+
if (user.email) {
|
|
145
|
+
state.set('ghost-user', user.email.toLowerCase(), user);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Each zip's profile authors the posts in that zip that name no author; the export's only profile, if there
|
|
149
|
+
// is just one, authors those in other zips. A profile also describes posts whose author has its handle.
|
|
150
|
+
const profiles = [];
|
|
151
|
+
for await (const record of context.sources.records({ kind: 'profile' })) {
|
|
152
|
+
const source = profileAuthor(record);
|
|
153
|
+
profiles.push(source);
|
|
154
|
+
state.set('profile-file', record.key, source);
|
|
155
|
+
if (source.key.startsWith('handle:') && !state.get('profile-handle', source.key.slice(7))) {
|
|
156
|
+
state.set('profile-handle', source.key.slice(7), source);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (profiles.length === 1) {
|
|
160
|
+
state.set('profile-file', '', profiles[0]);
|
|
161
|
+
}
|
|
162
|
+
return context.mapRecords(context.sources.records({ kind: 'post' }), async (record) => {
|
|
163
|
+
const item = processPost({ name: record.key, html: record.content, options: resolved, date: readAt });
|
|
164
|
+
const mediumId = item.data.comment_id;
|
|
165
|
+
const earlier = state.get('post-id', mediumId);
|
|
166
|
+
if (earlier) {
|
|
167
|
+
throw new RecordDataError(`${earlier} is the same Medium post (${mediumId}) and is imported instead`);
|
|
168
|
+
}
|
|
169
|
+
state.set('post-id', mediumId, record.key);
|
|
170
|
+
const post = new PostContext({ lookupKey: record.key });
|
|
171
|
+
post.ghostId = ghostId('post', mediumId);
|
|
172
|
+
post.set('title', item.data.title || '(Untitled)');
|
|
173
|
+
post.set('slug', item.data.slug || mediumId);
|
|
174
|
+
post.set('custom_excerpt', item.data.custom_excerpt || null);
|
|
175
|
+
post.set('status', item.data.status);
|
|
176
|
+
post.set('created_at', item.data.created_at);
|
|
177
|
+
post.set('updated_at', item.data.updated_at);
|
|
178
|
+
post.set('published_at', item.data.published_at ?? null);
|
|
179
|
+
post.set('comment_id', mediumId);
|
|
180
|
+
post.set('html', item.data.html);
|
|
181
|
+
for (const field of ['feature_image', 'feature_image_alt', 'feature_image_caption', 'canonical_url']) {
|
|
182
|
+
const value = item.data[field];
|
|
183
|
+
if (value) {
|
|
184
|
+
post.set(field, value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const author = postAuthor(state, record, item.data.author);
|
|
188
|
+
if (author) {
|
|
189
|
+
const entity = mappedAuthor(state, author, resolved);
|
|
190
|
+
post.addAuthor(entity);
|
|
191
|
+
context.sources.link(record.id, { type: 'author', id: entity.dbId });
|
|
192
|
+
}
|
|
193
|
+
for (const tag of item.data.tags) {
|
|
194
|
+
const name = tag.data.name.trim();
|
|
195
|
+
if (name) {
|
|
196
|
+
addTag(context, post, name, tag.data.slug, tag.url);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
sortTags(post);
|
|
200
|
+
post.save(context.db);
|
|
201
|
+
for (const tag of post.data.tags) {
|
|
202
|
+
context.sources.link(record.id, { type: 'tag', id: tag.dbId });
|
|
203
|
+
}
|
|
204
|
+
context.sources.link(record.id, { type: 'post', id: post.dbId });
|
|
205
|
+
for (const url of [item.url, `https://medium.com/p/${mediumId}`]) {
|
|
206
|
+
if (url) {
|
|
207
|
+
context.addLink(stringUtils.cleanURL(url), `/${post.get('slug')}/`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Apply a scraped post page to a mapped post: schema fields such as `meta_description` and `og_image`, the scraped
|
|
215
|
+
* tags (public tags before internal ones), and the author's profile image when the author has none. The caller
|
|
216
|
+
* saves the post, which saves its tags and authors.
|
|
217
|
+
*/
|
|
218
|
+
export function applyScrapedData(post, scraped, context) {
|
|
219
|
+
for (const [field, value] of Object.entries(scraped)) {
|
|
220
|
+
if (field !== 'tags' &&
|
|
221
|
+
field !== 'author' &&
|
|
222
|
+
field in post.schema.shape &&
|
|
223
|
+
value !== null &&
|
|
224
|
+
value !== undefined &&
|
|
225
|
+
value !== '') {
|
|
226
|
+
post.set(field, value);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let tagged = false;
|
|
230
|
+
for (const tag of scraped.tags ?? []) {
|
|
231
|
+
const name = (tag.name ?? '').trim();
|
|
232
|
+
if (name) {
|
|
233
|
+
addTag(context, post, name, tag.slug, tag.url);
|
|
234
|
+
tagged = true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (tagged) {
|
|
238
|
+
sortTags(post);
|
|
239
|
+
}
|
|
240
|
+
const [author] = post.data.authors;
|
|
241
|
+
if (scraped.author?.profile_image && author && !author.get('profile_image')) {
|
|
242
|
+
author.set('profile_image', scraped.author.profile_image);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/lib/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,WAAW,EACX,UAAU,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,OAAO,IAAI,WAAW,EAC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CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;IACD,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,IAAI,EAAE,CAAC;YACP,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YAC/C,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;IACL,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACT,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAA0B,CAAC;IACtD,IAAI,OAAO,CAAC,MAAM,EAAE,aAAa,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;QAC1E,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAC9D,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MediumRelation } from './types.js';
|
|
2
|
+
/** The fields of a post that converting its content reads and updates. */
|
|
3
|
+
export interface ContentPost {
|
|
4
|
+
data: {
|
|
5
|
+
title: string;
|
|
6
|
+
custom_excerpt?: string;
|
|
7
|
+
status?: string;
|
|
8
|
+
tags?: MediumRelation[];
|
|
9
|
+
html?: string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export default _default;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a Medium post's body HTML to Ghost-friendly HTML, setting `post.data.html`. A short published post with
|
|
16
|
+
* one paragraph and no images is probably a comment, so it becomes a draft tagged `#Medium Possible Comment`.
|
|
17
|
+
*/
|
|
18
|
+
declare function _default<T extends ContentPost>({ html, post }: {
|
|
19
|
+
html: string;
|
|
20
|
+
post: T;
|
|
21
|
+
}): T;
|