@tryghost/mg-blogger 0.11.8-0 → 0.12.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 +84 -14
- package/build/index.d.ts +9 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/build/lib/fetch.d.ts +34 -0
- package/build/lib/fetch.js +89 -0
- package/build/lib/fetch.js.map +1 -0
- package/build/lib/ingest.d.ts +23 -0
- package/build/lib/ingest.js +33 -0
- package/build/lib/ingest.js.map +1 -0
- package/build/lib/map.d.ts +21 -0
- package/build/lib/map.js +173 -0
- package/build/lib/map.js.map +1 -0
- package/build/lib/process.d.ts +18 -0
- package/{lib → build/lib}/process.js +49 -254
- package/build/lib/process.js.map +1 -0
- package/build/lib/types.d.ts +31 -0
- package/build/lib/types.js +4 -0
- package/build/lib/types.js.map +1 -0
- package/build/test/fetch.test.d.ts +1 -0
- package/build/test/fetch.test.js +108 -0
- package/build/test/fetch.test.js.map +1 -0
- package/build/test/helpers.d.ts +20 -0
- package/build/test/helpers.js +72 -0
- package/build/test/helpers.js.map +1 -0
- package/build/test/ingest.test.d.ts +1 -0
- package/build/test/ingest.test.js +104 -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 +251 -0
- package/build/test/map.test.js.map +1 -0
- package/build/test/process.test.d.ts +1 -0
- package/build/test/process.test.js +214 -0
- package/build/test/process.test.js.map +1 -0
- package/package.json +26 -11
- package/index.js +0 -7
- package/lib/fetch.js +0 -82
package/README.md
CHANGED
|
@@ -38,16 +38,19 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
38
38
|
- API Key
|
|
39
39
|
- **`--blogID`** (required)
|
|
40
40
|
- array - default: `null`
|
|
41
|
-
- Comma separated list of
|
|
42
|
-
- **`-V` `--verbose`**
|
|
41
|
+
- Comma separated list of blog IDs
|
|
42
|
+
- **`-V` `--verbose`**
|
|
43
43
|
- Show verbose output
|
|
44
44
|
- bool - default: `false`
|
|
45
|
-
- **`--zip`**
|
|
45
|
+
- **`--zip`**
|
|
46
46
|
- Create a zip file
|
|
47
47
|
- bool - default: `true`
|
|
48
|
-
-
|
|
48
|
+
- **`--report`**
|
|
49
|
+
- Write a `.report.json` migration report beside the import, or a `.failed-report.json` if the run fails
|
|
50
|
+
- bool - default: `false`
|
|
51
|
+
- **`-s` `--scrape`**
|
|
49
52
|
- Configure scraping tasks
|
|
50
|
-
- string - default: `all`
|
|
53
|
+
- string - default: `all`
|
|
51
54
|
- Choices: `all`, `web`, `assets`, `none`
|
|
52
55
|
- `all`: Scrape web metadata and download assets
|
|
53
56
|
- `web`: Only scrape metadata from web pages
|
|
@@ -55,24 +58,91 @@ It's possible to pass more options, in order to achieve a better migration file
|
|
|
55
58
|
- `none`: Skip all scraping tasks
|
|
56
59
|
- **`--addTag`**
|
|
57
60
|
- string - default: `null`
|
|
58
|
-
- Provide a tag
|
|
59
|
-
- **`--firstImageAsFeatured`**
|
|
61
|
+
- Provide a tag name which should be added to every post in this migration
|
|
62
|
+
- **`--firstImageAsFeatured`**
|
|
60
63
|
- Use the first image as the post's feature_image
|
|
61
64
|
- bool - default: `true`
|
|
62
|
-
- **`--
|
|
63
|
-
-
|
|
64
|
-
- bool - default: `
|
|
65
|
-
- **`--
|
|
65
|
+
- **`--rereadSource`**
|
|
66
|
+
- Fetch every post from the API again, replacing the stored source while preserving downloaded assets
|
|
67
|
+
- bool - default: `false`
|
|
68
|
+
- **`--postsPerFile`**
|
|
69
|
+
- Maximum posts written per Ghost import JSON file
|
|
70
|
+
- number - default: `2000`
|
|
71
|
+
- **`--cache`**
|
|
66
72
|
- Persist local cache after migration is complete (Only if `--zip` is `true`)
|
|
67
73
|
- bool - default: `true`
|
|
74
|
+
- **`--tmpPath`**
|
|
75
|
+
- Specify the full path where the temporary files will be stored (Defaults a hidden tmp dir)
|
|
76
|
+
- string - default: `null`
|
|
77
|
+
- **`--outputPath`**
|
|
78
|
+
- Specify the full path where the final zip file will be saved to (Defaults to CWD)
|
|
79
|
+
- string - default: `null`
|
|
80
|
+
- **`--cacheName`**
|
|
81
|
+
- Provide a unique name for the cache directory
|
|
82
|
+
- string - default: one based on the blog IDs
|
|
83
|
+
- **`--ghostApiUrl`**, **`--ghostAdminKey`**
|
|
84
|
+
- Match authors to existing Ghost users by email
|
|
85
|
+
- string - default: `null`
|
|
68
86
|
|
|
69
87
|
A more complex migration command could look like this:
|
|
70
88
|
|
|
71
89
|
```sh
|
|
72
|
-
migrate blogger --apiKey abcd --blogID 1234,
|
|
90
|
+
migrate blogger --apiKey abcd --blogID 1234,5678 --addTag 'Blog Posts' --firstImageAsFeatured false
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
This will fetch posts from 2 blogs, add a 'Blog Posts' tag to each post, and keep each post's first image in its content.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## Output
|
|
97
|
+
|
|
98
|
+
The import contains HTML; Ghost's importer converts it, so `--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 repeated posts, skipped posts, field changes and slug changes. Posts without an ID or a valid date, 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 intentionally empty selection succeeds.
|
|
99
|
+
|
|
100
|
+
Each post is published with its slug taken from its Blogger URL, its labels as tags, then `--addTag`, `#blogger-site-<blogID>` and `#blogger`, with internal `#` tags last. Labels that share a slug are one tag. Authors are identified by their Blogger profile ID, so different accounts with the same display name become different Ghost users (`jane-doe`, `jane-doe-2`), each with a `<slug>@example.com` email that `--ghostApiUrl`/`--ghostAdminKey` can match to an existing Ghost user. Links between the migrated posts are rewritten to their Ghost URLs.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Source storage
|
|
104
|
+
|
|
105
|
+
The first run fetches every post of each blog, in the order the blog IDs are given, following the API's page tokens, and stores them in an `mg-context` SQLite database in the workspace; later runs map the stored posts again without calling the API. Use `--rereadSource` to fetch them again. Without `--cacheName`, the workspace is keyed by the blog IDs, so a different list of blogs gets its own workspace. The API key is never stored, and API pages are no longer cached as JSON files in the workspace.
|
|
106
|
+
|
|
107
|
+
Each post is stored as a `post` record keyed `post:id:<id>`, with the blog and page it was fetched from. A post returned twice while paging keeps its most recently updated version and reports a `source:conflict`.
|
|
108
|
+
|
|
109
|
+
`--blogID` narrows the fetch and is stored with the source data. Leaving a stored blog out applies when the posts are mapped, but adding a blog that was not fetched (possible with `--cacheName`) needs `--rereadSource`. `--addTag` and `--firstImageAsFeatured` apply when the stored posts are mapped, so changing them needs no new fetch. Ghost IDs derive from the blog and post IDs, the tag slug or the author's profile ID, so they stay the same across runs.
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## Programmatic API
|
|
113
|
+
|
|
114
|
+
The package exports `parse`, `ingest` and `map` for use with `@tryghost/mg-context`. The caller owns the context, export and closure:
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
import {MigrateContext} from '@tryghost/mg-context';
|
|
118
|
+
import {ingest, map} from '@tryghost/mg-blogger';
|
|
119
|
+
|
|
120
|
+
const context = new MigrateContext({dbPath: './migration.sqlite'});
|
|
121
|
+
const rereadSource = process.argv.includes('--rereadSource');
|
|
122
|
+
await context.init();
|
|
123
|
+
try {
|
|
124
|
+
if (!context.sources.hasCompletedIngestion || rereadSource) {
|
|
125
|
+
await ingest(['1234', '5678'], context, {apiKey: process.env.BLOGGER_API_KEY, replace: rereadSource});
|
|
126
|
+
}
|
|
127
|
+
const summary = await map({addTag: 'Blog Posts'}, context);
|
|
128
|
+
for await (const file of context.writeGhostJsonStream('./output', {filename: 'ghost-import'})) {
|
|
129
|
+
// Consume one file descriptor at a time.
|
|
130
|
+
}
|
|
131
|
+
await context.writeMigrationReport('./migration.report.json', summary);
|
|
132
|
+
} finally {
|
|
133
|
+
await context.close();
|
|
134
|
+
}
|
|
73
135
|
```
|
|
74
136
|
|
|
75
|
-
|
|
137
|
+
- `ingest(blogIDs, context, {apiKey, replace, requestDelay, onProgress})` fetches each blog's posts into `context.sources` inside `context.sources.ingest()`, waiting `requestDelay` milliseconds (default 500) before each request and calling `onProgress(title)` before each page. Explicit `replace: true` is required when completed source data exists; a failed fetch keeps the previous data. `sourceBlogs(context)` returns the stored blog IDs.
|
|
138
|
+
- `parse(blogIDs, {apiKey, requestDelay, onProgress})` yields the same records as `SourceRecordInput` values, one page at a time, without storing them.
|
|
139
|
+
- `tasks({apiKey, blogIDs, requestDelay})` is an async generator of page tasks. Blogger pages by token, so each page's task is yielded after the previous page has been fetched. A task's `task(ctx)` writes its page into `ctx.sourceIngestion`, and `records()` fetches it without storing.
|
|
140
|
+
- `map(options, context, {ghostUsers?})` rebuilds mapped content and returns `{selected, imported, skipped}`. `options` takes `blogID`, `addTag` and `firstImageAsFeatured` (default `true`, as in the CLI). `ghostUsers` may be an iterable or async iterable of existing Ghost users; an author whose email matches keeps that user's Ghost ID, name and slug.
|
|
141
|
+
- `processHTMLContent({postData, html, options})`, `cleanExcerpt`, `increaseImageSize` and `slugFromURL` are the HTML helpers `map()` uses.
|
|
142
|
+
|
|
143
|
+
The previous default export (`fetch.tasks` and `process.all`, which built an array of posts in memory) and `processPost`/`processPosts` have been removed.
|
|
144
|
+
|
|
145
|
+
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.
|
|
76
146
|
|
|
77
147
|
|
|
78
148
|
## Develop
|
|
@@ -95,7 +165,7 @@ pnpm dev blogger --apiKey abcd --blogID 1234
|
|
|
95
165
|
|
|
96
166
|
## Test
|
|
97
167
|
|
|
98
|
-
- `pnpm test` runs the package tests
|
|
168
|
+
- `pnpm test` runs the package tests with 100% coverage
|
|
99
169
|
- Linting and formatting are run from the repo root (`pnpm lint`, `pnpm format`)
|
|
100
170
|
|
|
101
171
|
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { postsURL, pageRecords, tasks } from './lib/fetch.js';
|
|
2
|
+
export type { FetchOptions, FetchTask, TaskContext } from './lib/fetch.js';
|
|
3
|
+
export { ingest, parse, sourceBlogs } from './lib/ingest.js';
|
|
4
|
+
export type { IngestOptions, ParseOptions } from './lib/ingest.js';
|
|
5
|
+
export { ghostId, map } from './lib/map.js';
|
|
6
|
+
export type { MappingServices, MappingSummary } from './lib/map.js';
|
|
7
|
+
export { cleanExcerpt, increaseImageSize, processHTMLContent, slugFromURL } from './lib/process.js';
|
|
8
|
+
export type { ProcessedContent, ProcessHTMLArgs } from './lib/process.js';
|
|
9
|
+
export type { BloggerOptions, BloggerPost } from './lib/types.js';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { postsURL, pageRecords, tasks } from './lib/fetch.js';
|
|
2
|
+
export { ingest, parse, sourceBlogs } from './lib/ingest.js';
|
|
3
|
+
export { ghostId, map } from './lib/map.js';
|
|
4
|
+
export { cleanExcerpt, increaseImageSize, processHTMLContent, slugFromURL } from './lib/process.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAC,OAAO,EAAE,GAAG,EAAC,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SourceIngestion, SourceRecordInput } from '@tryghost/mg-context';
|
|
2
|
+
import type { BloggerPost } from './types.js';
|
|
3
|
+
/** The blogs to fetch and the API key to fetch them with. */
|
|
4
|
+
export interface FetchOptions {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
blogIDs: string[];
|
|
7
|
+
/** Milliseconds to wait before each request, to stay under Blogger's rate limits. Defaults to 500. */
|
|
8
|
+
requestDelay?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TaskContext {
|
|
11
|
+
sourceIngestion?: SourceIngestion;
|
|
12
|
+
}
|
|
13
|
+
export interface FetchTask {
|
|
14
|
+
title: string;
|
|
15
|
+
blogID: string;
|
|
16
|
+
page: number;
|
|
17
|
+
/** Fetch this page's records without storing them. The page is requested once. */
|
|
18
|
+
records: () => Promise<SourceRecordInput[]>;
|
|
19
|
+
/** Fetch this page and write its records into `ctx.sourceIngestion`. */
|
|
20
|
+
task: (ctx: TaskContext) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/** The posts endpoint for one page of a blog. */
|
|
23
|
+
declare const postsURL: (blogID: string, apiKey: string, pageToken?: string) => string;
|
|
24
|
+
/** Source records for one page of posts, keyed `post:id:<id>`. */
|
|
25
|
+
declare const pageRecords: (blogID: string, posts: BloggerPost[], page: number) => SourceRecordInput[];
|
|
26
|
+
/** Keep the most recently updated version when paging returns a post twice. */
|
|
27
|
+
declare const writeRecords: (stage: SourceIngestion, records: SourceRecordInput[]) => void;
|
|
28
|
+
/**
|
|
29
|
+
* One task per page of each blog's posts, blogs in the given order and pages in API order. Blogger pages by token,
|
|
30
|
+
* so the next page's task is yielded only after the previous page has been fetched, by its task or by this
|
|
31
|
+
* generator. Each task writes its page into `ctx.sourceIngestion` as `post` records.
|
|
32
|
+
*/
|
|
33
|
+
declare function tasks(options: FetchOptions): AsyncGenerator<FetchTask>;
|
|
34
|
+
export { postsURL, pageRecords, tasks, writeRecords };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
|
+
import errors from '@tryghost/errors';
|
|
3
|
+
/** The posts endpoint for one page of a blog. */
|
|
4
|
+
const postsURL = (blogID, apiKey, pageToken) => {
|
|
5
|
+
const searchParams = new URLSearchParams({ key: apiKey });
|
|
6
|
+
if (pageToken) {
|
|
7
|
+
searchParams.set('pageToken', pageToken);
|
|
8
|
+
}
|
|
9
|
+
return `https://www.googleapis.com/blogger/v3/blogs/${encodeURIComponent(blogID)}/posts?${searchParams}`;
|
|
10
|
+
};
|
|
11
|
+
/** Source records for one page of posts, keyed `post:id:<id>`. */
|
|
12
|
+
const pageRecords = (blogID, posts, page) => posts.map(post => ({
|
|
13
|
+
kind: 'post',
|
|
14
|
+
key: post.id ? `post:id:${post.id}` : null,
|
|
15
|
+
content: JSON.stringify(post),
|
|
16
|
+
format: 'json',
|
|
17
|
+
metadata: { blog: blogID, page }
|
|
18
|
+
}));
|
|
19
|
+
/** Request one page. Errors never include the URL, which carries the API key. */
|
|
20
|
+
const fetchPage = async ({ apiKey, requestDelay = 500 }, blogID, page, pageToken) => {
|
|
21
|
+
await sleep(requestDelay);
|
|
22
|
+
let response;
|
|
23
|
+
let body;
|
|
24
|
+
try {
|
|
25
|
+
response = await fetch(postsURL(blogID, apiKey, pageToken));
|
|
26
|
+
body = await response.json();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
const status = response ? `: ${response.status} ${response.statusText}` : '';
|
|
30
|
+
throw new errors.InternalServerError({
|
|
31
|
+
message: `Failed to fetch Blogger content for blog ${blogID}${status}`,
|
|
32
|
+
error
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new errors.InternalServerError({
|
|
37
|
+
message: `Failed to fetch Blogger content for blog ${blogID}: ${response.status} ${body?.error?.message ?? response.statusText}`
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return { records: pageRecords(blogID, body.items ?? [], page), nextPageToken: body.nextPageToken || undefined };
|
|
41
|
+
};
|
|
42
|
+
/** Keep the most recently updated version when paging returns a post twice. */
|
|
43
|
+
const writeRecords = (stage, records) => {
|
|
44
|
+
for (const record of records) {
|
|
45
|
+
stage.reconcile(record, {
|
|
46
|
+
choose: (existing, incoming) => Date.parse(JSON.parse(incoming.content).updated) > Date.parse(JSON.parse(existing.content).updated)
|
|
47
|
+
? 'replace'
|
|
48
|
+
: 'keep'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const stageFor = (ctx) => {
|
|
53
|
+
if (!ctx.sourceIngestion) {
|
|
54
|
+
throw new errors.IncorrectUsageError({
|
|
55
|
+
message: 'mg-blogger fetch tasks write into ctx.sourceIngestion; run them inside context.sources.ingest()'
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return ctx.sourceIngestion;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* One task per page of each blog's posts, blogs in the given order and pages in API order. Blogger pages by token,
|
|
62
|
+
* so the next page's task is yielded only after the previous page has been fetched, by its task or by this
|
|
63
|
+
* generator. Each task writes its page into `ctx.sourceIngestion` as `post` records.
|
|
64
|
+
*/
|
|
65
|
+
async function* tasks(options) {
|
|
66
|
+
for (const blogID of options.blogIDs) {
|
|
67
|
+
let pageToken;
|
|
68
|
+
let page = 0;
|
|
69
|
+
do {
|
|
70
|
+
const token = pageToken;
|
|
71
|
+
const number = ++page;
|
|
72
|
+
let fetched;
|
|
73
|
+
const load = () => (fetched ??= fetchPage(options, blogID, number, token));
|
|
74
|
+
yield {
|
|
75
|
+
title: `Fetching posts for blog ${blogID}, page ${number}`,
|
|
76
|
+
blogID,
|
|
77
|
+
page: number,
|
|
78
|
+
records: async () => (await load()).records,
|
|
79
|
+
task: async (ctx) => {
|
|
80
|
+
const stage = stageFor(ctx);
|
|
81
|
+
writeRecords(stage, (await load()).records);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
pageToken = (await load()).nextPageToken;
|
|
85
|
+
} while (pageToken);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export { postsURL, pageRecords, tasks, writeRecords };
|
|
89
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/lib/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,IAAI,KAAK,EAAC,MAAM,sBAAsB,CAAC;AACzD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AA+BtC,iDAAiD;AACjD,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,SAAkB,EAAU,EAAE;IAC5E,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC,EAAC,GAAG,EAAE,MAAM,EAAC,CAAC,CAAC;IACxD,IAAI,SAAS,EAAE,CAAC;QACZ,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,+CAA+C,kBAAkB,CAAC,MAAM,CAAC,UAAU,YAAY,EAAE,CAAC;AAC7G,CAAC,CAAC;AAEF,kEAAkE;AAClE,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAoB,EAAE,IAAY,EAAuB,EAAE,CAC5F,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI;IAC1C,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAC;CACjC,CAAC,CAAC,CAAC;AAER,iFAAiF;AACjF,MAAM,SAAS,GAAG,KAAK,EACnB,EAAC,MAAM,EAAE,YAAY,GAAG,GAAG,EAAe,EAC1C,MAAc,EACd,IAA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EAAC,EAAE;oBACd,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;oBAC5B,YAAY,CAAC,KAAK,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;gBAChD,CAAC;aACJ,CAAC;YACF,SAAS,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,aAAa,CAAC;QAC7C,CAAC,QAAQ,SAAS,EAAE;IACxB,CAAC;AACL,CAAC;AAED,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MigrateContext, SourceRecordInput } from '@tryghost/mg-context';
|
|
2
|
+
export interface ParseOptions {
|
|
3
|
+
/** The Blogger API key. It is used for requests only and never stored. */
|
|
4
|
+
apiKey: string;
|
|
5
|
+
/** Milliseconds to wait before each request. Defaults to 500. */
|
|
6
|
+
requestDelay?: number;
|
|
7
|
+
/** Called with each page's title before it is fetched. */
|
|
8
|
+
onProgress?: (title: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface IngestOptions extends ParseOptions {
|
|
11
|
+
/** Replace completed source data. Without it, ingesting into a context that has source data throws. */
|
|
12
|
+
replace?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Yield the source records for every page of each blog's posts, one page at a time, without storing them. */
|
|
15
|
+
export declare function parse(blogIDs: string | string[], { apiKey, requestDelay, onProgress }: ParseOptions): AsyncGenerator<SourceRecordInput>;
|
|
16
|
+
/**
|
|
17
|
+
* Fetch every post of the given blogs into `context.sources` as `post` records keyed `post:id:<id>`, blogs in the
|
|
18
|
+
* given order. The blog IDs narrow the fetch and are stored with the ingestion; `map()` applies every other option.
|
|
19
|
+
* A post returned twice while paging keeps its most recently updated version and reports a `source:conflict`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ingest(blogIDs: string | string[], context: MigrateContext, { apiKey, requestDelay, replace, onProgress }: IngestOptions): Promise<void>;
|
|
22
|
+
/** The blog IDs stored with the completed ingestion. */
|
|
23
|
+
export declare function sourceBlogs(context: MigrateContext): string[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { tasks } from './fetch.js';
|
|
2
|
+
const blogList = (blogIDs) => [blogIDs].flat().map(String);
|
|
3
|
+
/** Yield the source records for every page of each blog's posts, one page at a time, without storing them. */
|
|
4
|
+
export async function* parse(blogIDs, { apiKey, requestDelay, onProgress }) {
|
|
5
|
+
for await (const task of tasks({ apiKey, blogIDs: blogList(blogIDs), requestDelay })) {
|
|
6
|
+
onProgress?.(task.title);
|
|
7
|
+
yield* await task.records();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Fetch every post of the given blogs into `context.sources` as `post` records keyed `post:id:<id>`, blogs in the
|
|
12
|
+
* given order. The blog IDs narrow the fetch and are stored with the ingestion; `map()` applies every other option.
|
|
13
|
+
* A post returned twice while paging keeps its most recently updated version and reports a `source:conflict`.
|
|
14
|
+
*/
|
|
15
|
+
export async function ingest(blogIDs, context, { apiKey, requestDelay, replace = false, onProgress }) {
|
|
16
|
+
const blogs = blogList(blogIDs);
|
|
17
|
+
await context.sources.ingest({ replace, metadata: { adapter: 'blogger', blogs } }, async (stage) => {
|
|
18
|
+
const ctx = { sourceIngestion: stage };
|
|
19
|
+
for await (const task of tasks({ apiKey, blogIDs: blogs, requestDelay })) {
|
|
20
|
+
onProgress?.(task.title);
|
|
21
|
+
await task.task(ctx);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** The blog IDs stored with the completed ingestion. */
|
|
26
|
+
export function sourceBlogs(context) {
|
|
27
|
+
const blogs = context.sources.currentIngestion?.metadata.blogs;
|
|
28
|
+
if (!Array.isArray(blogs)) {
|
|
29
|
+
throw new Error('Completed Blogger source data has no blog IDs.');
|
|
30
|
+
}
|
|
31
|
+
return blogs.map(String);
|
|
32
|
+
}
|
|
33
|
+
//# sourceM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E,YAAY,EAAC,CAAC,EAAE,CAAC;YACrE,UAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,WAAW,CAAC,OAAuB;IAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,KAAK,CAAC;IAC/D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MigrateContext } from '@tryghost/mg-context';
|
|
2
|
+
import type { MappingSummary } from '@tryghost/mg-context';
|
|
3
|
+
import type { GhostUser } from '@tryghost/mg-ghost-authors';
|
|
4
|
+
import type { BloggerOptions } 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, name and slug. */
|
|
8
|
+
ghostUsers?: Iterable<GhostUser> | AsyncIterable<GhostUser>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A stable Ghost ID. Posts are scoped to their blog ID; tags and authors are shared by every blog, so they use
|
|
12
|
+
* `blogger.com`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ghostId(site: string, kind: string, key: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Rebuild posts, tags and authors from the stored Blogger posts. `blogID` selects stored blogs, and `addTag` and
|
|
17
|
+
* `firstImageAsFeatured` apply here, so changing them needs no new fetch; a blog that was not fetched needs a new
|
|
18
|
+
* ingestion. Posts without an ID or a valid date, or over Ghost's relationship limits, are skipped with a
|
|
19
|
+
* `record:skipped` diagnostic.
|
|
20
|
+
*/
|
|
21
|
+
export declare function map(options: BloggerOptions, context: MigrateContext, services?: MappingServices): Promise<MappingSummary>;
|
package/build/lib/map.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
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 { dateUtils, stringUtils } from '@tryghost/mg-utils';
|
|
5
|
+
import { decode } from 'html-entities';
|
|
6
|
+
import { processHTMLContent, slugFromURL } from './process.js';
|
|
7
|
+
import { sourceBlogs } from './ingest.js';
|
|
8
|
+
const ROLES = ['Contributor', 'Author', 'Editor', 'Administrator'];
|
|
9
|
+
/** Ghost relationship limits for one post. */
|
|
10
|
+
const MAX_RELATIONS = 500;
|
|
11
|
+
/**
|
|
12
|
+
* A stable Ghost ID. Posts are scoped to their blog ID; tags and authors are shared by every blog, so they use
|
|
13
|
+
* `blogger.com`.
|
|
14
|
+
*/
|
|
15
|
+
export function ghostId(site, kind, key) {
|
|
16
|
+
return coreGhostId('mg-blogger:1', site, kind, key);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The saved author for a Blogger profile. Authors are identified by Blogger profile ID, or by name when a post has
|
|
20
|
+
* none, so different accounts that share a display name stay separate users. A Ghost user with the author's
|
|
21
|
+
* `<slug>@example.com` email supplies its ID, name and slug.
|
|
22
|
+
*/
|
|
23
|
+
function mappedAuthor(state, author, name) {
|
|
24
|
+
const context = state.context;
|
|
25
|
+
const base = slugify(name) || 'author';
|
|
26
|
+
const key = author.id ? `id:${author.id}` : `name:${base}`;
|
|
27
|
+
const binding = state.getBinding('author', key);
|
|
28
|
+
if (binding) {
|
|
29
|
+
return AuthorContext.fromRow(context.db.stmts.findAuthorById.get(binding));
|
|
30
|
+
}
|
|
31
|
+
const email = (slug) => `${slug.slice(0, 50).replace(/-+$/, '')}@example.com`;
|
|
32
|
+
let data = { name, slug: base, email: email(base) };
|
|
33
|
+
const match = state.get('ghost-user', data.email);
|
|
34
|
+
if (match) {
|
|
35
|
+
data = { ...mergeUsersWithGhost([{ url: '', data: data }], [match])[0].data };
|
|
36
|
+
const sameGhost = state.getBinding('ghost-author', data.id);
|
|
37
|
+
if (sameGhost) {
|
|
38
|
+
state.bind('author', key, sameGhost);
|
|
39
|
+
return AuthorContext.fromRow(context.db.stmts.findAuthorById.get(sameGhost));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const id = data.id || ghostId('blogger.com', 'author', key);
|
|
43
|
+
delete data.id;
|
|
44
|
+
if (data.roles?.some((role) => !ROLES.includes(role))) {
|
|
45
|
+
context.recordDiagnostic('operation:warning', {
|
|
46
|
+
author: key,
|
|
47
|
+
reason: 'Unsupported author roles replaced by supported Ghost roles'
|
|
48
|
+
});
|
|
49
|
+
data.roles = data.roles.filter((role) => ROLES.includes(role));
|
|
50
|
+
if (!data.roles.length) {
|
|
51
|
+
data.roles = ['Contributor'];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
data.slug = state.uniqueSlug('author', data.slug, id);
|
|
55
|
+
if (!match && data.slug !== base) {
|
|
56
|
+
// Distinct authors need distinct emails as well as slugs.
|
|
57
|
+
data.email = email(data.slug);
|
|
58
|
+
}
|
|
59
|
+
const entity = new AuthorContext();
|
|
60
|
+
for (const [field, value] of Object.entries(data)) {
|
|
61
|
+
if (value !== undefined) {
|
|
62
|
+
entity.set(field, value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
entity.ghostId = id;
|
|
66
|
+
entity.save(context.db);
|
|
67
|
+
state.bind('author', key, entity.dbId);
|
|
68
|
+
state.bind('ghost-author', id, entity.dbId);
|
|
69
|
+
return entity;
|
|
70
|
+
}
|
|
71
|
+
/** Blogger labels are identified by slug, so labels that share a slug are one tag. `#` names are internal tags. */
|
|
72
|
+
function namedTag(name, slug = slugify(name)) {
|
|
73
|
+
if (name.startsWith('#') && !slug.startsWith('hash-')) {
|
|
74
|
+
slug = `hash-${slug}`;
|
|
75
|
+
}
|
|
76
|
+
const tag = new TagContext({ name, slug });
|
|
77
|
+
tag.ghostId = ghostId('blogger.com', 'tag', `slug:${slug}`);
|
|
78
|
+
return tag;
|
|
79
|
+
}
|
|
80
|
+
/** Order tags public first, then internal (`#`) tags, keeping their order otherwise. */
|
|
81
|
+
function publicFirst(tags) {
|
|
82
|
+
return [...tags].sort((a, b) => Number(a.data.name.startsWith('#')) - Number(b.data.name.startsWith('#')));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Rebuild posts, tags and authors from the stored Blogger posts. `blogID` selects stored blogs, and `addTag` and
|
|
86
|
+
* `firstImageAsFeatured` apply here, so changing them needs no new fetch; a blog that was not fetched needs a new
|
|
87
|
+
* ingestion. Posts without an ID or a valid date, or over Ghost's relationship limits, are skipped with a
|
|
88
|
+
* `record:skipped` diagnostic.
|
|
89
|
+
*/
|
|
90
|
+
export async function map(options, context, services = {}) {
|
|
91
|
+
if (!context.sources.hasCompletedIngestion) {
|
|
92
|
+
throw new Error('Ingest complete Blogger source data before mapping.');
|
|
93
|
+
}
|
|
94
|
+
const stored = sourceBlogs(context);
|
|
95
|
+
const blogs = options.blogID?.length ? options.blogID.map(String) : stored;
|
|
96
|
+
const missing = blogs.filter(blog => !stored.includes(blog));
|
|
97
|
+
if (missing.length) {
|
|
98
|
+
throw new Error(`The stored Blogger source data does not include blog ${missing.join(', ')}. Fetch it again with --rereadSource.`);
|
|
99
|
+
}
|
|
100
|
+
const firstImageAsFeatured = options.firstImageAsFeatured ?? true;
|
|
101
|
+
const addTag = options.addTag?.trim();
|
|
102
|
+
const state = new MappingState(context, 'mg-blogger');
|
|
103
|
+
return context.rebuildMappedContent(async () => {
|
|
104
|
+
for await (const user of services.ghostUsers ?? []) {
|
|
105
|
+
state.reserveSlug('author', user.slug, user.id);
|
|
106
|
+
if (user.email) {
|
|
107
|
+
state.set('ghost-user', user.email.toLowerCase(), user);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return context.mapRecords(context.sources.records({ kind: 'post' }), async (record) => {
|
|
111
|
+
const item = JSON.parse(record.content);
|
|
112
|
+
const blog = String(item.blog?.id ?? record.metadata.blog);
|
|
113
|
+
if (!blogs.includes(blog)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (!record.key) {
|
|
117
|
+
throw new RecordDataError('Post has no ID');
|
|
118
|
+
}
|
|
119
|
+
const published = dateUtils.parseDate(item.published) ?? dateUtils.parseDate(item.updated);
|
|
120
|
+
if (!published) {
|
|
121
|
+
throw new RecordDataError('Invalid Blogger post dates');
|
|
122
|
+
}
|
|
123
|
+
const tags = (item.labels ?? [])
|
|
124
|
+
.map(label => decode(String(label)).trim())
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.map(label => namedTag(label));
|
|
127
|
+
if (addTag) {
|
|
128
|
+
tags.push(namedTag(addTag));
|
|
129
|
+
}
|
|
130
|
+
tags.push(namedTag(`#blogger-site-${blog}`, `hash-blogger-site-${blog}`));
|
|
131
|
+
tags.push(namedTag('#blogger', 'hash-blogger'));
|
|
132
|
+
if (tags.length > MAX_RELATIONS) {
|
|
133
|
+
throw new RecordDataError('Post exceeds Ghost tag relationship limit');
|
|
134
|
+
}
|
|
135
|
+
const title = decode(item.title ?? '') || '(Untitled)';
|
|
136
|
+
const { html, feature_image: featureImage } = await processHTMLContent({
|
|
137
|
+
postData: {},
|
|
138
|
+
html: item.content ?? '',
|
|
139
|
+
options: { firstImageAsFeatured }
|
|
140
|
+
});
|
|
141
|
+
const post = new PostContext({ lookupKey: record.key });
|
|
142
|
+
post.ghostId = ghostId(blog, 'post', item.id);
|
|
143
|
+
post.set('title', title);
|
|
144
|
+
post.set('slug', (item.url && slugFromURL(item.url)) || slugify(title) || item.id);
|
|
145
|
+
post.set('status', 'published');
|
|
146
|
+
post.set('type', 'post');
|
|
147
|
+
post.set('created_at', published);
|
|
148
|
+
post.set('published_at', published);
|
|
149
|
+
post.set('updated_at', dateUtils.parseDate(item.updated) ?? published);
|
|
150
|
+
post.set('html', html);
|
|
151
|
+
if (featureImage) {
|
|
152
|
+
post.set('feature_image', featureImage);
|
|
153
|
+
}
|
|
154
|
+
const authorName = decode(item.author?.displayName ?? '').trim();
|
|
155
|
+
if (authorName) {
|
|
156
|
+
const author = mappedAuthor(state, item.author, authorName);
|
|
157
|
+
post.addAuthor(author);
|
|
158
|
+
context.sources.link(record.id, { type: 'author', id: author.dbId });
|
|
159
|
+
}
|
|
160
|
+
for (const tag of publicFirst(tags)) {
|
|
161
|
+
tag.save(context.db);
|
|
162
|
+
post.addTag(tag);
|
|
163
|
+
context.sources.link(record.id, { type: 'tag', id: tag.dbId });
|
|
164
|
+
}
|
|
165
|
+
post.save(context.db);
|
|
166
|
+
context.sources.link(record.id, { type: 'post', id: post.dbId });
|
|
167
|
+
if (item.url && URL.canParse(item.url)) {
|
|
168
|
+
context.addLink(stringUtils.cleanURL(item.url), `/${post.get('slug')}/`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//# 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,EACzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAC,MAAM,EAAC,MA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O,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,IAAK,EAAC,CAAC,CAAC;YACxE,CAAC;YAED,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACjB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,IAAK,EAAC,CAAC,CAAC;YAClE,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,IAAK,EAAC,CAAC,CAAC;YAChE,IAAI,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7E,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ProcessedContent {
|
|
2
|
+
html?: string;
|
|
3
|
+
feature_image?: string | null;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface ProcessHTMLArgs {
|
|
7
|
+
/** Fields to add `html` (and `feature_image`) to. */
|
|
8
|
+
postData: ProcessedContent;
|
|
9
|
+
html: string;
|
|
10
|
+
options?: {
|
|
11
|
+
firstImageAsFeatured?: boolean;
|
|
12
|
+
} | null;
|
|
13
|
+
}
|
|
14
|
+
declare const cleanExcerpt: (htmlContent: string) => string;
|
|
15
|
+
declare const slugFromURL: (url: string) => string;
|
|
16
|
+
declare const increaseImageSize: (src: string) => string;
|
|
17
|
+
declare const processHTMLContent: ({ postData, html, options }: ProcessHTMLArgs) => Promise<ProcessedContent>;
|
|
18
|
+
export { cleanExcerpt, slugFromURL, increaseImageSize, processHTMLContent };
|