@tryghost/mg-jekyll-export 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.
@@ -0,0 +1,399 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+ import { readFileSync } from 'node:fs';
4
+ import { RecordDataError } from '@tryghost/mg-context';
5
+ import { parseDate, parseFrontMatter, postUrl, processHtml, processPost } from '../index.js';
6
+ // Tests run from build/, so fixtures are read from the source tree.
7
+ const readSync = (name) => readFileSync(new URL(`../../src/test/fixtures/${name}`, import.meta.url), 'utf8');
8
+ const iso = (date) => date?.toISOString() ?? null;
9
+ describe('Process', function () {
10
+ it('Can process a basic Jekyll Markdown post', function () {
11
+ const fakeName = '_posts/2021-08-23-basic-post.md';
12
+ const fixture = readSync('2021-08-23-basic-post.md');
13
+ const post = processPost(fakeName, fixture);
14
+ assert.equal(post.title, 'This is a Basic Post');
15
+ assert.equal(post.slug, 'basic-post');
16
+ assert.equal(post.sourceSlug, 'basic-post');
17
+ assert.equal(post.status, 'published');
18
+ assert.equal(iso(post.date), '2021-08-23T00:00:00.000Z');
19
+ assert.deepEqual(post.tags, [{ name: '#jekyll', slug: 'hash-jekyll' }]);
20
+ assert.equal(post.html, '<p>Lorem ipsum <em>dolor</em> sit amet, <strong>consectetur</strong> adipiscing elit. <em><strong>Aliquam</strong></em> risus turpis, dictum ut eros vel, mollis fermentum purus. Sed venenatis cursus vestibulum. Proin auctor consequat viverra.</p>\n' +
21
+ '<p>Praesent sed est laoreet, vehicula nisl ac, fermentum magna.</p>\n' +
22
+ '<p>Lorem ipsum <em>dolor</em> sit amet, <strong>consectetur</strong> adipiscing elit. <em><strong>Aliquam</strong></em> risus turpis, dictum ut eros vel, mollis fermentum purus. Sed venenatis cursus vestibulum. Proin auctor consequat viverra.</p>\n' +
23
+ '<h2>Nulla et enim vel augue ultricies tempus</h2>\n' +
24
+ '<p>Donec eu <a href="https://example.com">luctus neque</a>, ut aliquet justo. Sed eleifend lorem sit amet libero pharetra, et vestibulum nibh pretium. Maecenas viverra nunc tortor, porta convallis quam convallis non. Donec nisl dolor, viverra id tortor accumsan, interdum feugiat sapien. Sed ultrices interdum tristique.</p>\n' +
25
+ '<p><img src="https://example.com/landscape.jpg" alt="A landscape image"></p>\n' +
26
+ '<ul>\n' +
27
+ '<li>Orci varius natoque penatibus et magnis dis</li>\n' +
28
+ '<li>Parturient montes, nascetur ridiculus mus. Suspendisse rutrum justo orci, sed vulputate est interdum a</li>\n' +
29
+ '<li>Nullam convallis, enim id tristique interdum, ligula leo ultricies nisi, eget scelerisque est eros lacinia orci.\n' +
30
+ '<ul>\n' +
31
+ '<li>Sed ante elit, laoreet ut feugiat vel, varius eu elit.</li>\n' +
32
+ '</ul>\n' +
33
+ '</li>\n' +
34
+ '<li>Class aptent taciti sociosqu ad litora torquent per conubia nostra</li>\n' +
35
+ '</ul>\n' +
36
+ '<p>Per inceptos himenaeos. Phasellus pharetra condimentum iaculis. Duis suscipit viverra scelerisque. Maecenas auctor arcu enim, dapibus egestas mi rhoncus quis.</p>\n' +
37
+ '<ul>\n' +
38
+ '<li>Orci varius natoque penatibus et magnis dis</li>\n' +
39
+ '<li>Parturient montes, nascetur ridiculus mus. Suspendisse rutrum justo orci, sed vulputate est interdum a</li>\n' +
40
+ '<li>Nullam convallis, enim id tristique interdum, ligula leo ultricies nisi, eget scelerisque est eros lacinia orci.\n' +
41
+ '<ul>\n' +
42
+ '<li>Sed ante elit, laoreet ut feugiat vel, varius eu elit.</li>\n' +
43
+ '</ul>\n' +
44
+ '</li>\n' +
45
+ '<li>Class aptent taciti sociosqu ad litora torquent per conubia nostra</li>\n' +
46
+ '</ul>\n' +
47
+ '<h3>Fusce efficitur congue hendrerit</h3>\n' +
48
+ '<p>Integer eu viverra ligula. Sed vulputate facilisis aliquam. In ultricies rhoncus justo, in feugiat tortor volutpat id. Morbi mollis tortor vel turpis feugiat tempus.</p>\n' +
49
+ '<h4>Proin pretium faucibus tincidunt</h4>\n' +
50
+ '<p>Praesent ac nulla eu ante pretium vehicula eget pharetra magna. Cras eleifend lobortis lacus, in volutpat diam finibus in.</p>\n' +
51
+ '<h5>Integer posuere libero non nisi commodo molestie</h5>\n' +
52
+ '<p>Donec luctus posuere dui sit amet consectetur. Suspendisse interdum enim eu dolor convallis laoreet. Mauris non metus elit. Nam ut sem rutrum, sollicitudin dui sed, feugiat velit.</p>\n' +
53
+ '<h6>Etiam eget imperdiet purus.</h6>\n' +
54
+ '<p>Duis a mattis augue, nec scelerisque velit. Sed mollis enim quis quam sollicitudin, quis fringilla tellus pulvinar. Aenean in consectetur ex. Sed non rhoncus nisl, quis vestibulum leo. Nulla vel porttitor dolor.</p>\n' +
55
+ '<ol>\n' +
56
+ '<li>Orci varius natoque penatibus et magnis dis</li>\n' +
57
+ '<li>Parturient montes, nascetur ridiculus mus. Suspendisse rutrum justo orci, sed vulputate est interdum a</li>\n' +
58
+ '<li>Nullam convallis, enim id tristique interdum, ligula leo ultricies nisi, eget scelerisque est eros lacinia orci.\n' +
59
+ '<ol>\n' +
60
+ '<li>Sed ante elit, laoreet ut feugiat vel, varius eu elit.</li>\n' +
61
+ '</ol>\n' +
62
+ '</li>\n' +
63
+ '<li>Class aptent taciti sociosqu ad litora torquent per conubia nostra</li>\n' +
64
+ '</ol>\n' +
65
+ '<p>Nunc eget magna sed dolor eleifend hendrerit. In quam dui, posuere eu tincidunt ullamcorper, tempor elementum ex. Vivamus lacus quam, bibendum ac felis vel, scelerisque rhoncus lacus. Integer posuere sollicitudin orci, quis dictum enim tempor et. Suspendisse potenti. Sed a ante ante.</p>');
66
+ assert.deepEqual(post.authors, ['Persons Name']);
67
+ });
68
+ it('Can process a basic Jekyll HTML post', function () {
69
+ const fakeName = '_posts/2022-06-05-basic.html';
70
+ const fixture = readSync('2022-06-05-basic.html');
71
+ const post = processPost(fakeName, fixture);
72
+ assert.equal(post.title, 'Basic HTML Post');
73
+ // Here are testing that Markdown syntax is left alone
74
+ assert.equal(post.html, '<p>First Paragraph</p>\n' + '\n' + '* First\n' + '* Second');
75
+ assert.deepEqual(post.authors, ['Mark Stosberg']);
76
+ });
77
+ it('Can process a post without front matter', function () {
78
+ const post = processPost('_posts/2022-06-05-no-front-matter.md', 'Plain body');
79
+ assert.equal(post.title, '(Untitled)');
80
+ assert.equal(post.html, '<p>Plain body</p>');
81
+ assert.deepEqual(post.authors, []);
82
+ });
83
+ it('Can process legacy front matter delimiters', function () {
84
+ const contents = '= yaml =\ntitle: Legacy delimiters\n...\nPlain body';
85
+ const post = processPost('_posts/2022-06-05-legacy-delimiters.md', contents);
86
+ assert.equal(post.title, 'Legacy delimiters');
87
+ assert.equal(post.html, '<p>Plain body</p>');
88
+ });
89
+ it('Can process a basic Jekyll post with no author', function () {
90
+ const fakeName = '_posts/2021-08-24-no-author.md';
91
+ const fixture = readSync('2021-08-24-no-author.md');
92
+ const post = processPost(fakeName, fixture);
93
+ // map() gives a post without authors the Example User.
94
+ assert.deepEqual(post.authors, []);
95
+ });
96
+ it('Can leave relative links when no URL is defined', function () {
97
+ const fakeName = '_posts/2021-08-25-relative-links.md';
98
+ const fixture = readSync('2021-08-25-relative-links.md');
99
+ const post = processPost(fakeName, fixture);
100
+ assert.equal(post.html, '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="/another-page">Pellentesque rutrum</a> ante in <a href="https://example.com">sapien ultrices</a>, sit amet auctor tellus iaculis.</p>\n' +
101
+ '<p><img src="/images/photo.jpg" alt="A nice photo"></p>\n' +
102
+ '<p><img src="/news/images/photo.jpg" alt="Relative-to-root image"></p>\n' +
103
+ '<p>Duis efficitur nisl pharetra enim lobortis consequat. Curabitur vestibulum diam vel elit ultricies semper.</p>\n' +
104
+ '<p><img src="http://example.com/images/photo.jpg" alt="Another nice photo"></p>\n' +
105
+ '<p>Sed nec sagittis risus, vitae tempor mi. Suspendisse potenti.</p>');
106
+ });
107
+ it('Can fix relative links when a URL is defined', function () {
108
+ const fakeName = '_posts/2021-08-25-relative-links.md';
109
+ const fixture = readSync('2021-08-25-relative-links.md');
110
+ const post = processPost(fakeName, fixture, {
111
+ url: `https://www.my-site.com/`
112
+ });
113
+ assert.equal(post.html, '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="https://www.my-site.com/another-page">Pellentesque rutrum</a> ante in <a href="https://example.com">sapien ultrices</a>, sit amet auctor tellus iaculis.</p>\n' +
114
+ '<p><img src="https://www.my-site.com/images/photo.jpg" alt="A nice photo"></p>\n' +
115
+ '<p><img src="https://www.my-site.com/news/images/photo.jpg" alt="Relative-to-root image"></p>\n' +
116
+ '<p>Duis efficitur nisl pharetra enim lobortis consequat. Curabitur vestibulum diam vel elit ultricies semper.</p>\n' +
117
+ '<p><img src="http://example.com/images/photo.jpg" alt="Another nice photo"></p>\n' +
118
+ '<p>Sed nec sagittis risus, vitae tempor mi. Suspendisse potenti.</p>');
119
+ assert.equal(postUrl({ url: 'https://www.my-site.com/' }, post), 'https://www.my-site.com/relative-links');
120
+ });
121
+ it('Can fix relative links when a URL with subdirectory is defined', function () {
122
+ const fakeName = '_posts/2021-08-25-relative-links.md';
123
+ const fixture = readSync('2021-08-25-relative-links.md');
124
+ const post = processPost(fakeName, fixture, {
125
+ url: `https://blog.my-site.com/news/`
126
+ });
127
+ assert.equal(post.html, '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="https://blog.my-site.com/another-page">Pellentesque rutrum</a> ante in <a href="https://example.com">sapien ultrices</a>, sit amet auctor tellus iaculis.</p>\n' +
128
+ '<p><img src="https://blog.my-site.com/images/photo.jpg" alt="A nice photo"></p>\n' +
129
+ '<p><img src="https://blog.my-site.com/news/images/photo.jpg" alt="Relative-to-root image"></p>\n' +
130
+ '<p>Duis efficitur nisl pharetra enim lobortis consequat. Curabitur vestibulum diam vel elit ultricies semper.</p>\n' +
131
+ '<p><img src="http://example.com/images/photo.jpg" alt="Another nice photo"></p>\n' +
132
+ '<p>Sed nec sagittis risus, vitae tempor mi. Suspendisse potenti.</p>');
133
+ assert.equal(postUrl({ url: 'https://blog.my-site.com/news/' }, post), 'https://blog.my-site.com/news/relative-links');
134
+ });
135
+ it('Can use a non-standard post date format', function () {
136
+ const fakeName = '_posts/2021-9-1-alt-date-format.md';
137
+ const fixture = readSync('2021-9-1-alt-date-format.md');
138
+ const post = processPost(fakeName, fixture);
139
+ assert.equal(iso(post.date), '2021-09-01T00:00:00.000Z');
140
+ assert.equal(post.slug, 'alt-date-format');
141
+ });
142
+ it('Can add specified tags to each post', function () {
143
+ const fakeName = '_posts/2021-08-25-relative-links.md';
144
+ const fixture = readSync('2021-08-25-relative-links.md');
145
+ const post = processPost(fakeName, fixture, {
146
+ addTags: 'Hello, #World, '
147
+ });
148
+ // Public tags come before internal ones.
149
+ assert.deepEqual(post.tags, [
150
+ { name: 'Hello', slug: 'hello' },
151
+ { name: '#jekyll', slug: 'hash-jekyll' },
152
+ { name: '#World', slug: 'hash-world' }
153
+ ]);
154
+ });
155
+ it('Can process draft posts', function () {
156
+ const fakeName = '_drafts/relative-links.md';
157
+ const fixture = readSync('2021-08-25-relative-links.md');
158
+ const post = processPost(fakeName, fixture);
159
+ assert.equal(post.status, 'draft');
160
+ assert.equal(post.slug, 'relative-links');
161
+ // map() dates a draft without a date when the export was read.
162
+ assert.equal(post.date, null);
163
+ });
164
+ it('Can process published:false frontmatter', function () {
165
+ const fakeName = '_posts/2022-06-05-published-false.md';
166
+ const fixture = readSync('2022-06-05-published-false.md');
167
+ const post = processPost(fakeName, fixture);
168
+ assert.equal(post.status, 'draft');
169
+ assert.equal(iso(post.date), '2022-06-05T00:00:00.000Z');
170
+ });
171
+ it('Can process `basename` frontmatter into slug', function () {
172
+ const fakeName = '_posts/2022-06-09-basename.md';
173
+ const fixture = readSync('2022-06-09-basename.md');
174
+ const post = processPost(fakeName, fixture);
175
+ assert.equal(post.slug, 'custom-basename');
176
+ assert.equal(post.sourceSlug, 'custom-basename');
177
+ assert.equal(iso(post.date), '2022-06-09T00:00:00.000Z');
178
+ });
179
+ it('Can process non-standard post types and add related tag', function () {
180
+ const fakeName = '_posts/w31rd_type-here/2021-08-25-relative-links.md';
181
+ const fixture = readSync('2021-08-25-relative-links.md');
182
+ const post = processPost(fakeName, fixture);
183
+ assert.equal(post.status, 'published');
184
+ assert.equal(post.slug, 'relative-links');
185
+ assert.deepEqual(post.tags, [
186
+ { name: '#w31rd_type-here', slug: 'hash-w31rd_type-here' },
187
+ { name: '#jekyll', slug: 'hash-jekyll' }
188
+ ]);
189
+ });
190
+ it('Can process non-standard post types and add related tag, with additonal tags', function () {
191
+ const fakeName = '_drafts/w31rd_type-here/2021-08-25-relative-links.md';
192
+ const fixture = readSync('2021-08-25-relative-links.md');
193
+ const post = processPost(fakeName, fixture, {
194
+ addTags: 'Hello'
195
+ });
196
+ assert.equal(post.status, 'draft');
197
+ assert.deepEqual(post.tags, [
198
+ { name: 'Hello', slug: 'hello' },
199
+ { name: '#w31rd_type-here', slug: 'hash-w31rd_type-here' },
200
+ { name: '#jekyll', slug: 'hash-jekyll' }
201
+ ]);
202
+ });
203
+ it('Can process posts without a date in the file name', function () {
204
+ const fakeName = '_posts/my-first-post.md';
205
+ const fixture = readSync('my-first-post.md');
206
+ const post = processPost(fakeName, fixture, {
207
+ addTags: 'NoFileDate'
208
+ });
209
+ assert.equal(post.status, 'published');
210
+ assert.equal(post.slug, 'my-first-post');
211
+ assert.equal(iso(post.date), '2021-11-26T00:00:00.000Z');
212
+ assert.deepEqual(post.tags, [
213
+ { name: 'NoFileDate', slug: 'nofiledate' },
214
+ { name: '#jekyll', slug: 'hash-jekyll' }
215
+ ]);
216
+ });
217
+ it('Can process posts with unquoted date in frontmatter, using .markdown extension', function () {
218
+ const fakeName = '_posts/unquoted-date.markdown';
219
+ const fixture = readSync('unquoted-date.markdown');
220
+ const post = processPost(fakeName, fixture);
221
+ assert.equal(iso(post.date), '2022-06-06T00:00:00.000Z');
222
+ assert.equal(post.slug, 'unquoted-date');
223
+ });
224
+ it('Can process posts with tags and categories in YAML list format', function () {
225
+ const fakeName = '_posts/2022-06-06-tag-list.md';
226
+ const fixture = readSync('2022-06-06-tag-list.md');
227
+ const post = processPost(fakeName, fixture);
228
+ assert.deepEqual(post.tags, [
229
+ { name: 'cat', slug: 'category-cat' },
230
+ { name: 'photos', slug: 'category-photos' },
231
+ { name: 'some-word', slug: 'some-word' },
232
+ { name: '#jekyll', slug: 'hash-jekyll' }
233
+ ]);
234
+ });
235
+ it('Can process posts that already include HTML', function () {
236
+ const fakeName = '_posts/2022-03-10-has-html.md';
237
+ const fixture = readSync('2022-03-10-has-html.md');
238
+ const post = processPost(fakeName, fixture, {
239
+ addTags: 'Has HTML'
240
+ });
241
+ assert.equal(post.html, '<p>Lorem ipsum dolor sit amet.</p>\n' +
242
+ '<video width="320" height="240" controls>\n' +
243
+ ' <source src="movie.mp4" type="video/mp4">\n' +
244
+ ' <source src="movie.ogg" type="video/ogg">\n' +
245
+ '</video>\n' +
246
+ '<p>Dolor sit amet.</p>');
247
+ });
248
+ it('Can process lists that have spaced between list items', function () {
249
+ const fakeName = '_posts/2022-03-11-has-spaced-lists.md';
250
+ const fixture = readSync('2022-03-11-has-spaced-lists.md');
251
+ const post = processPost(fakeName, fixture, {
252
+ addTags: 'Has HTML'
253
+ });
254
+ assert.equal(post.html, '<p>Lorem ipsum.</p>\n' +
255
+ '<ul>\n' +
256
+ '<li>This</li>\n' +
257
+ '<li>Is</li>\n' +
258
+ '<li>My</li>\n' +
259
+ '<li>List</li>\n' +
260
+ '</ul>\n' +
261
+ '<p>Dolor sit amet.</p>\n' +
262
+ '<ul>\n' +
263
+ '<li>This</li>\n' +
264
+ '<li>Is</li>\n' +
265
+ '<li>Another</li>\n' +
266
+ '<li>List</li>\n' +
267
+ '</ul>\n' +
268
+ '<p>Lorem ipsum.</p>\n' +
269
+ '<ul>\n' +
270
+ '<li>This list</li>\n' +
271
+ '<li>Has spaces</li>\n' +
272
+ '<li>Between each</li>\n' +
273
+ '<li>Line</li>\n' +
274
+ '</ul>\n' +
275
+ '<p>Dolor sit amet.</p>\n' +
276
+ '<ul>\n' +
277
+ '<li>Likewise</li>\n' +
278
+ '<li>For this</li>\n' +
279
+ '<li>Set of</li>\n' +
280
+ '<li>List Items too</li>\n' +
281
+ '</ul>\n' +
282
+ '<p>Lorem ipsum.</p>');
283
+ });
284
+ it('Can process front matter tags & categories', function () {
285
+ const fakeName = '_posts/2022-06-03-front-matter-tags-cats.md';
286
+ const fixture = readSync('2022-06-03-front-matter-tags-cats.md');
287
+ const post = processPost(fakeName, fixture, {
288
+ addTags: 'My Extra Tag'
289
+ });
290
+ assert.deepEqual(post.tags, [
291
+ { name: 'News', slug: 'category-news' },
292
+ { name: 'Posts', slug: 'category-posts' },
293
+ { name: 'Articles', slug: 'category-articles' },
294
+ { name: 'Lorem Ipsum', slug: 'lorem-ipsum' },
295
+ { name: 'dolor', slug: 'dolor' },
296
+ { name: 'Simet-Amet', slug: 'simet-amet' },
297
+ { name: 'My Extra Tag', slug: 'my-extra-tag' },
298
+ { name: '#jekyll', slug: 'hash-jekyll' }
299
+ ]);
300
+ });
301
+ it('Uses the front matter date over the file name, and drops the file name date from the slug', function () {
302
+ const post = processPost('_posts/2023-01-15-dated-both.md', '---\ntitle: Dated twice\ndate: 2023-01-14 23:30:00 -0100\n---\nBody');
303
+ assert.equal(iso(post.date), '2023-01-15T00:30:00.000Z');
304
+ assert.equal(post.slug, 'dated-both');
305
+ assert.equal(post.sourceSlug, 'dated-both');
306
+ });
307
+ it('Falls back to the file name date when the front matter date is invalid', function () {
308
+ for (const date of ['sometime', '2021-02-30', '"2021-13-01"', '20210101', '[2021-01-01]']) {
309
+ const post = processPost('_posts/2023-03-01-bad-date.md', `---\ndate: ${date}\n---\nBody`);
310
+ assert.equal(iso(post.date), '2023-03-01T00:00:00.000Z', date);
311
+ }
312
+ assert.equal(processPost('_posts/2023-02-30-impossible.md', 'Body').date, null);
313
+ assert.equal(processPost('_posts/undated.md', 'Body').date, null);
314
+ });
315
+ it('Reads dated drafts like posts', function () {
316
+ const post = processPost('_drafts/2023-01-01-dated-draft.md', 'Body');
317
+ assert.equal(post.status, 'draft');
318
+ assert.equal(post.slug, 'dated-draft');
319
+ assert.equal(iso(post.date), '2023-01-01T00:00:00.000Z');
320
+ });
321
+ it('Parses Jekyll front matter dates, reading zoneless values as UTC', function () {
322
+ const cases = [
323
+ ['2022-06-06', '2022-06-06T00:00:00.000Z'],
324
+ ['2021-9-1', '2021-09-01T00:00:00.000Z'],
325
+ ['2023-02-01 08:00', '2023-02-01T08:00:00.000Z'],
326
+ ['2023-02-01 08:00:00', '2023-02-01T08:00:00.000Z'],
327
+ ['2023-02-01T08:00:00Z', '2023-02-01T08:00:00.000Z'],
328
+ ['2023-01-15 10:30:00 +0100', '2023-01-15T09:30:00.000Z'],
329
+ ['2023-01-15 10:30:00 +01:00', '2023-01-15T09:30:00.000Z'],
330
+ ['2023-01-15 10:30:00 +01', '2023-01-15T09:30:00.000Z'],
331
+ ['2023-01-15T10:30:00.25-07:00', '2023-01-15T17:30:00.250Z'],
332
+ [' 2023-01-15 10:30:00 UTC ', '2023-01-15T10:30:00.000Z'],
333
+ ['2023-01-15 10:30:00 GMT', '2023-01-15T10:30:00.000Z'],
334
+ ['2023-01-15 25:00', null],
335
+ ['2023-01-15 10:30:00 EST', null],
336
+ ['15/01/2023', null],
337
+ ['', null],
338
+ [new Date('2023-01-15T00:00:00Z'), null],
339
+ [20230115, null],
340
+ [null, null]
341
+ ];
342
+ for (const [value, expected] of cases) {
343
+ assert.equal(iso(parseDate(value)), expected, String(value));
344
+ }
345
+ });
346
+ it('Reads dates in front matter as text rather than YAML timestamps', function () {
347
+ const { attributes } = parseFrontMatter('---\ndate: 2023-02-01 08:00:00\npublished: no\ncount: 3\n---\nBody');
348
+ assert.deepEqual(attributes, { date: '2023-02-01 08:00:00', published: false, count: 3 });
349
+ });
350
+ it('Ignores front matter that is not a mapping, and rejects invalid YAML', function () {
351
+ assert.deepEqual(parseFrontMatter('---\n- a\n- b\n---\nBody'), { attributes: {}, body: 'Body' });
352
+ assert.deepEqual(parseFrontMatter('---\nplain\n---\nBody'), { attributes: {}, body: 'Body' });
353
+ assert.deepEqual(parseFrontMatter('---\n\n---\nBody'), { attributes: {}, body: 'Body' });
354
+ assert.deepEqual(parseFrontMatter('---\n---\nBody'), { attributes: {}, body: 'Body' });
355
+ assert.deepEqual(parseFrontMatter('\uFEFF---\ntitle: BOM\n---'), { attributes: { title: 'BOM' }, body: '' });
356
+ assert.throws(() => processPost('_posts/2021-01-01-bad.md', '---\ntitle: [unclosed\n---\nBody'), (error) => error instanceof RecordDataError && error.message.startsWith('Invalid front matter: '));
357
+ });
358
+ it('Reads numbers, lists and space-separated values from the front matter', function () {
359
+ const post = processPost('_posts/2021-01-01-values.md', '---\ntitle: 2021\nauthor: [Jane Doe, 42, "", {name: Ignored}]\ncategory: [Big News, Other]\n' +
360
+ 'categories: " Posts Articles "\ntag: Lorem Ipsum\ntags: [Foo, foo, 7]\n---\nBody');
361
+ assert.equal(post.title, '2021');
362
+ assert.deepEqual(post.authors, ['Jane Doe', '42']);
363
+ assert.deepEqual(post.tags, [
364
+ { name: 'Big News', slug: 'category-big-news' },
365
+ { name: 'Other', slug: 'category-other' },
366
+ { name: 'Posts', slug: 'category-posts' },
367
+ { name: 'Articles', slug: 'category-articles' },
368
+ { name: 'Lorem Ipsum', slug: 'lorem-ipsum' },
369
+ { name: 'Foo', slug: 'foo' },
370
+ { name: '7', slug: '7' },
371
+ { name: '#jekyll', slug: 'hash-jekyll' }
372
+ ]);
373
+ });
374
+ it('Slugifies the slug, falling back to the title', function () {
375
+ assert.equal(processPost('_posts/2021-01-01-My Post.md', 'Body').slug, 'my-post');
376
+ assert.equal(processPost('_posts/2021-01-01-My Post.md', 'Body').sourceSlug, 'My Post');
377
+ assert.equal(processPost('_posts/2021-01-01-x.md', '---\nbasename: /nested/path/\n---\nBody').sourceSlug, 'nested/path');
378
+ assert.equal(processPost('_posts/2021-01-01-%%%.md', '---\ntitle: The Title\n---\nBody').slug, 'the-title');
379
+ assert.equal(processPost('_posts/2021-01-01-%%%.md', 'Body').slug, 'post');
380
+ });
381
+ it('Rejects a path that is not a post file', function () {
382
+ assert.throws(() => processPost('_posts/notes.txt', 'Body'), /Not a Jekyll post file: _posts\/notes.txt/);
383
+ });
384
+ it('Keeps HTML that already looks like an attribute, and links without targets', function () {
385
+ const html = processHtml('<p><code>a=""</code> <a>none</a> <img alt="x"> <a href="#top">top</a></p>', 'https://example.com');
386
+ assert.equal(html, '<p><code>a=""</code> <a>none</a> <img alt="x"> <a href="#top">top</a></p>');
387
+ });
388
+ it('Builds dated live URLs', function () {
389
+ const post = { sourceSlug: 'my-post', date: new Date('2021-08-23T10:00:00Z') };
390
+ assert.equal(postUrl({ url: 'https://example.com/' }, post), 'https://example.com/my-post');
391
+ assert.equal(postUrl({ url: 'https://example.com', datedPermalinks: 'none' }, post), 'https://example.com/my-post');
392
+ assert.equal(postUrl({ url: 'https://example.com', datedPermalinks: '/yyyy/mm/dd/' }, post), 'https://example.com/2021/08/23/my-post');
393
+ assert.equal(postUrl({ url: 'https://example.com/blog', datedPermalinks: '/yyyy/mm/' }, post), 'https://example.com/blog/2021/08/my-post');
394
+ assert.equal(postUrl({ url: 'https://example.com', datedPermalinks: '/yyyy/mm/dd/' }, { ...post, date: null }), 'https://example.com/my-post');
395
+ assert.throws(() => postUrl({ url: 'example.com' }, post), /--url/);
396
+ assert.throws(() => postUrl({}, post), /--url/);
397
+ });
398
+ });
399
+ //# sourceMappingURL=process.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.test.js","sourceRoot":"","sources":["../../src/test/process.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,QAAQ,EAAE,EAAE,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AACrC,OA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.0",
4
+ "description": "Migrate content from a Jekyll site export to Ghost",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/TryGhost/migrate.git",
@@ -9,27 +9,38 @@
9
9
  },
