Suggest twitter badges
This commit is contained in:
parent
7031e17a0c
commit
9882531c0e
34
suggest.js
34
suggest.js
|
@ -19,30 +19,42 @@ var suggest = function(data, end, ask) {
|
|||
try {
|
||||
var url = nodeUrl.parse(data.url);
|
||||
} catch(e) { end({err:''+e}); return; }
|
||||
|
||||
if (url.hostname === 'github.com') {
|
||||
github(url, end);
|
||||
}
|
||||
findSuggestions(url, end);
|
||||
};
|
||||
|
||||
// url: string
|
||||
// cb: function({badges})
|
||||
var github = function(url, cb) {
|
||||
var findSuggestions = function(url, cb) {
|
||||
var userRepo = url.pathname.slice(1).split('/');
|
||||
var user = userRepo[0];
|
||||
var repo = userRepo[1];
|
||||
Promise.all([
|
||||
githubIssues(user, repo),
|
||||
githubForks(user, repo),
|
||||
githubStars(user, repo),
|
||||
githubLicense(user, repo),
|
||||
]).then(function(badges) {
|
||||
var promises = [];
|
||||
if (url.hostname === 'github.com') {
|
||||
promises = promises.concat([
|
||||
githubIssues(user, repo),
|
||||
githubForks(user, repo),
|
||||
githubStars(user, repo),
|
||||
githubLicense(user, repo),
|
||||
]);
|
||||
}
|
||||
promises.push(twitterPage(url));
|
||||
Promise.all(promises).then(function(badges) {
|
||||
cb({badges:badges.filter(function(b) { return b != null; })});
|
||||
}).catch(function(err) {
|
||||
cb({badges:[], err:err});
|
||||
});
|
||||
};
|
||||
|
||||
var twitterPage = function(url) {
|
||||
var schema = url.protocol.slice(0, -1);
|
||||
var host = url.host;
|
||||
var path = url.path;
|
||||
return Promise.resolve({
|
||||
name: 'Twitter',
|
||||
link: 'https://twitter.com/intent/tweet?text=Wow:&url=' + encodeURIComponent(url),
|
||||
badge: 'https://img.shields.io/twitter/url/' + schema + '/' + host + path + '.svg?style=social',
|
||||
});
|
||||
};
|
||||
var githubIssues = function(user, repo) {
|
||||
var userRepo = user + '/' + repo;
|
||||
return Promise.resolve({
|
||||
|
|
Loading…
Reference in New Issue
Block a user