Skip to content

Added contributors widget #1098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _layouts/tour.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<a href="{{page.next-page}}.html"><strong>next</strong> &rarr;</a>
{% endif %}
</div>

<div class="content-contributors">
<h3>Contributors to this page:</h3>
<div id="contributors" class="contributors-container"></div>
</div>
</div>
</div>

Expand Down
23 changes: 23 additions & 0 deletions _sass/layout/inner-main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@
}
}

.content-contributors {
.contributors-container {
display: flex;
flex-wrap: wrap;
align-items: center;
div {
margin: 5px;
a {
vertical-align: middle;
padding: 3px;
text-decoration: none;
}
img {
vertical-align: middle;
width: 35px;
height: 35px;
margin-bottom: 0;
border-radius: 7px;
}
}
}
}

.content-primary {
.documentation,
.tools {
Expand Down
58 changes: 57 additions & 1 deletion resources/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,60 @@ $(document).ready(function(){
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
});
});

//Contributors widget
// see https://stackoverflow.com/a/19200303/4496364
$(document).ready(function () {
let githubApiUrl = 'https://api.github.com/repos/scala/docs.scala-lang/commits';
// transform "/tour/basics.html" to "_ba/tour/basics.md";
let thisPageUrl = window.location.pathname;
thisPageUrl = thisPageUrl.substring(1, thisPageUrl.lastIndexOf('.'));
thisPageUrl = '_' + thisPageUrl + '.md';
// e.g. https://api.github.com/repos/scala/docs.scala-lang/commits?path=README
let url = githubApiUrl + '?path=' + thisPageUrl;
$.get(url, function (data, status) {
let contributorsUnique = [];
let res = data.forEach(commit => {
// add if not already in array
let addedToList = contributorsUnique.find(c => {
let matches = c.authorName == commit.commit.author.name;
if (!matches && commit.author) {
matches = c.authorName == commit.author.login;
}
return matches;
});

if (!addedToList) {
// first set fallback properties
let authorName = commit.commit.author.name;
let authorLink = '';
let authorImageLink = 'https://github.com/identicons/' + commit.commit.author.name + '.png';
// if author present, fill these preferably
if (commit.author) {
authorName = commit.author.login;
authorLink = commit.author.html_url;
authorImageLink = commit.author.avatar_url;
}
contributorsUnique.push({
'authorName': authorName,
'authorLink': authorLink,
'authorImageLink': authorImageLink
});
}
});

let contributorsHtml = '';
contributorsUnique.forEach(contributor => {
let contributorHtml = '<div>';
contributorHtml += '<img src="' + contributor.authorImageLink + '">';
if (contributor.authorLink)
contributorHtml += '<a href="' + contributor.authorLink + '">' + contributor.authorName + '</a>';
else
contributorHtml += '<a>' + contributor.authorName + '</a>';
contributorHtml += '</div>';
contributorsHtml += contributorHtml;
});
$('#contributors').html(contributorsHtml);
});
});