10
10
  "author": "Ghost Foundation",
11
11
  "license": "MIT",
12
- "main": "index.js",
12
+ "main": "build/index.js",
13
13
  "type": "module",
14
+ "types": "./build/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./build/index.d.ts",
18
+ "default": "./build/index.js"
19
+ }
20
+ },
14
21
  "files": [
15
- "index.js",
16
- "lib"
22
+ "build"
17
23
  ],
18
24
  "publishConfig": {
19
25
  "access": "public"
20
26
  },
21
- "devDependencies": {},
27
+ "devDependencies": {
28
+ "@types/node": "24.19.2",
29
+ "c8": "12.0.0",
30
+ "typescript": "7.0.2"
31
+ },
22
32
  "dependencies": {
23
- "@tryghost/errors": "3.4.2",
24
- "@tryghost/mg-fs-utils": "0.26.8-0",
25
- "@tryghost/mg-utils": "0.11.8-0",
26
- "@tryghost/pretty-cli": "3.3.16",
27
- "@tryghost/string": "0.3.7",
33
+ "@tryghost/mg-context": "0.12.0",
34
+ "@tryghost/mg-fs-utils": "0.27.0",
35
+ "@tryghost/mg-ghost-authors": "0.11.0",
36
+ "@tryghost/mg-utils": "0.12.0",
37
+ "@tryghost/string": "0.3.10",
28
38
  "js-yaml": "5.5.0",
29
39
  "markdown-it": "15.0.3"
30
40
  },
