@docusaurus/plugin-content-blog 2.0.0-beta.677e53d4d → 2.0.0-beta.7

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.
Files changed (56) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/authors.d.ts +23 -0
  3. package/lib/authors.js +150 -0
  4. package/lib/blogFrontMatter.d.ts +19 -6
  5. package/lib/blogFrontMatter.js +31 -19
  6. package/lib/blogUtils.d.ts +10 -2
  7. package/lib/blogUtils.js +146 -104
  8. package/lib/index.js +78 -77
  9. package/lib/markdownLoader.js +3 -3
  10. package/lib/pluginOptionSchema.d.ts +3 -26
  11. package/lib/pluginOptionSchema.js +22 -7
  12. package/lib/translations.d.ts +10 -0
  13. package/lib/translations.js +53 -0
  14. package/lib/types.d.ts +38 -14
  15. package/package.json +13 -11
  16. package/src/__tests__/__fixtures__/authorsMapFiles/authors.json +29 -0
  17. package/src/__tests__/__fixtures__/authorsMapFiles/authors.yml +27 -0
  18. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.json +5 -0
  19. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.yml +3 -0
  20. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.json +3 -0
  21. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.yml +2 -0
  22. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.json +8 -0
  23. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.yml +3 -0
  24. package/src/__tests__/__fixtures__/component/Typography.tsx +6 -0
  25. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathEmpty/empty +0 -0
  26. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson1/authors.json +0 -0
  27. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson2/authors.json +0 -0
  28. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathNestedYml/sub/folder/authors.yml +0 -0
  29. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml1/authors.yml +0 -0
  30. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml2/authors.yml +0 -0
  31. package/src/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md +3 -0
  32. package/src/__tests__/__fixtures__/website/blog/_partials/somePartial.md +3 -0
  33. package/src/__tests__/__fixtures__/website/blog/_partials/subfolder/somePartial.md +3 -0
  34. package/src/__tests__/__fixtures__/website/blog/_somePartial.md +3 -0
  35. package/src/__tests__/__fixtures__/website/blog/authors.yml +4 -0
  36. package/src/__tests__/__fixtures__/website/blog/mdx-blog-post.mdx +36 -0
  37. package/src/__tests__/__fixtures__/website/blog/simple-slug.md +4 -0
  38. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +3 -0
  39. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/authors.yml +5 -0
  40. package/src/__tests__/__snapshots__/generateBlogFeed.test.ts.snap +81 -3
  41. package/src/__tests__/__snapshots__/translations.test.ts.snap +64 -0
  42. package/src/__tests__/authors.test.ts +608 -0
  43. package/src/__tests__/blogFrontMatter.test.ts +93 -16
  44. package/src/__tests__/blogUtils.test.ts +94 -0
  45. package/src/__tests__/generateBlogFeed.test.ts +7 -1
  46. package/src/__tests__/index.test.ts +63 -12
  47. package/src/__tests__/pluginOptionSchema.test.ts +3 -3
  48. package/src/__tests__/translations.test.ts +92 -0
  49. package/src/authors.ts +202 -0
  50. package/src/blogFrontMatter.ts +73 -33
  51. package/src/blogUtils.ts +206 -131
  52. package/src/index.ts +98 -71
  53. package/{index.d.ts → src/plugin-content-blog.d.ts} +35 -31
  54. package/src/pluginOptionSchema.ts +25 -9
  55. package/src/translations.ts +63 -0
  56. package/src/types.ts +48 -16
