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

Dynamic sync for contributors page #33

Merged
merged 1 commit into from
Dec 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
Binary file added pro1/blog/static/blog/images/codingBG.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed pro1/blog/static/blog/images/gopavasanth.jpeg
Binary file not shown.
Binary file removed pro1/blog/static/blog/images/gutsytechster.jpeg
Binary file not shown.
Binary file removed pro1/blog/static/blog/images/harry-hov.jpeg
Binary file not shown.
Binary file removed pro1/blog/static/blog/images/monsij.jpeg
Binary file not shown.
Binary file removed pro1/blog/static/blog/images/r3trd.jpeg
Binary file not shown.
223 changes: 223 additions & 0 deletions pro1/blog/static/blog/js/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
function querystring() {
var href = window.location.href, kv;
var params = href.slice(href.indexOf('?') + 1).split('&');
var qs = [];

for (i = 0; i < params.length; i++) {
kv = params[i].split('=');
qs.push(kv[0]);
qs[kv[0]] = kv[1];
}
return qs;
}

var qs = querystring();

(function(d) {
var baseurl = 'https://api.github.com/', i;

function store(key, value) {
try {
if (window.localStorage) {
if (value) {
value._timestamp = new Date().valueOf();
localStorage[key] = JSON.stringify(value);
} else {
var ret = localStorage[key];
if (ret) {
return JSON.parse(ret);
}
return null;
}
}
} catch(e) {}
}

function valueof(data, key) {
var ret = data;
var bits = key.split('.');
for (var j = 0; j < bits.length; j++) {
if (ret) {
ret = ret[bits[j]];
} else {
break;
}
}
if (ret === undefined || ret === null) {
return '';
}
return ret;
}

function template(type, data) {
var t = d.getElementById(type + '-card');
var regex = /{([^}]+)}/g;
var text = t.innerHTML;
var m = text.match(regex);
for (i = 0; i < m.length; i++) {
text = text.replace(m[i], valueof(data, m[i].slice(1, -1)));
}
return text;
}

function request(url, callback) {
var cache = store(url);
if (cache && cache._timestamp) {
// cache in 10s
if (new Date().valueOf() - cache._timestamp < 10000) {
return callback(cache);
}
}
if (qs.client_id && qs.client_secret) {
url += '?client_id=' + qs.client_id + '&client_secret=' + qs.client_secret;
}
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function() {
callback(JSON.parse(xhr.response));
};
xhr.send();
}

function linky(card, identity) {
var links = card.getElementsByTagName('a');
for (i = 0; i < links.length; i++) {
(function(link) {
link.target = '_' + (qs.target || 'top');
})(links[i]);
}
d.body.appendChild(card);
d.body.className = 'ready';
if (parent !== self && parent.postMessage) {
var height = Math.max(
d.body.scrollHeight,
d.documentElement.scrollHeight,
d.body.offsetHeight,
d.documentElement.offsetHeight,
d.body.clientHeight,
d.documentElement.clientHeight
);
parent.postMessage({
height: height,
sender: qs.identity || '*'
}, '*');
}
}

function userCard(user) {
var url = baseurl + 'users/' + user;
request(url, function(data) {
data = data || {};
var message = data.message;
var defaults = '0';
if (message) {
data = store(url) || data;
defaults = '?';
} else {
store(url, data);
}
data.login = user;
data.name = escape(data.name || user);
data.public_repos = numberic(data.public_repos) || defaults;
data.public_gists = numberic(data.public_gists) || defaults;
data.followers = numberic(data.followers) || defaults;

var job = 'Not available for hire.';
if (data.hireable) {
var link = '';
if (data.email) {
link = 'mailto:' + data.email;
} else if (data.blog) {
link = data.blog;
} else {
link = data.html_url;
}
job = '<a href="' + link + '">Available for hire.</a>';
}
if (message) {
job = message;
}
data.job = job;

var card = d.createElement('div');
card.className = 'github-card user-card';
card.innerHTML = template('user', data);
linky(card);
});
}

function repoCard(user, repo) {
var url = baseurl + 'repos/' + user + '/' + repo;
request(url, function(data) {
data = data || {};
var message = data.message;
var defaults = '0';
if (message) {
data = store(url) || data;
defaults = '?';
} else {
store(url, data);
}
data.login = user;

data.avatar_url = '';
if (data.owner && data.owner.avatar_url) {
data.avatar_url = data.owner.avatar_url;
}
data.forks_count = numberic(data.forks_count) || defaults;
data.watchers_count = numberic(data.watchers_count) || defaults;
if (data.fork) {
data.action = 'Forked by ';
} else {
data.action = 'Created by ';
}
var description = data.description;
if (!description && data.source) {
description = data.source.description;
}
if (!description && message) {
description = message;
}
data.description = escape(description) || 'No description';
var homepage = data.homepage;
if (!homepage && data.source) {
homepage = data.source.homepage;
}
if (homepage) {
data.homepage = ' <a href="' + homepage + '">' + homepage.replace(/https?:\/\//, '').replace(/\/$/, '') + '</a>';
} else {
data.homepage = '';
}

var card = d.createElement('div');
card.className = 'github-card repo-card';
card.innerHTML = template('repo', data);
linky(card);
});
}

function errorCard() {
}

function numberic(num) {
if (!num) return null;
if (num === 1000) return 1;
if (num < 1000) return num;
num = num / 1000;
if (num > 10) return parseInt(num, 10) + 'k';
return num.toFixed(1) + 'k';
}

if (!qs.user) {
errorCard();
} else if (qs.repo) {
repoCard(qs.user, qs.repo);
} else {
userCard(qs.user);
}

function escape(text) {
return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

})(document);
1 change: 1 addition & 0 deletions pro1/blog/static/blog/jsGit/widget.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 12 additions & 84 deletions pro1/blog/templates/blog/contributor.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,17 @@
{% block content %}
<h1> Contributors </h1>
<br>

<div class="row text-center">
<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/monsij.jpeg' %}" width="400" height="300">
<p><strong>Monsij Biswal</strong></p>
<p><i>Owner</i></p>
<a href="https://github.com/monsij" target="_blank"><button class="btn">@monsij</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/r3trd.jpeg' %}" width="400" height="300">
<p><strong>Satyajit Das</strong></p>
<p><i>Owner</i></p>
<a href="https://github.com/r3trd" target="_blank"><button class="btn">@r3trd</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/harry-hov.jpeg' %}" width="400" height="300">
<p><strong>Hariom Verma</strong></p>
<p><i>Contributor</i></p>
<a href="https://github.com/harry-hov" target="_blank"><button class="btn">@harry-hov</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/Tiyas-13.jpeg' %}" width="400" height="300">
<p><strong>Tiyas Dey</strong></p>
<p><i>Contributor</i></p>
<a href="https://github.com/Tiyas-13" target="_blank"><button class="btn">@Tiyas-13</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/gutsytechster.jpeg' %}" width="400" height="300">
<p><strong>Prashant Sharma</strong></p>
<p><i>Contributor</i></p>
<a href="https://github.com/gutsytechster" target="_blank"><button class="btn">@gutsytechster</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/gopavasanth.jpeg' %}" width="400" height="300">
<p><strong>Gopa Vasanth</strong></p>
<p><i>Contributor</i></p>
<a href="https://github.com/gopavasanth" target="_blank"><button class="btn">@gopavasanth</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/BhanuPrakashNani.jpeg' %}" width="400" height="300">
<p><strong>Bhanu Prakash Poluparthi</strong></p>
<p><i>Contributor</i></p>
<a href="https://github.com/BhanuPrakashNani" target="_blank"><button class="btn">@BhanuPrakashNani</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/arpit3018.jpeg' %}" width="400" height="300">
<p><strong>Arpit Agrawal</strong></p>
<p><i>Contributor</i></p>
<a href="https://github.com/arpit3018" target="_blank"><button class="btn">@arpit3018</button></a>
</div>
</div>

<div class="col-sm-4">
<div class="thumbnail">
<img src="{% static 'blog/images/nguptaa.jpeg' %}" width="400" height="300">
<p><strong>Nikhil Gupta</strong></p>
<p><i>Contributor</i></p>
<a href="https://github.com/nguptaa" target="_blank"><button class="btn">@nguptaa</button></a>
</div>
</div>
</div>

<style>
body{
padding-left:5em ;
}
</style>

<div class="github-card" data-github="monsij" data-width="240" data-height="300" data-theme="medium"></div>
<div class="github-card" data-github="r3trd" data-width="240" data-height="300" data-theme="medium"></div>
<div class="github-card" data-github="harry-hov" data-width="240" data-height="300" data-theme="medium"></div>
<div class="github-card" data-github="gutsytechster" data-width="240" data-height="300" data-theme="medium"></div>
<div class="github-card" data-github="gopavasanth" data-width="240" data-height="300" data-theme="medium"></div>
<script src="{% static 'blog/jsGit/widget.js' %}"></script>

{% endblock content %}
Loading