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 all 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
4 changes: 4 additions & 0 deletions _includes/contributors-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="content-contributors">
<h3>Contributors to this page:</h3>
<div id="contributors" class="contributors-container"></div>
</div>
2 changes: 2 additions & 0 deletions _includes/inner-page-main-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<div class="content-primary">
<div class="inner-box">
{{content}}

{% include contributors-list.html %}
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions _layouts/cheatsheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
{% endfor %}
</ul>
{% endif %}

{% include contributors-list.html %}
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions _layouts/glossary.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<div class="content-primary documentation glossary">
<div class="inner-box">
{{content}}

{% include contributors-list.html %}
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions _layouts/multipage-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<div class="content-primary documentation">
<div class="inner-box">
{{content}}

{% include contributors-list.html %}
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions _layouts/singlepage-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<div class="content-primary documentation">
<div class="inner-box">
{{content}}

{% include contributors-list.html %}
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions _layouts/style-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<div class="content-primary documentation style-guide">
<div class="inner-box">
{{content}}

{% include contributors-list.html %}
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions _layouts/tour.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<a href="{{page.next-page}}.html"><strong>next</strong> &rarr;</a>
{% endif %}
</div>

{% include contributors-list.html %}
</div>
</div>

Expand Down
22 changes: 22 additions & 0 deletions _sass/layout/content-contributors.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.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;
}
}
}
}
3 changes: 2 additions & 1 deletion resources/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
@import 'layout/books';
@import 'layout/training-events';
@import 'layout/blog';
@import 'layout/download'; // COMPONENTS
@import 'layout/download';
@import 'layout/content-contributors'; // COMPONENTS
//------------------------------------------------
//------------------------------------------------
@import 'components/buttons';
Expand Down
83 changes: 82 additions & 1 deletion resources/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,85 @@ $(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';
let identiconsUrl = 'https://github.com/identicons';
/* - we need to transform "/tour/basics.html" to "_ba/tour/basics.md"
* - some files aren't prefixed with underscore, see rootFiles
* - some files are placed in _overviews but rendered to its folder, see overviewsFolders
*/

let rootFiles = ['getting-started', 'learn', 'glossary'];
let overviewsFolders = ['FAQ', 'cheatsheets', 'collections', 'compiler-options',
'core', 'jdk-compatibility', 'macros', 'parallel-collections',
'plugins', 'quasiquotes', 'reflection',
'repl', 'scaladoc', 'tutorials'
];

let thisPageUrl = window.location.pathname;
// chop off beginning slash and ending .html
thisPageUrl = thisPageUrl.substring(1, thisPageUrl.lastIndexOf('.'));
let isRootFile = rootFiles.some(rf => thisPageUrl.startsWith(rf));
let isInOverviewsFolder = overviewsFolders.some(of => thisPageUrl.startsWith(of));
if(isRootFile) {
thisPageUrl = thisPageUrl + '.md';
} else if(isInOverviewsFolder) {
thisPageUrl = '_overviews/'+ thisPageUrl + '.md';
} else {
thisPageUrl = '_' + thisPageUrl + '.md';
}

let url = githubApiUrl + '?path=' + thisPageUrl;
$.get(url, function (data, status) {
if(!data || data.length < 1) {
$('.content-contributors').html(''); // clear content
return false; // break
}
let contributorsUnique = [];
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 = identiconsUrl + '/' + 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);
});
});