@@ -521,4 +521,58 @@ $(document).ready(function(){
521
521
$ ( "html, body" ) . animate ( { scrollTop : 0 } , 600 ) ;
522
522
return false ;
523
523
} ) ;
524
- } ) ;
524
+ } ) ;
525
+
526
+ //Contributors widget
527
+ // see https://stackoverflow.com/a/19200303/4496364
528
+ $ ( document ) . ready ( function ( ) {
529
+ let githubApiUrl = 'https://api.github.com/repos/scala/docs.scala-lang/commits' ;
530
+ // transform "/tour/basics.html" to "_ba/tour/basics.md";
531
+ let thisPageUrl = window . location . pathname ;
532
+ thisPageUrl = thisPageUrl . substring ( 1 , thisPageUrl . lastIndexOf ( '.' ) ) ;
533
+ thisPageUrl = '_' + thisPageUrl + '.md' ;
534
+ // e.g. https://api.github.com/repos/scala/docs.scala-lang/commits?path=README
535
+ let url = githubApiUrl + '?path=' + thisPageUrl ;
536
+ $ . get ( url , function ( data , status ) {
537
+
538
+ let contributorsUnique = [ ] ;
539
+ let res = data . forEach ( commit => {
540
+ // add if not already in array
541
+ let addedToList = contributorsUnique . find ( c => {
542
+ let matches = c . authorName == commit . commit . committer . name ;
543
+ if ( ! matches && commit . author ) {
544
+ matches = c . authorName == commit . author . login ;
545
+ }
546
+ return matches ;
547
+ } ) ;
548
+
549
+ if ( ! addedToList ) {
550
+ // first set fallback properties
551
+ let authorName = commit . commit . committer . name ;
552
+ let authorLink = 'mailto:' + commit . commit . committer . email ;
553
+ let authorImageLink = 'https://github.com/identicons/' + commit . commit . committer . name + '.png' ;
554
+ // if author present, fill these preferably
555
+ if ( commit . author ) {
556
+ authorName = commit . author . login ;
557
+ authorLink = commit . author . html_url ;
558
+ authorImageLink = commit . author . avatar_url ;
559
+ }
560
+ contributorsUnique . push ( {
561
+ 'authorName' : authorName ,
562
+ 'authorLink' : authorLink ,
563
+ 'authorImageLink' : authorImageLink
564
+ } ) ;
565
+ }
566
+ } ) ;
567
+
568
+ let contributorsHtml = '' ;
569
+ contributorsUnique . forEach ( contributor => {
570
+ let contributorHtml = '<div>' ;
571
+ contributorHtml += '<img src="' + contributor . authorImageLink + '">' ;
572
+ contributorHtml += '<a href="' + contributor . authorLink + '">' + contributor . authorName + '</a>' ;
573
+ contributorHtml += '</div>' ;
574
+ contributorsHtml += contributorHtml ;
575
+ } ) ;
576
+ $ ( '#contributors' ) . html ( contributorsHtml ) ;
577
+ } ) ;
578
+ } ) ;
0 commit comments