Skip to content

Commit 6a6d384

Browse files
committed
Added contributors widget
1 parent e6eecc9 commit 6a6d384

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

_layouts/tour.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<a href="{{page.next-page}}.html"><strong>next</strong> &rarr;</a>
2121
{% endif %}
2222
</div>
23+
24+
<div class="content-contributors">
25+
<h3>Contributors to this page:</h3>
26+
<div id="contributors" class="contributors-container"></div>
27+
</div>
2328
</div>
2429
</div>
2530

_sass/layout/inner-main.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@
5151
}
5252
}
5353

54+
.content-contributors {
55+
.contributors-container {
56+
display: flex;
57+
flex-wrap: wrap;
58+
align-items: center;
59+
div {
60+
margin: 5px;
61+
a {
62+
vertical-align: middle;
63+
padding: 3px;
64+
text-decoration: none;
65+
}
66+
img {
67+
vertical-align: middle;
68+
width: 35px;
69+
height: 35px;
70+
margin-bottom: 0;
71+
border-radius: 7px;
72+
}
73+
}
74+
}
75+
}
76+
5477
.content-primary {
5578
.documentation,
5679
.tools {

resources/js/functions.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,58 @@ $(document).ready(function(){
521521
$("html, body").animate({ scrollTop: 0 }, 600);
522522
return false;
523523
});
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

Comments
 (0)