Skip to content
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

Added contributors widget #1098

Merged
merged 3 commits into from Jul 7, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

Refactor widget to separate file. Added it to more pages

  • Loading branch information...
sake92 committed Jul 6, 2018
commit ba57de5cc294f74a39f1401f3d51d0d6f94942ad
@@ -0,0 +1,4 @@
<div class="content-contributors">
<h3>Contributors to this page:</h3>
<div id="contributors" class="contributors-container"></div>
</div>
@@ -3,6 +3,8 @@
<div class="content-primary">
<div class="inner-box">
{{content}}

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

@@ -30,6 +30,8 @@
{% endfor %}
</ul>
{% endif %}

{% include contributors-list.html %}
</div>
</div>
</div>
@@ -8,6 +8,8 @@
<div class="content-primary documentation glossary">
<div class="inner-box">
{{content}}

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

@@ -9,6 +9,8 @@
<div class="content-primary documentation">
<div class="inner-box">
{{content}}

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

@@ -8,6 +8,8 @@
<div class="content-primary documentation">
<div class="inner-box">
{{content}}

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

@@ -9,6 +9,8 @@
<div class="content-primary documentation style-guide">
<div class="inner-box">
{{content}}

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

@@ -21,10 +21,7 @@
{% endif %}
</div>

<div class="content-contributors">
<h3>Contributors to this page:</h3>
<div id="contributors" class="contributors-container"></div>
</div>
{% include contributors-list.html %}
</div>
</div>

@@ -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;
}
}
}
}
@@ -51,29 +51,6 @@
}
}

.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 {
@@ -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';
@@ -527,15 +527,40 @@ $(document).ready(function(){
// 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 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('.'));
thisPageUrl = '_' + thisPageUrl + '.md';
// e.g. https://api.github.com/repos/scala/docs.scala-lang/commits?path=README
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 = [];
let res = data.forEach(commit => {
data.forEach(commit => {
// add if not already in array
let addedToList = contributorsUnique.find(c => {
let matches = c.authorName == commit.commit.author.name;
@@ -549,7 +574,7 @@ $(document).ready(function () {
// first set fallback properties
let authorName = commit.commit.author.name;
let authorLink = '';
let authorImageLink = 'https://github.com/identicons/' + commit.commit.author.name + '.png';
let authorImageLink = identiconsUrl + '/' + commit.commit.author.name + '.png';
// if author present, fill these preferably
if (commit.author) {
authorName = commit.author.login;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.