2019-05-12 13:44:03 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const got = require('got');
|
|
|
|
const emoji = require('github-emoji');
|
|
|
|
const jsdom = require('jsdom').JSDOM,
|
2019-05-20 07:38:30 +00:00
|
|
|
options = {
|
|
|
|
resources: "usable"
|
|
|
|
};
|
2019-05-12 13:44:03 +00:00
|
|
|
|
2019-05-20 07:38:30 +00:00
|
|
|
function convertToEmoji(text) {
|
2019-05-12 13:44:03 +00:00
|
|
|
if (text == null) return;
|
|
|
|
text = text.toString();
|
2019-05-20 07:38:30 +00:00
|
|
|
if (text.match(/(?<=:\s*).*?(?=\s*:)/gs) != null) {
|
2019-05-12 13:44:03 +00:00
|
|
|
var str = text.match(/(?<=:\s*).*?(?=\s*:)/gs);
|
2019-05-20 07:38:30 +00:00
|
|
|
str = str.filter(function (arr) {
|
2019-05-12 13:44:03 +00:00
|
|
|
return /\S/.test(arr);
|
|
|
|
});
|
2019-05-20 07:38:30 +00:00
|
|
|
for (i = 0; i < str.length; i++) {
|
|
|
|
if (emoji.URLS[str[i]] != undefined) {
|
2019-05-12 13:44:03 +00:00
|
|
|
var output = emoji.of(str[i]);
|
|
|
|
var emojiImage = output.url.replace("assets-cdn.github", "github.githubassets");
|
|
|
|
text = text.replace(`:${str[i]}:`, `<img src="${emojiImage}" class="emoji">`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text;
|
2019-05-20 07:38:30 +00:00
|
|
|
} else {
|
2019-05-12 13:44:03 +00:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 09:22:19 +00:00
|
|
|
module.exports.updateHTML = (username, sort, order, includeFork) => {
|
2019-05-20 07:38:30 +00:00
|
|
|
//add data to assets/index.html
|
|
|
|
jsdom.fromFile("./assets/index.html", options).then(function (dom) {
|
|
|
|
let window = dom.window, document = window.document;
|
|
|
|
(async () => {
|
|
|
|
try {
|
2019-05-20 09:22:19 +00:00
|
|
|
console.log("Building HTML/CSS...");
|
2019-05-20 10:25:09 +00:00
|
|
|
var repos;
|
|
|
|
if(sort == "star"){
|
|
|
|
repos = await got(`https://api.github.com/users/${username}/repos?per_page=1200`);
|
|
|
|
repos = JSON.parse(repos.body);
|
|
|
|
if(order == "desc"){
|
|
|
|
repos = repos.sort(function(a, b) {
|
|
|
|
return b.stargazers_count - a.stargazers_count;
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
repos = repos.sort(function(a, b) {
|
|
|
|
return a.stargazers_count - b.stargazers_count;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
repos = await got(`https://api.github.com/users/${username}/repos?sort=${sort}&order=${order}&per_page=1200`);
|
|
|
|
repos = JSON.parse(repos.body);
|
|
|
|
}
|
2019-05-20 09:22:19 +00:00
|
|
|
for (var i = 0; i < repos.length; i++) {
|
|
|
|
if(repos[i].fork == false){
|
|
|
|
document.getElementById("work_section").innerHTML += `
|
|
|
|
<a href="${repos[i].html_url}" target="_blank">
|
|
|
|
<section>
|
|
|
|
<div class="section_title">${repos[i].name}</div>
|
|
|
|
<div class="about_section">
|
|
|
|
<span style="display:${repos[i].description == undefined ? 'none' : 'block'};">${convertToEmoji(repos[i].description)}</span>
|
|
|
|
</div>
|
|
|
|
<div class="bottom_section">
|
|
|
|
<span style="display:${repos[i].language == null ? 'none' : 'inline-block'};"><i class="fas fa-code"></i> ${repos[i].language}</span>
|
|
|
|
<span><i class="fas fa-star"></i> ${repos[i].stargazers_count}</span>
|
|
|
|
<span><i class="fas fa-code-branch"></i> ${repos[i].forks_count}</span>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</a>`;
|
|
|
|
}else{
|
|
|
|
if(includeFork == true){
|
|
|
|
document.getElementById("forks").style.display = "block";
|
|
|
|
document.getElementById("forks_section").innerHTML += `
|
|
|
|
<a href="${repos[i].html_url}" target="_blank">
|
|
|
|
<section>
|
|
|
|
<div class="section_title">${repos[i].name}</div>
|
|
|
|
<div class="about_section">
|
|
|
|
<span style="display:${repos[i].description == undefined ? 'none' : 'block'};">${convertToEmoji(repos[i].description)}</span>
|
|
|
|
</div>
|
|
|
|
<div class="bottom_section">
|
|
|
|
<span style="display:${repos[i].language == null ? 'none' : 'inline-block'};"><i class="fas fa-code"></i> ${repos[i].language}</span>
|
|
|
|
<span><i class="fas fa-star"></i> ${repos[i].stargazers_count}</span>
|
|
|
|
<span><i class="fas fa-code-branch"></i> ${repos[i].forks_count}</span>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</a>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var user = await got(`https://api.github.com/users/${username}`);
|
|
|
|
user = JSON.parse(user.body);
|
|
|
|
document.title = user.login;
|
|
|
|
var icon = document.createElement("link");
|
|
|
|
icon.setAttribute("rel", "icon");
|
|
|
|
icon.setAttribute("href", user.avatar_url);
|
|
|
|
icon.setAttribute("type", "image/png");
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(icon);
|
|
|
|
document.getElementById("profile_img").style.background = `url('${user.avatar_url}') center center`
|
|
|
|
document.getElementById("username").innerHTML = `<span style="display:${user.name == null || !user.name ? 'none' : 'block'};">${user.name}</span>@${user.login}`;
|
|
|
|
//document.getElementById("github_link").href = `https://github.com/${user.login}`;
|
|
|
|
document.getElementById("userbio").innerHTML = convertToEmoji(user.bio);
|
|
|
|
document.getElementById("userbio").style.display = user.bio == null || !user.bio ? 'none' : 'block';
|
|
|
|
document.getElementById("about").innerHTML = `
|
|
|
|
<span style="display:${user.company == null || !user.company ? 'none' : 'block'};"><i class="fas fa-users"></i> ${user.company}</span>
|
|
|
|
<span style="display:${user.email == null || !user.email ? 'none' : 'block'};"><i class="fas fa-envelope"></i> ${user.email}</span>
|
|
|
|
<span style="display:${user.blog == null || !user.blog ? 'none' : 'block'};"><i class="fas fa-link"></i> ${user.blog}</span>
|
|
|
|
<span style="display:${user.location == null || !user.location ? 'none' : 'block'};"><i class="fas fa-map-marker-alt"></i> ${user.location}</span>
|
|
|
|
<span style="display:${user.hireable == false || !user.hireable ? 'none' : 'block'};"><i class="fas fa-user-tie"></i> Available for hire</span>`;
|
|
|
|
//add data to config.json
|
|
|
|
fs.readFile("./dist/config.json", function (err, data) {
|
2019-05-20 07:38:30 +00:00
|
|
|
if (err) throw err;
|
2019-05-20 09:22:19 +00:00
|
|
|
data = JSON.parse(data);
|
|
|
|
data[0].username = user.login;
|
|
|
|
data[0].name = user.name;
|
|
|
|
data[0].userimg = user.avatar_url;
|
|
|
|
fs.writeFile('./dist/config.json', JSON.stringify(data, null, ' '), function (err) {
|
|
|
|
if (err) throw err;
|
2019-05-21 01:37:08 +00:00
|
|
|
console.log("Config file updated.");
|
2019-05-20 09:22:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
fs.writeFile('dist/index.html', '<!DOCTYPE html>' + window.document.documentElement.outerHTML, function (error) {
|
|
|
|
if (error) throw error;
|
|
|
|
console.log("Build Complete");
|
2019-05-20 07:38:30 +00:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}).catch(function (error) {
|
|
|
|
console.log(error);
|
|
|
|
});
|
2019-05-20 09:22:19 +00:00
|
|
|
}
|