mirror of
https://github.com/dilllxd/gitfolio.git
synced 2024-08-14 22:28:09 +00:00
14fdafebe4
* Created site files are now placed in an output directory `dist` * Added a ton of comments in build.js * Made functions in build.js use bluebird promises * Themes are now in the assets/templates folder instead as magic strings in the source code * Any number of custom themes (not just light and dark) can be used by creating a [theme].css file and putting it in assets/themes * CSS themes are rendered with Handlebars * CSS themes now rely on Handlebars for specifying the background * Restored config.json to template file * Changes to the blogging * Moved blog templates and config files to assets/blog * Created blog pages now go to dist/blog/ * Updated blogTemplate * Updated the README to reflect the changes made by this pull request * Added link to demo site in README * Added sorting and ordering
137 lines
No EOL
6.2 KiB
JavaScript
137 lines
No EOL
6.2 KiB
JavaScript
const fs = require('fs');
|
|
const got = require('got');
|
|
const emoji = require('github-emoji');
|
|
const jsdom = require('jsdom').JSDOM,
|
|
options = {
|
|
resources: "usable"
|
|
};
|
|
|
|
function convertToEmoji(text) {
|
|
if (text == null) return;
|
|
text = text.toString();
|
|
if (text.match(/(?<=:\s*).*?(?=\s*:)/gs) != null) {
|
|
var str = text.match(/(?<=:\s*).*?(?=\s*:)/gs);
|
|
str = str.filter(function (arr) {
|
|
return /\S/.test(arr);
|
|
});
|
|
for (i = 0; i < str.length; i++) {
|
|
if (emoji.URLS[str[i]] != undefined) {
|
|
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;
|
|
} else {
|
|
return text;
|
|
}
|
|
}
|
|
|
|
let savedRepos = [];
|
|
let savedForks = [];
|
|
|
|
module.exports.updateHTML = (username, sort, order) => {
|
|
//add data to assets/index.html
|
|
jsdom.fromFile("./assets/index.html", options).then(function (dom) {
|
|
let window = dom.window, document = window.document;
|
|
(async () => {
|
|
try {
|
|
console.log("Building HTML/CSS/JS...");
|
|
var repos = await got(`https://api.github.com/users/${username}/repos?per_page=1200`);
|
|
repos = JSON.parse(repos.body);
|
|
for(var i = 0;i < repos.length;i++){
|
|
if(repos[i].fork == false){
|
|
repos[i].description = convertToEmoji(repos[i].description);
|
|
savedRepos.push(repos[i]);
|
|
} else {
|
|
repos[i].description = convertToEmoji(repos[i].description);
|
|
savedForks.push(repos[i]);
|
|
}
|
|
}
|
|
|
|
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) {
|
|
if (err) throw err;
|
|
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;
|
|
});
|
|
});
|
|
fs.writeFile('dist/index.html', '<!DOCTYPE html>' + window.document.documentElement.outerHTML, function (error) {
|
|
if (error) throw error;
|
|
console.log("Build Complete");
|
|
process.exit(0)
|
|
});
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
})();
|
|
}).catch(function (error) {
|
|
console.log(error);
|
|
});
|
|
}
|
|
|
|
function populateHTML(type, sort, order, document){
|
|
let data = require('./dist/' + type + '.json');
|
|
let result = [];
|
|
result = data.sort(GetSortOrder(sort, order));
|
|
if(result.length){
|
|
for(var i = 0;i < result.length;i++){
|
|
document.getElementById(type === 'repos' ? 'projects' : 'forks').innerHTML += `
|
|
<a href="${result[i].html_url}" target="_blank">
|
|
<section>
|
|
<div class="section_title">${result[i].name}</div>
|
|
<div class="about_section">
|
|
<span style="display:${result[i].description == undefined ? 'none' : 'block'};">${result[i].description}</span>
|
|
</div>
|
|
<div class="bottom_section">
|
|
<span style="display:${result[i].language == null ? 'none' : 'inline-block'};"><i class="fas fa-code"></i> ${result[i].language}</span>
|
|
<span><i class="fas fa-star"></i> ${result[i].stargazers_count}</span>
|
|
<span><i class="fas fa-code-branch"></i> ${result[i].forks_count}</span>
|
|
</div>
|
|
</section>
|
|
</a>`;
|
|
}
|
|
}
|
|
}
|
|
|
|
function GetSortOrder(prop, order) {
|
|
return function(a, b) {
|
|
if(typeof(a[prop]) === 'string'){
|
|
if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
|
|
return 1 * order;
|
|
} else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
|
|
return -1 * order;
|
|
}
|
|
} else {
|
|
if (a[prop] > b[prop]) {
|
|
return 1 * order;
|
|
} else if (a[prop] < b[prop]) {
|
|
return -1 * order;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|