7
7
8
8
import { fromPartial , type PartialDeep } from '@total-typescript/shoehorn' ;
9
9
import { getBlogPostAuthors , groupBlogPostsByAuthorKey } from '../authors' ;
10
- import type { AuthorsMap , BlogPost } from '@docusaurus/plugin-content-blog' ;
10
+ import type {
11
+ AuthorAttributes ,
12
+ AuthorsMap ,
13
+ BlogPost ,
14
+ } from '@docusaurus/plugin-content-blog' ;
11
15
12
16
function post ( partial : PartialDeep < BlogPost > ) : BlogPost {
13
17
return fromPartial ( partial ) ;
@@ -268,11 +272,176 @@ describe('getBlogPostAuthors', () => {
268
272
] ) ;
269
273
} ) ;
270
274
271
- it ( 'can read authors Author' , ( ) => {
275
+ it ( 'read different values from socials' , ( ) => {
276
+ function testSocials ( socials : AuthorAttributes [ 'socials' ] | undefined ) {
277
+ return getBlogPostAuthors ( {
278
+ frontMatter : {
279
+ authors : {
280
+ name : 'Sébastien Lorber' ,
281
+ title : 'maintainer' ,
282
+ socials,
283
+ } ,
284
+ } ,
285
+ authorsMap : undefined ,
286
+ baseUrl : '/' ,
287
+ } ) ;
288
+ }
289
+
290
+ // @ts -expect-error test
291
+ expect ( ( ) => testSocials ( null ) ) . not . toThrow ( ) ;
292
+ // @ts -expect-error test
293
+ expect ( testSocials ( null ) ) . toEqual ( [
294
+ {
295
+ name : 'Sébastien Lorber' ,
296
+ title : 'maintainer' ,
297
+ imageURL : undefined ,
298
+ socials : { } ,
299
+ key : null ,
300
+ page : null ,
301
+ } ,
302
+ ] ) ;
303
+ expect ( ( ) => ( ) => testSocials ( undefined ) ) . not . toThrow ( ) ;
304
+ // @ts -expect-error test
305
+ expect ( ( ) => testSocials ( { twitter : undefined } ) )
306
+ . toThrowErrorMatchingInlineSnapshot ( `
307
+ "Author socials should be usernames/userIds/handles, or fully qualified HTTP(s) absolute URLs.
308
+ Social platform 'twitter' has illegal value 'undefined'"
309
+ ` ) ;
310
+ expect (
311
+ // @ts -expect-error test
312
+ ( ) => testSocials ( { twitter : null } ) ,
313
+ ) . toThrowErrorMatchingInlineSnapshot ( `
314
+ "Author socials should be usernames/userIds/handles, or fully qualified HTTP(s) absolute URLs.
315
+ Social platform 'twitter' has illegal value 'null'"
316
+ ` ) ;
317
+ } ) ;
318
+
319
+ it ( 'can read empty socials' , ( ) => {
320
+ expect (
321
+ getBlogPostAuthors ( {
322
+ frontMatter : {
323
+ authors : {
324
+ name : 'Sébastien Lorber' ,
325
+ title : 'maintainer' ,
326
+ socials : { } ,
327
+ } ,
328
+ } ,
329
+ authorsMap : undefined ,
330
+ baseUrl : '/' ,
331
+ } ) ,
332
+ ) . toEqual ( [
333
+ {
334
+ name : 'Sébastien Lorber' ,
335
+ title : 'maintainer' ,
336
+ imageURL : undefined ,
337
+ socials : { } ,
338
+ key : null ,
339
+ page : null ,
340
+ } ,
341
+ ] ) ;
342
+ } ) ;
343
+
344
+ it ( 'can normalize full socials from Author' , ( ) => {
345
+ expect (
346
+ getBlogPostAuthors ( {
347
+ frontMatter : {
348
+ authors : {
349
+ name : 'Sébastien Lorber' ,
350
+ title : 'maintainer' ,
351
+ socials : {
352
+ github : 'https://github.com/slorber' ,
353
+ linkedin : 'https://www.linkedin.com/in/sebastienlorber/' ,
354
+ stackoverflow : 'https://stackoverflow.com/users/82609' ,
355
+ twitter : 'https://twitter.com/sebastienlorber' ,
356
+ x : 'https://x.com/sebastienlorber' ,
357
+ } ,
358
+ } ,
359
+ } ,
360
+ authorsMap : undefined ,
361
+ baseUrl : '/' ,
362
+ } ) ,
363
+ ) . toEqual ( [
364
+ {
365
+ name : 'Sébastien Lorber' ,
366
+ title : 'maintainer' ,
367
+ imageURL : undefined ,
368
+ key : null ,
369
+ socials : {
370
+ github : 'https://github.com/slorber' ,
371
+ linkedin : 'https://www.linkedin.com/in/sebastienlorber/' ,
372
+ stackoverflow : 'https://stackoverflow.com/users/82609' ,
373
+ twitter : 'https://twitter.com/sebastienlorber' ,
374
+ x : 'https://x.com/sebastienlorber' ,
375
+ } ,
376
+ page : null ,
377
+ } ,
378
+ ] ) ;
379
+ } ) ;
380
+
381
+ it ( 'can normalize handle socials from Author' , ( ) => {
382
+ expect (
383
+ getBlogPostAuthors ( {
384
+ frontMatter : {
385
+ authors : {
386
+ name : 'Sébastien Lorber' ,
387
+ title : 'maintainer' ,
388
+ socials : {
389
+ github : 'slorber' ,
390
+ x : 'sebastienlorber' ,
391
+ linkedin : 'sebastienlorber' ,
392
+ stackoverflow : '82609' ,
393
+ twitter : 'sebastienlorber' ,
394
+ } ,
395
+ } ,
396
+ } ,
397
+ authorsMap : undefined ,
398
+ baseUrl : '/' ,
399
+ } ) ,
400
+ ) . toEqual ( [
401
+ {
402
+ name : 'Sébastien Lorber' ,
403
+ title : 'maintainer' ,
404
+ imageURL : undefined ,
405
+ key : null ,
406
+ socials : {
407
+ github : 'https://github.com/slorber' ,
408
+ linkedin : 'https://www.linkedin.com/in/sebastienlorber/' ,
409
+ stackoverflow : 'https://stackoverflow.com/users/82609' ,
410
+ twitter : 'https://twitter.com/sebastienlorber' ,
411
+ x : 'https://x.com/sebastienlorber' ,
412
+ } ,
413
+ page : null ,
414
+ } ,
415
+ ] ) ;
416
+ } ) ;
417
+
418
+ it ( 'can normalize socials from Author[]' , ( ) => {
272
419
expect (
273
420
getBlogPostAuthors ( {
274
421
frontMatter : {
275
- authors : { name : 'Sébastien Lorber' , title : 'maintainer' } ,
422
+ authors : [
423
+ {
424
+ name : 'Sébastien Lorber' ,
425
+ title : 'maintainer' ,
426
+ socials : {
427
+ github : 'slorber' ,
428
+ x : 'sebastienlorber' ,
429
+ linkedin : 'sebastienlorber' ,
430
+ stackoverflow : '82609' ,
431
+ twitter : 'sebastienlorber' ,
432
+ } ,
433
+ } ,
434
+ {
435
+ name : 'Seb' ,
436
+ socials : {
437
+ github : 'https://github.com/slorber' ,
438
+ linkedin : 'https://www.linkedin.com/in/sebastienlorber/' ,
439
+ stackoverflow : 'https://stackoverflow.com/users/82609' ,
440
+ twitter : 'https://twitter.com/sebastienlorber' ,
441
+ x : 'https://x.com/sebastienlorber' ,
442
+ } ,
443
+ } ,
444
+ ] ,
276
445
} ,
277
446
authorsMap : undefined ,
278
447
baseUrl : '/' ,
@@ -283,6 +452,26 @@ describe('getBlogPostAuthors', () => {
283
452
title : 'maintainer' ,
284
453
imageURL : undefined ,
285
454
key : null ,
455
+ socials : {
456
+ github : 'https://github.com/slorber' ,
457
+ linkedin : 'https://www.linkedin.com/in/sebastienlorber/' ,
458
+ stackoverflow : 'https://stackoverflow.com/users/82609' ,
459
+ twitter : 'https://twitter.com/sebastienlorber' ,
460
+ x : 'https://x.com/sebastienlorber' ,
461
+ } ,
462
+ page : null ,
463
+ } ,
464
+ {
465
+ name : 'Seb' ,
466
+ imageURL : undefined ,
467
+ key : null ,
468
+ socials : {
469
+ github : 'https://github.com/slorber' ,
470
+ linkedin : 'https://www.linkedin.com/in/sebastienlorber/' ,
471
+ stackoverflow : 'https://stackoverflow.com/users/82609' ,
472
+ twitter : 'https://twitter.com/sebastienlorber' ,
473
+ x : 'https://x.com/sebastienlorber' ,
474
+ } ,
286
475
page : null ,
287
476
} ,
288
477
] ) ;
@@ -293,8 +482,13 @@ describe('getBlogPostAuthors', () => {
293
482
getBlogPostAuthors ( {
294
483
frontMatter : {
295
484
authors : [
296
- { name : 'Sébastien Lorber' , title : 'maintainer' } ,
297
- { name : 'Yangshun Tay' } ,
485
+ {
486
+ name : 'Sébastien Lorber' ,
487
+ title : 'maintainer' ,
488
+ } ,
489
+ {
490
+ name : 'Yangshun Tay' ,
491
+ } ,
298
492
] ,
299
493
} ,
300
494
authorsMap : undefined ,
@@ -306,9 +500,16 @@ describe('getBlogPostAuthors', () => {
306
500
title : 'maintainer' ,
307
501
imageURL : undefined ,
308
502
key : null ,
503
+ socials : { } ,
504
+ page : null ,
505
+ } ,
506
+ {
507
+ name : 'Yangshun Tay' ,
508
+ imageURL : undefined ,
509
+ socials : { } ,
510
+ key : null ,
309
511
page : null ,
310
512
} ,
311
- { name : 'Yangshun Tay' , imageURL : undefined , key : null , page : null } ,
312
513
] ) ;
313
514
} ) ;
314
515
@@ -323,7 +524,12 @@ describe('getBlogPostAuthors', () => {
323
524
title : 'Yangshun title local override' ,
324
525
extra : 42 ,
325
526
} ,
326
- { name : 'Alexey' } ,
527
+ {
528
+ name : 'Alexey' ,
529
+ socials : {
530
+ github : 'lex111' ,
531
+ } ,
532
+ } ,
327
533
] ,
328
534
} ,
329
535
authorsMap : {
@@ -355,10 +561,19 @@ describe('getBlogPostAuthors', () => {
355
561
name : 'Yangshun Tay' ,
356
562
title : 'Yangshun title local override' ,
357
563
extra : 42 ,
564
+ socials : { } ,
358
565
imageURL : undefined ,
359
566
page : null ,
360
567
} ,
361
- { name : 'Alexey' , imageURL : undefined , key : null , page : null } ,
568
+ {
569
+ name : 'Alexey' ,
570
+ imageURL : undefined ,
571
+ key : null ,
572
+ page : null ,
573
+ socials : {
574
+ github : 'https://github.com/lex111' ,
575
+ } ,
576
+ } ,
362
577
] ) ;
363
578
} ) ;
364
579
@@ -627,6 +842,7 @@ describe('getBlogPostAuthors', () => {
627
842
imageURL : './ozaki.png' ,
628
843
key : null ,
629
844
page : null ,
845
+ socials : { } ,
630
846
} ,
631
847
] ) ;
632
848
expect ( ( ) => withoutBaseUrlTest ) . not . toThrow ( ) ;
@@ -635,6 +851,7 @@ describe('getBlogPostAuthors', () => {
635
851
imageURL : './ozaki.png' ,
636
852
key : null ,
637
853
page : null ,
854
+ socials : { } ,
638
855
} ,
639
856
] ) ;
640
857
} ) ;
@@ -654,6 +871,7 @@ describe('getBlogPostAuthors', () => {
654
871
imageURL : '/ozaki.png' ,
655
872
key : null ,
656
873
page : null ,
874
+ socials : { } ,
657
875
} ,
658
876
] ) ;
659
877
} ) ;
@@ -673,6 +891,7 @@ describe('getBlogPostAuthors', () => {
673
891
imageURL : '/img/ozaki.png' ,
674
892
key : null ,
675
893
page : null ,
894
+ socials : { } ,
676
895
} ,
677
896
] ) ;
678
897
} ) ;
@@ -692,6 +911,7 @@ describe('getBlogPostAuthors', () => {
692
911
imageURL : '/img/ozaki.png' ,
693
912
key : null ,
694
913
page : null ,
914
+ socials : { } ,
695
915
} ,
696
916
] ) ;
697
917
} ) ;
@@ -711,6 +931,7 @@ describe('getBlogPostAuthors', () => {
711
931
imageURL : '/img/img/ozaki.png' ,
712
932
key : null ,
713
933
page : null ,
934
+ socials : { } ,
714
935
} ,
715
936
] ) ;
716
937
} ) ;
0 commit comments