31
41
  "scripts": {
32
- "dev": "echo \"Implement me!\"",
33
- "test": "node --test 'test/**/*.test.js'"
42
+ "build": "tsc --build",
43
+ "test": "c8 --src src --all --check-coverage --100 --exclude '**/test/**' --exclude '**/*.d.ts' node --test 'build/test/**/*.test.js'",
44
+ "test:local": "pnpm build && pnpm test"
34
45
  }
35
46
  }
package/index.js DELETED
@@ -1,9 +0,0 @@
1
- import readZip from './lib/read-zip.js';
2
- import process from './lib/process.js';
3
-
4
- export default (pathToZip, options) => {
5
- let input = readZip(pathToZip, options);
6
- let output = process(input, options);
7
-
8
- return output;
9
- };
@@ -1,60 +0,0 @@
1
- import {domUtils} from '@tryghost/mg-utils';
2
-
3
- /*
4
- Process the HTML of a single Jekyll Post.
5
-
6
- Receives raw HTML, returns processed HTML
7
- */
8
-
9
- export default (rawHtml, options = {}) => {
10
- return domUtils.processFragment(rawHtml, parsed => {
11
- // Convert relative links and image paths to absolute
12
- if (options.url) {
13
- const urlData = new URL(options.url);
14
- // The "origin" the URL truncated to the domain.
15
- // The difference between the "href" matters for blogs that were hosted
16
- // in sub-directories so that relative and relative-to-root URLs resolve correctly.
17
- const urlOrigin = urlData.origin;
18
-
19
- parsed.$('a').forEach(anchor => {
20
- const thisURL = anchor.getAttribute('href');
21
-
22
- // If it starts with a slash, append the base URL
23
- if (thisURL && thisURL.indexOf('/') === 0) {
24
- const updatedURL = `${urlOrigin.replace(/^\/|\/$/g, '')}/${thisURL.replace(/^\/|\/$/g, '')}`;
25
- anchor.setAttribute('href', updatedURL);
26
- }
27
- });
28
-
29
- parsed.$('img').forEach(img => {
30
- const thisSrc = img.getAttribute('src');
31
-
32
- // If it starts with a slash, append the base URL
33
- if (thisSrc && thisSrc.indexOf('/') === 0) {
34
- const updatedURL = `${urlOrigin.replace(/^\/|\/$/g, '')}/${thisSrc.replace(/^\/|\/$/g, '')}`;
35
- img.setAttribute('src', updatedURL);
36
- }
37
- });
38
- }
39
-
40
- // Unwrap <p> tags that are in <li> tags
41
- parsed.$('li').forEach(li => {
42
- const p = li.querySelector('p');
43
-
44
- if (p) {
45
- li.replaceChildren(...p.childNodes);
46
- }
47
- });
48
-
49
- // convert HTML back to a string
50
- let html = parsed.html();
51
-
52
- // Remove empty attributes
53
- html = html.replace(/=""/g, '');
54
-
55
- // Trim whitespace
56
- html = html.trim();
57
-
58
- return html;
59
- });
60
- };