forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_contributors.js
67 lines (56 loc) · 2.01 KB
/
show_contributors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
Shows a list of the contributors to a Phobos module
It queries the backend contribs.dlang.io
Backend source: https://github.com/wilzbach/phobos-contribs
License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0
Authors: Sebastian Wilzbach
*/
// find out whether the current page is a module or package
function isPackage()
{
return $('.tip.smallprint a[href*="package.d"]').length > 0;
}
$(document).ready(function()
{
// only for library documentation
if (!$('body').hasClass("std"))
return;
// for index modules (package.d), we want to display all contributors of the package
var modulePath = document.body.id.replace(/[.]/g, '/');
if (!isPackage())
modulePath += '.d';
// enable only for std, etc and core
var repo;
if (modulePath.indexOf("core") == 0 || modulePath.indexOf("object") == 0)
{
repo = "druntime";
modulePath = "src/" + modulePath;
}
else if (modulePath.indexOf("std") == 0 || modulePath.indexOf("etc") == 0)
{
repo = "phobos";
}
else
{
return;
}
$.getJSON( "https://contribs.dlang.io/contributors/file/dlang/" + repo + "?file=" + modulePath, function(contributors)
{
var posToInsert = $('#copyright');
var contentNode = $("<div id='contributors-github'></div>");
var totalContributors = contributors.length;
// ignore invalid files
if (totalContributors == 0)
return;
contentNode.append("<h3>" + totalContributors + " Contributors</h3>");
// list contributors with github avatar
$.each(contributors, function(i, contributor)
{
var contributorDiv = '<a href=' + contributor.html_url +' target="_blank">';
contributorDiv += '<img src="'+ contributor.avatar_url +'&size=40" height="40" width=40" alt="' + contributor.login + '"/>';
contributorDiv += "</a>";
contentNode.append(contributorDiv);
});
contentNode.insertBefore(posToInsert);
});
});