@tryghost/mg-chorus 0.11.8-0 → 0.12.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 +101 -27
- package/build/index.d.ts +5 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/build/lib/ingest.d.ts +16 -0
- package/build/lib/ingest.js +81 -0
- package/build/lib/ingest.js.map +1 -0
- package/build/lib/json-to-html.d.ts +20 -0
- package/build/lib/json-to-html.js +74 -0
- package/build/lib/json-to-html.js.map +1 -0
- package/build/lib/map.d.ts +20 -0
- package/build/lib/map.js +178 -0
- package/build/lib/map.js.map +1 -0
- package/build/lib/types.d.ts +40 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/test/helpers.d.ts +27 -0
- package/build/test/helpers.js +75 -0
- package/build/test/helpers.js.map +1 -0
- package/build/test/ingest.test.d.ts +1 -0
- package/build/test/ingest.test.js +136 -0
- package/build/test/ingest.test.js.map +1 -0
- package/build/test/json-to-html.test.d.ts +1 -0
- package/build/test/json-to-html.test.js +109 -0
- package/build/test/json-to-html.test.js.map +1 -0
- package/build/test/map.test.d.ts +1 -0
- package/build/test/map.test.js +284 -0
- package/build/test/map.test.js.map +1 -0
- package/package.json +24 -10
- package/index.js +0 -10
- package/lib/json-to-html.js +0 -187
- package/lib/processor.js +0 -146
- package/lib/read-zip.js +0 -87
package/lib/processor.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import {slugify} from '@tryghost/string';
|
|
2
|
-
import {_base as debugFactory} from '@tryghost/debug';
|
|
3
|
-
import jsonToHtml from './json-to-html.js';
|
|
4
|
-
|
|
5
|
-
const debug = debugFactory('migrate:chorus:processor');
|
|
6
|
-
|
|
7
|
-
const processContent = groups => {
|
|
8
|
-
if (!groups) {
|
|
9
|
-
debug(`Post has no content`);
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return jsonToHtml(groups);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const processPost = (data, options) => {
|
|
17
|
-
const {addPrimaryTag} = options;
|
|
18
|
-
|
|
19
|
-
const postUrl = data.source.url;
|
|
20
|
-
const postSlug = data.source.url.match(/([a-zA-Z0-9-_]+)$/)[1];
|
|
21
|
-
|
|
22
|
-
const post = {
|
|
23
|
-
url: postUrl,
|
|
24
|
-
data: {
|
|
25
|
-
slug: postSlug,
|
|
26
|
-
title: data?.source?.title || '(Untitled)',
|
|
27
|
-
custom_excerpt: data?.source?.dek?.html || null,
|
|
28
|
-
status: 'published',
|
|
29
|
-
created_at: data.source.createdAt,
|
|
30
|
-
updated_at: data.source.updatedAt,
|
|
31
|
-
published_at: data.source.createdAt,
|
|
32
|
-
tags: [],
|
|
33
|
-
authors: []
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (data?.source?.author?.fullOrUserName) {
|
|
38
|
-
let authorSlug = slugify(data.source.author.fullOrUserName);
|
|
39
|
-
let authorObject = {
|
|
40
|
-
url: `/author/${authorSlug}`,
|
|
41
|
-
data: {
|
|
42
|
-
email: `${authorSlug}@example.com`,
|
|
43
|
-
slug: authorSlug,
|
|
44
|
-
name: data.source.author.fullOrUserName
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
post.data.authors.push(authorObject);
|
|
48
|
-
debug(`Adding author to ${data.slug} post object`, authorObject);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (data?.source?.authorProfile?.name) {
|
|
52
|
-
let authorSlug = slugify(data.source.authorProfile.name);
|
|
53
|
-
let authorObject = {
|
|
54
|
-
url: `/author/${authorSlug}`,
|
|
55
|
-
data: {
|
|
56
|
-
email: `${authorSlug}@example.com`,
|
|
57
|
-
slug: authorSlug,
|
|
58
|
-
name: data.source.authorProfile.name
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
post.data.authors.push(authorObject);
|
|
62
|
-
debug(`Adding author to ${data.slug} post object`, authorObject);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (data?.source?.contributors) {
|
|
66
|
-
data?.source?.contributors.forEach(contributor => {
|
|
67
|
-
let authorSlug = slugify(contributor.fullOrUserName);
|
|
68
|
-
let authorObject = {
|
|
69
|
-
url: `/author/${authorSlug}`,
|
|
70
|
-
data: {
|
|
71
|
-
email: `${authorSlug}@example.com`,
|
|
72
|
-
slug: authorSlug,
|
|
73
|
-
name: contributor.fullOrUserName
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
post.data.authors.push(authorObject);
|
|
77
|
-
debug(`Adding contributor to ${data.slug} post object`, authorObject);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (addPrimaryTag) {
|
|
82
|
-
let tagObject = {
|
|
83
|
-
url: `/tag/${slugify(addPrimaryTag)}`,
|
|
84
|
-
data: {
|
|
85
|
-
slug: slugify(addPrimaryTag),
|
|
86
|
-
name: addPrimaryTag
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
post.data.tags.push(tagObject);
|
|
90
|
-
debug(`Adding supplied primary tag to ${data.slug} post object`, tagObject);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (data?.source?.communityGroups) {
|
|
94
|
-
data.source.communityGroups.forEach(tag => {
|
|
95
|
-
let tagSlug = slugify(tag.name);
|
|
96
|
-
let tagObject = {
|
|
97
|
-
url: `migrator-added-tag-${tagSlug}`,
|
|
98
|
-
data: {
|
|
99
|
-
slug: tagSlug,
|
|
100
|
-
name: tag.name
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
post.data.tags.push(tagObject);
|
|
104
|
-
debug(`Adding tag to ${data.slug} post object`, tagObject);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
post.data.tags.push({
|
|
109
|
-
url: `migrator-added-tag-hash-chorus`,
|
|
110
|
-
data: {
|
|
111
|
-
slug: 'hash-chorus',
|
|
112
|
-
name: '#chorus'
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// Some HTML content needs to be modified so that our parser plugins can interpret it
|
|
117
|
-
post.data.html = processContent(data.source.body.components, options);
|
|
118
|
-
|
|
119
|
-
return post;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const processPosts = (posts, options) => {
|
|
123
|
-
const results = [];
|
|
124
|
-
for (let i = 0; i < posts.length; i++) {
|
|
125
|
-
const post = posts[i];
|
|
126
|
-
if (post) {
|
|
127
|
-
results.push(processPost(post, options));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return results;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const all = ({result, options}) => {
|
|
134
|
-
const output = {
|
|
135
|
-
posts: processPosts(result.posts, options)
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
return output;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export default {
|
|
142
|
-
processContent,
|
|
143
|
-
processPost,
|
|
144
|
-
processPosts,
|
|
145
|
-
all
|
|
146
|
-
};
|
package/lib/read-zip.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import fsUtils from '@tryghost/mg-fs-utils';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import {_base as debugFactory} from '@tryghost/debug';
|
|
5
|
-
|
|
6
|
-
const debug = debugFactory('migrate:chorus:lib:read-zip');
|
|
7
|
-
|
|
8
|
-
const readChorusFile = ({content, entries, options, skippedFileCount}) => {
|
|
9
|
-
if (entries.includes('.zip')) {
|
|
10
|
-
fsUtils.zip.read(entries, (entryName, zipEntry) => {
|
|
11
|
-
// Catch all JSON files
|
|
12
|
-
if (/^Entry:.*\.json$/.test(entryName)) {
|
|
13
|
-
try {
|
|
14
|
-
content.posts.push({
|
|
15
|
-
name: entryName,
|
|
16
|
-
source: JSON.parse(zipEntry.getData().toString('utf8'))
|
|
17
|
-
});
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.log(entries, entryName, error); // eslint-disable-line no-console
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Skip if not matched above, and report skipped files if `--verbose`
|
|
23
|
-
} else {
|
|
24
|
-
if (options.verbose) {
|
|
25
|
-
debug(`Skipped: ${entryName}`);
|
|
26
|
-
}
|
|
27
|
-
skippedFileCount += 1;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
fs.readdirSync(entries).forEach(entryName => {
|
|
32
|
-
if (/^Entry:.*\.json$/.test(entryName)) {
|
|
33
|
-
try {
|
|
34
|
-
content.posts.push({
|
|
35
|
-
name: entryName,
|
|
36
|
-
source: JSON.parse(fs.readFileSync(path.join(entries, entryName), 'utf8'))
|
|
37
|
-
});
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.log(entries, entryName, error); // eslint-disable-line no-console
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Skip if not matched above, and report skipped files if `--verbose`
|
|
43
|
-
} else {
|
|
44
|
-
if (options.verbose) {
|
|
45
|
-
debug(`Skipped: ${entryName}`);
|
|
46
|
-
}
|
|
47
|
-
skippedFileCount += 1;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
content,
|
|
54
|
-
skippedFileCount
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export default (entries, options) => {
|
|
59
|
-
let content = {
|
|
60
|
-
posts: []
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
let skippedFileCount = 0;
|
|
64
|
-
|
|
65
|
-
// We only support the current Chorus export file structure:
|
|
66
|
-
// - entries.csv
|
|
67
|
-
// - Entry:0969db64-b8d7-11ed-afa1-0242ac120001.json
|
|
68
|
-
// - Entry:0969db64-b8d7-11ed-afa1-0242ac120002.json
|
|
69
|
-
|
|
70
|
-
const ifIsArray = Array.isArray(entries);
|
|
71
|
-
|
|
72
|
-
if (ifIsArray && entries.length > 1) {
|
|
73
|
-
entries.forEach(file => {
|
|
74
|
-
const fileContent = readChorusFile({content, entries: file, options, skippedFileCount});
|
|
75
|
-
content = fileContent.content;
|
|
76
|
-
skippedFileCount = fileContent.skippedFileCount;
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
const fileContent = readChorusFile({content, entries: entries[0], options, skippedFileCount});
|
|
80
|
-
content = fileContent.content;
|
|
81
|
-
skippedFileCount = fileContent.skippedFileCount;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
debug(`Skipped files: ${skippedFileCount}`);
|
|
85
|
-
|
|
86
|
-
return content;
|
|
87
|
-
};
|