-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathcatalogue-details.html
147 lines (134 loc) · 5.58 KB
/
catalogue-details.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
layout: catalogue
---
<style>
@import url("/stylesheets/catalogue.css");
</style>
<p id="loading_status" v-if="show"><i :class="icon"></i> (( message ))</p>
<div id="repo_details" class="content" v-if="ready">
<div class="row">
<div class="col">
<a class="go-back" href="{{ site.baseurl }}/"><i class="fa fa-caret-left"></i> Go back</a>
</div>
</div>
<div class="row">
<div class="col">
<div class="media">
<img class="m-3 logo-small" :src="logo" alt="Logo">
<div class="media-body">
<h2 class="display-4 mt-0 mb-1"> (( repo.name ))</h2>
<p class="lead">by <a target="_blank" :href="repo.owner.html_url">(( repo.owner.login ))</a></p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-md-8">
<div v-html="compiledReadme"></div>
</div>
<div class="col-12 col-md-4">
<div id="about">
<a class="btn btn-lg btn-success" target="_blank" :href="repo.html_url + '/archive/' + repo.default_branch + '.zip'">Download <i class="fa fa-download"></i></a>
<h3>About this repo</h3>
<ul class="list-unstyled">
<li><i class="fas fa-globe fa-fw"></i> Repo ID: <span class="float-right">(( repo.id ))</span></li>
<li><i class="far fa-user-circle fa-fw"></i> Author: <span class="float-right">(( repo.owner.login ))</span></li>
<li><i class="fab fa-github fa-fw"></i> Repo: <a class="float-right" target="_blank" :href="repo.html_url">View on Github <i class="fa fa-external-link-alt"></i></a></li>
<li><i class="fas fa-eye fa-fw"></i> Watchers: <span class="float-right">(( repo.watchers_count ))</span></li>
<li><i class="fas fa-star fa-fw"></i> Stars : <span class="float-right">(( repo.stargazers_count ))</span></li>
<li><i class="fas fa-code-branch fa-fw"></i> Forks: <span class="float-right">(( repo.forks_count ))</span></li>
<li><i class="fas fa-clock fa-fw"></i> Created: <span class="float-right">(( repo.created_at | dateFromNow ))</span></li>
<li><i class="fas fa-clock fa-fw"></i> Last update: <span class="float-right">(( repo.updated_at | dateFromNow ))</li>
<li><i class="fas fa-balance-scale fa-fw"></i> License: <span class="float-right" v-if="repo.license">(( repo.license.spdx_id ))</span></li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/marked@0.3.6"></script>
<script>
var mDetails = new Vue({
el: '#repo_details',
delimiters: ['((', '))'],
data: {
logo: '',
repo: null,
readme: '',
ready: false
},
computed: {
compiledReadme: function () {
return marked(this.readme, { sanitize: false })
}
},
methods: {
loadInfo: function(info) {
if (info)
{
this.repo = info;
this.readme = this.repo.description || 'No description';
this.logo = this.repo.owner.avatar_url;
mStatus.hideMessage();
this.ready = true;
$.get(`https://raw.githubusercontent.com/${this.repo.full_name}/${this.repo.default_branch}/README.md`, (res) => {
this.readme = res ? res : this.repo.description;
});
let iconUrl = `https://raw.githubusercontent.com/${this.repo.full_name}/${this.repo.default_branch}/icon.png`;
$.get(iconUrl, (res) => {
this.logo = iconUrl;
});
// parent -> repo from which this was forked
// source -> original repo at the end of the chain
if (this.repo.fork && this.repo.source != null) {
Vue.set(mDetails.repo, 'owner', this.repo.source.owner);
}
} else {
mStatus.showError("Couldn't find the repo you requested :(");
}
}
},
filters: {
dateFromNow: function(date) {
return moment(date).fromNow();
}
}
});
var mStatus = new Vue({
el: '#loading_status',
delimiters: ['((', '))'],
data: {
message: '',
icon: '',
show: false
},
methods: {
hideMessage: function() {
this.show = false;
},
showError: function(msg) {
this.message = msg;
this.icon = 'far fa-times-circle';
this.show = true;
},
showLoading: function() {
this.message = "Loading repository...";
this.icon = 'fas fa-sync fa-spin';
this.show = true;
}
}
});
function getParameterByName(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
$(document).ready(() => {
mStatus.showLoading();
let id = getParameterByName('id');
if (id == undefined || isNaN(id))
{
mStatus.showError("Invalid repo ID");
}
$.getJSON(`https://api.github.com/repositories/${id}`, (json) => {
mDetails.loadInfo(json);
});
});
</script>