@@ -0,0 +1,608 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {
9
+ AuthorsMap,
10
+ getAuthorsMapFilePath,
11
+ validateAuthorsMapFile,
12
+ readAuthorsMapFile,
13
+ getAuthorsMap,
14
+ getBlogPostAuthors,
15
+ } from '../authors';
16
+ import path from 'path';
17
+
18
+ describe('getBlogPostAuthors', () => {
19
+ test('can read no authors', () => {
20
+ expect(
21
+ getBlogPostAuthors({
22
+ frontMatter: {},
23
+ authorsMap: undefined,
24
+ }),
25
+ ).toEqual([]);
26
+ expect(
27
+ getBlogPostAuthors({
28
+ frontMatter: {
29
+ authors: [],
30
+ },
31
+ authorsMap: undefined,
32
+ }),
33
+ ).toEqual([]);
34
+ });
35
+
36
+ test('can read author from legacy frontmatter', () => {
37
+ expect(
38
+ getBlogPostAuthors({
39
+ frontMatter: {
40
+ author: 'Sébastien Lorber',
41
+ },
42
+ authorsMap: undefined,
43
+ }),
44
+ ).toEqual([{name: 'Sébastien Lorber'}]);
45
+ expect(
46
+ getBlogPostAuthors({
47
+ frontMatter: {
48
+ authorTitle: 'maintainer',
49
+ },
50
+ authorsMap: undefined,
51
+ }),
52
+ ).toEqual([{title: 'maintainer'}]);
53
+ expect(
54
+ getBlogPostAuthors({
55
+ frontMatter: {
56
+ authorImageURL: 'https://github.com/slorber.png',
57
+ },
58
+ authorsMap: undefined,
59
+ }),
60
+ ).toEqual([{imageURL: 'https://github.com/slorber.png'}]);
61
+ expect(
62
+ getBlogPostAuthors({
63
+ frontMatter: {
64
+ author: 'Sébastien Lorber',
65
+ author_title: 'maintainer1',
66
+ authorTitle: 'maintainer2',
67
+ author_image_url: 'https://github.com/slorber1.png',
68
+ authorImageURL: 'https://github.com/slorber2.png',
69
+ author_url: 'https://github.com/slorber1',
70
+ authorURL: 'https://github.com/slorber2',
71
+ },
72
+ authorsMap: undefined,
73
+ }),
74
+ ).toEqual([
75
+ {
76
+ name: 'Sébastien Lorber',
77
+ title: 'maintainer1',
78
+ imageURL: 'https://github.com/slorber1.png',
79
+ url: 'https://github.com/slorber1',
80
+ },
81
+ ]);
82
+ });
83
+
84
+ test('can read authors string', () => {
85
+ expect(
86
+ getBlogPostAuthors({
87
+ frontMatter: {
88
+ authors: 'slorber',
89
+ },
90
+ authorsMap: {slorber: {name: 'Sébastien Lorber'}},
91
+ }),
92
+ ).toEqual([{key: 'slorber', name: 'Sébastien Lorber'}]);
93
+ });
94
+
95
+ test('can read authors string[]', () => {
96
+ expect(
97
+ getBlogPostAuthors({
98
+ frontMatter: {
99
+ authors: ['slorber', 'yangshun'],
100
+ },
101
+ authorsMap: {
102
+ slorber: {name: 'Sébastien Lorber', title: 'maintainer'},
103
+ yangshun: {name: 'Yangshun Tay'},
104
+ },
105
+ }),
106
+ ).toEqual([
107
+ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'},
108
+ {key: 'yangshun', name: 'Yangshun Tay'},
109
+ ]);
110
+ });
111
+
112
+ test('can read authors Author', () => {
113
+ expect(
114
+ getBlogPostAuthors({
115
+ frontMatter: {
116
+ authors: {name: 'Sébastien Lorber', title: 'maintainer'},
117
+ },
118
+ authorsMap: undefined,
119
+ }),
120
+ ).toEqual([{name: 'Sébastien Lorber', title: 'maintainer'}]);
121
+ });
122
+
123
+ test('can read authors Author[]', () => {
124
+ expect(
125
+ getBlogPostAuthors({
126
+ frontMatter: {
127
+ authors: [
128
+ {name: 'Sébastien Lorber', title: 'maintainer'},
129
+ {name: 'Yangshun Tay'},
130
+ ],
131
+ },
132
+ authorsMap: undefined,
133
+ }),
134
+ ).toEqual([
135
+ {name: 'Sébastien Lorber', title: 'maintainer'},
136
+ {name: 'Yangshun Tay'},
137
+ ]);
138
+ });
139
+
140
+ test('can read authors complex (string | Author)[] setup with keys and local overrides', () => {
141
+ expect(
142
+ getBlogPostAuthors({
143
+ frontMatter: {
144
+ authors: [
145
+ 'slorber',
146
+ {
147
+ key: 'yangshun',
148
+ title: 'Yangshun title local override',
149
+ extra: 42,
150
+ },
151
+ {name: 'Alexey'},
152
+ ],
153
+ },
154
+ authorsMap: {
155
+ slorber: {name: 'Sébastien Lorber', title: 'maintainer'},
156
+ yangshun: {name: 'Yangshun Tay', title: 'Yangshun title original'},
157
+ },
158
+ }),
159
+ ).toEqual([
160
+ {key: 'slorber', name: 'Sébastien Lorber', title: 'maintainer'},
161
+ {
162
+ key: 'yangshun',
163
+ name: 'Yangshun Tay',
164
+ title: 'Yangshun title local override',
165
+ extra: 42,
166
+ },
167
+ {name: 'Alexey'},
168
+ ]);
169
+ });
170
+
171
+ test('throw when using author key with no authorsMap', () => {
172
+ expect(() =>
173
+ getBlogPostAuthors({
174
+ frontMatter: {
175
+ authors: 'slorber',
176
+ },
177
+ authorsMap: undefined,
178
+ }),
179
+ ).toThrowErrorMatchingInlineSnapshot(`
180
+ "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded.
181
+ Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!"
182
+ `);
183
+ });
184
+
185
+ test('throw when using author key with empty authorsMap', () => {
186
+ expect(() =>
187
+ getBlogPostAuthors({
188
+ frontMatter: {
189
+ authors: 'slorber',
190
+ },
191
+ authorsMap: {},
192
+ }),
193
+ ).toThrowErrorMatchingInlineSnapshot(`
194
+ "Can't reference blog post authors by a key (such as 'slorber') because no authors map file could be loaded.
195
+ Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!"
196
+ `);
197
+ });
198
+
199
+ test('throw when using bad author key in string', () => {
200
+ expect(() =>
201
+ getBlogPostAuthors({
202
+ frontMatter: {
203
+ authors: 'slorber',
204
+ },
205
+ authorsMap: {
206
+ yangshun: {name: 'Yangshun Tay'},
207
+ jmarcey: {name: 'Joel Marcey'},
208
+ },
209
+ }),
210
+ ).toThrowErrorMatchingInlineSnapshot(`
211
+ "Blog author with key \\"slorber\\" not found in the authors map file.
212
+ Valid author keys are:
213
+ - yangshun
214
+ - jmarcey"
215
+ `);
216
+ });
217
+
218
+ test('throw when using bad author key in string[]', () => {
219
+ expect(() =>
220
+ getBlogPostAuthors({
221
+ frontMatter: {
222
+ authors: ['yangshun', 'jmarcey', 'slorber'],
223
+ },
224
+ authorsMap: {
225
+ yangshun: {name: 'Yangshun Tay'},
226
+ jmarcey: {name: 'Joel Marcey'},
227
+ },
228
+ }),
229
+ ).toThrowErrorMatchingInlineSnapshot(`
230
+ "Blog author with key \\"slorber\\" not found in the authors map file.
231
+ Valid author keys are:
232
+ - yangshun
233
+ - jmarcey"
234
+ `);
235
+ });
236
+
237
+ test('throw when using bad author key in Author[].key', () => {
238
+ expect(() =>
239
+ getBlogPostAuthors({
240
+ frontMatter: {
241
+ authors: [{key: 'yangshun'}, {key: 'jmarcey'}, {key: 'slorber'}],
242
+ },
243
+ authorsMap: {
244
+ yangshun: {name: 'Yangshun Tay'},
245
+ jmarcey: {name: 'Joel Marcey'},
246
+ },
247
+ }),
248
+ ).toThrowErrorMatchingInlineSnapshot(`
249
+ "Blog author with key \\"slorber\\" not found in the authors map file.
250
+ Valid author keys are:
251
+ - yangshun
252
+ - jmarcey"
253
+ `);
254
+ });
255
+
256
+ test('throw when mixing legacy/new authors frontmatter', () => {
257
+ expect(() =>
258
+ getBlogPostAuthors({
259
+ frontMatter: {
260
+ authors: [{name: 'Sébastien Lorber'}],
261
+ author: 'Yangshun Tay',
262
+ },
263
+ authorsMap: undefined,
264
+ }),
265
+ ).toThrowErrorMatchingInlineSnapshot(`
266
+ "To declare blog post authors, use the 'authors' FrontMatter in priority.
267
+ Don't mix 'authors' with other existing 'author_*' FrontMatter. Choose one or the other, not both at the same time."
268
+ `);
269
+
270
+ expect(() =>
271
+ getBlogPostAuthors({
272
+ frontMatter: {
273
+ authors: [{key: 'slorber'}],
274
+ author_title: 'legacy title',
275
+ },
276
+ authorsMap: {slorber: {name: 'Sébastien Lorber'}},
277
+ }),
278
+ ).toThrowErrorMatchingInlineSnapshot(`
279
+ "To declare blog post authors, use the 'authors' FrontMatter in priority.
280
+ Don't mix 'authors' with other existing 'author_*' FrontMatter. Choose one or the other, not both at the same time."
281
+ `);
282
+ });
283
+ });
284
+
285
+ describe('readAuthorsMapFile', () => {
286
+ const fixturesDir = path.join(__dirname, '__fixtures__/authorsMapFiles');
287
+
288
+ test('read valid yml author file', async () => {
289
+ const filePath = path.join(fixturesDir, 'authors.yml');
290
+ expect(await readAuthorsMapFile(filePath)).toBeDefined();
291
+ });
292
+
293
+ test('read valid json author file', async () => {
294
+ const filePath = path.join(fixturesDir, 'authors.json');
295
+ expect(await readAuthorsMapFile(filePath)).toBeDefined();
296
+ });
297
+
298
+ test('read yml and json should lead to the same result', async () => {
299
+ const content1 = await readAuthorsMapFile(
300
+ path.join(fixturesDir, 'authors.yml'),
301
+ );
302
+ const content2 = await readAuthorsMapFile(
303
+ path.join(fixturesDir, 'authors.json'),
304
+ );
305
+ expect(content1).toEqual(content2);
306
+ });
307
+
308
+ test('fail to read invalid yml 1', async () => {
309
+ const filePath = path.join(fixturesDir, 'authorsBad1.yml');
310
+ await expect(
311
+ readAuthorsMapFile(filePath),
312
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
313
+ `"\\"slorber.name\\" is required"`,
314
+ );
315
+ });
316
+ test('fail to read invalid json 1', async () => {
317
+ const filePath = path.join(fixturesDir, 'authorsBad1.json');
318
+ await expect(
319
+ readAuthorsMapFile(filePath),
320
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
321
+ `"\\"slorber.name\\" is required"`,
322
+ );
323
+ });
324
+
325
+ test('fail to read invalid yml 2', async () => {
326
+ const filePath = path.join(fixturesDir, 'authorsBad2.yml');
327
+ await expect(
328
+ readAuthorsMapFile(filePath),
329
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
330
+ `"\\"name\\" must be of type object"`,
331
+ );
332
+ });
333
+ test('fail to read invalid json 2', async () => {
334
+ const filePath = path.join(fixturesDir, 'authorsBad2.json');
335
+ await expect(
336
+ readAuthorsMapFile(filePath),
337
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
338
+ `"\\"name\\" must be of type object"`,
339
+ );
340
+ });
341
+
342
+ test('fail to read invalid yml 3', async () => {
343
+ const filePath = path.join(fixturesDir, 'authorsBad3.yml');
344
+ await expect(
345
+ readAuthorsMapFile(filePath),
346
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
347
+ `"\\"value\\" must be of type object"`,
348
+ );
349
+ });
350
+ test('fail to read invalid json 3', async () => {
351
+ const filePath = path.join(fixturesDir, 'authorsBad3.json');
352
+ await expect(
353
+ readAuthorsMapFile(filePath),
354
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
355
+ `"\\"value\\" must be of type object"`,
356
+ );
357
+ });
358
+ });
359
+ describe('getAuthorsMap', () => {
360
+ const fixturesDir = path.join(__dirname, '__fixtures__/authorsMapFiles');
361
+ const contentPaths = {
362
+ contentPathLocalized: fixturesDir,
363
+ contentPath: fixturesDir,
364
+ };
365
+
366
+ test('getAuthorsMap can read yml file', async () => {
367
+ expect(
368
+ await getAuthorsMap({
369
+ contentPaths,
370
+ authorsMapPath: 'authors.yml',
371
+ }),
372
+ ).toBeDefined();
373
+ });
374
+
375
+ test('getAuthorsMap can read json file', async () => {
376
+ expect(
377
+ await getAuthorsMap({
378
+ contentPaths,
379
+ authorsMapPath: 'authors.json',
380
+ }),
381
+ ).toBeDefined();
382
+ });
383
+
384
+ test('getAuthorsMap can return undefined if yaml file not found', async () => {
385
+ expect(
386
+ await getAuthorsMap({
387
+ contentPaths,
388
+ authorsMapPath: 'authors_does_not_exist.yml',
389
+ }),
390
+ ).toBeUndefined();
391
+ });
392
+ });
393
+
394
+ describe('validateAuthorsMapFile', () => {
395
+ test('accept valid authors map', () => {
396
+ const authorsMap: AuthorsMap = {
397
+ slorber: {
398
+ name: 'Sébastien Lorber',
399
+ title: 'maintainer',
400
+ url: 'https://sebastienlorber.com',
401
+ imageURL: 'https://github.com/slorber.png',
402
+ },
403
+ yangshun: {
404
+ name: 'Yangshun Tay',
405
+ imageURL: 'https://github.com/yangshun.png',
406
+ randomField: 42,
407
+ },
408
+ jmarcey: {
409
+ name: 'Joel',
410
+ title: 'creator of Docusaurus',
411
+ hello: new Date(),
412
+ },
413
+ };
414
+ expect(validateAuthorsMapFile(authorsMap)).toEqual(authorsMap);
415
+ });
416
+
417
+ test('rename snake case image_url to camelCase imageURL', () => {
418
+ const authorsMap: AuthorsMap = {
419
+ slorber: {
420
+ name: 'Sébastien Lorber',
421
+ image_url: 'https://github.com/slorber.png',
422
+ },
423
+ };
424
+ expect(validateAuthorsMapFile(authorsMap)).toEqual({
425
+ slorber: {
426
+ name: 'Sébastien Lorber',
427
+ imageURL: 'https://github.com/slorber.png',
428
+ },
429
+ });
430
+ });
431
+
432
+ test('reject author without name', () => {
433
+ const authorsMap: AuthorsMap = {
434
+ slorber: {
435
+ image_url: 'https://github.com/slorber.png',
436
+ },
437
+ };
438
+ expect(() =>
439
+ validateAuthorsMapFile(authorsMap),
440
+ ).toThrowErrorMatchingInlineSnapshot(`"\\"slorber.name\\" is required"`);
441
+ });
442
+
443
+ test('reject undefined author', () => {
444
+ expect(() =>
445
+ validateAuthorsMapFile({
446
+ slorber: undefined,
447
+ }),
448
+ ).toThrowErrorMatchingInlineSnapshot(`"\\"slorber\\" is required"`);
449
+ });
450
+
451
+ test('reject null author', () => {
452
+ expect(() =>
453
+ validateAuthorsMapFile({
454
+ slorber: null,
455
+ }),
456
+ ).toThrowErrorMatchingInlineSnapshot(
457
+ `"\\"slorber\\" must be of type object"`,
458
+ );
459
+ });
460
+
461
+ test('reject array author', () => {
462
+ expect(() =>
463
+ validateAuthorsMapFile({slorber: []}),
464
+ ).toThrowErrorMatchingInlineSnapshot(
465
+ `"\\"slorber\\" must be of type object"`,
466
+ );
467
+ });
468
+
469
+ test('reject array content', () => {
470
+ expect(() => validateAuthorsMapFile([])).toThrowErrorMatchingInlineSnapshot(
471
+ // TODO improve this error message
472
+ `"\\"value\\" must be of type object"`,
473
+ );
474
+ });
475
+
476
+ test('reject flat author', () => {
477
+ expect(() =>
478
+ validateAuthorsMapFile({name: 'Sébastien'}),
479
+ ).toThrowErrorMatchingInlineSnapshot(
480
+ // TODO improve this error message
481
+ `"\\"name\\" must be of type object"`,
482
+ );
483
+ });
484
+
485
+ test('reject non-map author', () => {
486
+ const authorsMap: AuthorsMap = {
487
+ // @ts-expect-error: for tests
488
+ slorber: [],
489
+ };
490
+ expect(() =>
491
+ validateAuthorsMapFile(authorsMap),
492
+ ).toThrowErrorMatchingInlineSnapshot(
493
+ `"\\"slorber\\" must be of type object"`,
494
+ );
495
+ });
496
+ });
497
+
498
+ describe('getAuthorsMapFilePath', () => {
499
+ const fixturesDir = path.join(
500
+ __dirname,
501
+ '__fixtures__/getAuthorsMapFilePath',
502
+ );
503
+ const contentPathYml1 = path.join(fixturesDir, 'contentPathYml1');
504
+ const contentPathYml2 = path.join(fixturesDir, 'contentPathYml2');
505
+ const contentPathJson1 = path.join(fixturesDir, 'contentPathJson1');
506
+ const contentPathJson2 = path.join(fixturesDir, 'contentPathJson2');
507
+ const contentPathEmpty = path.join(fixturesDir, 'contentPathEmpty');
508
+ const contentPathNestedYml = path.join(fixturesDir, 'contentPathNestedYml');
509
+
510
+ test('getAuthorsMapFilePath returns localized Yml path in priority', async () => {
511
+ expect(
512
+ await getAuthorsMapFilePath({
513
+ authorsMapPath: 'authors.yml',
514
+ contentPaths: {
515
+ contentPathLocalized: contentPathYml1,
516
+ contentPath: contentPathYml2,
517
+ },
518
+ }),
519
+ ).toEqual(path.join(contentPathYml1, 'authors.yml'));
520
+ expect(
521
+ await getAuthorsMapFilePath({
522
+ authorsMapPath: 'authors.yml',
523
+ contentPaths: {
524
+ contentPathLocalized: contentPathYml2,
525
+ contentPath: contentPathYml1,
526
+ },
527
+ }),
528
+ ).toEqual(path.join(contentPathYml2, 'authors.yml'));
529
+ });
530
+
531
+ test('getAuthorsMapFilePath returns localized Json path in priority', async () => {
532
+ expect(
533
+ await getAuthorsMapFilePath({
534
+ authorsMapPath: 'authors.json',
535
+ contentPaths: {
536
+ contentPathLocalized: contentPathJson1,
537
+ contentPath: contentPathJson2,
538
+ },
539
+ }),
540
+ ).toEqual(path.join(contentPathJson1, 'authors.json'));
541
+ expect(
542
+ await getAuthorsMapFilePath({
543
+ authorsMapPath: 'authors.json',
544
+ contentPaths: {
545
+ contentPathLocalized: contentPathJson2,
546
+ contentPath: contentPathJson1,
547
+ },
548
+ }),
549
+ ).toEqual(path.join(contentPathJson2, 'authors.json'));
550
+ });
551
+
552
+ test('getAuthorsMapFilePath returns unlocalized Yml path as fallback', async () => {
553
+ expect(
554
+ await getAuthorsMapFilePath({
555
+ authorsMapPath: 'authors.yml',
556
+ contentPaths: {
557
+ contentPathLocalized: contentPathEmpty,
558
+ contentPath: contentPathYml2,
559
+ },
560
+ }),
561
+ ).toEqual(path.join(contentPathYml2, 'authors.yml'));
562
+ });
563
+
564
+ test('getAuthorsMapFilePath returns unlocalized Json path as fallback', async () => {
565
+ expect(
566
+ await getAuthorsMapFilePath({
567
+ authorsMapPath: 'authors.json',
568
+ contentPaths: {
569
+ contentPathLocalized: contentPathEmpty,
570
+ contentPath: contentPathJson1,
571
+ },
572
+ }),
573
+ ).toEqual(path.join(contentPathJson1, 'authors.json'));
574
+ });
575
+
576
+ test('getAuthorsMapFilePath can return undefined (file not found)', async () => {
577
+ expect(
578
+ await getAuthorsMapFilePath({
579
+ authorsMapPath: 'authors.json',
580
+ contentPaths: {
581
+ contentPathLocalized: contentPathEmpty,
582
+ contentPath: contentPathYml1,
583
+ },
584
+ }),
585
+ ).toBeUndefined();
586
+ expect(
587
+ await getAuthorsMapFilePath({
588
+ authorsMapPath: 'authors.yml',
589
+ contentPaths: {
590
+ contentPathLocalized: contentPathEmpty,
591
+ contentPath: contentPathJson1,
592
+ },
593
+ }),
594
+ ).toBeUndefined();
595
+ });
596
+
597
+ test('getAuthorsMapFilePath can return nested path', async () => {
598
+ expect(
599
+ await getAuthorsMapFilePath({
600
+ authorsMapPath: 'sub/folder/authors.yml',
601
+ contentPaths: {
602
+ contentPathLocalized: contentPathEmpty,
603
+ contentPath: contentPathNestedYml,
604
+ },
605
+ }),
606
+ ).toEqual(path.join(contentPathNestedYml, 'sub/folder/authors.yml'));
607
+ });
608
+ });