-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.html
68 lines (58 loc) · 1.9 KB
/
github.html
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
68
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: 'GET',
url:'https://api.github.com/users/kdr213/repos',
dataType: 'json',
success: function(data) {
$("#repos").html('');
console.log(data[0].pushed_at);
data.sort(function(a,b) {
a = new Date(a.pushed_at);
b = new Date(b.pushed_at);
return a>b ? -1 : a<b ? 1 : 0;
});
var repoHTML = "";
$.each(data, function(index, element){
repoHTML = `<div class="col-sm-4 masonry__item">
<a href="` + element.html_url + `" target="_blank">
<div class="boxed bg--white box-shadow">`
repoHTML += "<span>" + element.name + "</span>";
if(element.description) repoHTML += "<h5>" + element.description + "</h5>";
repoHTML+=
`<hr>
<p>Latest push: ` + formatDate(new Date(element.pushed_at)) + `<br>
Created: ` + formatDate(new Date(element.created_at)) +
`</p>
</div>
</a>
</div>`
//console.log(repoHTML);
$("#repos").append(repoHTML);
});
}
});
});
function formatDate(date) {
var monthNames = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
];
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
return day + ' ' + monthNames[monthIndex] + ' ' + year;
}
</script>
<section class="bg--secondary">
<div class="container github-container">
<div class="row">
<div class="masonry">
<div class="masonry__container masonry--active masonry--animate" id="repos">
</div>
</div>
</div>
</div>
</section>