2019-11-17 02:27:32 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const emoji = require("github-emoji");
|
|
|
|
const jsdom = require("jsdom").JSDOM,
|
|
|
|
options = {
|
|
|
|
resources: "usable"
|
|
|
|
};
|
2019-12-07 16:18:12 +00:00
|
|
|
const
|
|
|
|
{
|
|
|
|
getConfig,
|
|
|
|
outDir
|
|
|
|
} = require("./utils");
|
|
|
|
const
|
|
|
|
{
|
|
|
|
getRepos,
|
|
|
|
getUser
|
|
|
|
} = require("./api");
|
2019-11-17 02:27:32 +00:00
|
|
|
|
2019-12-07 16:18:12 +00:00
|
|
|
function convertToEmoji(text)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
if (text == null) return;
|
|
|
|
text = text.toString();
|
|
|
|
var pattern = /(?<=:\s*).*?(?=\s*:)/gs;
|
2019-12-07 16:18:12 +00:00
|
|
|
if (text.match(pattern) != null)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
var str = text.match(pattern);
|
2019-12-07 16:18:12 +00:00
|
|
|
str = str.filter(function(arr)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
return /\S/.test(arr);
|
|
|
|
});
|
2019-12-07 16:18:12 +00:00
|
|
|
for (i = 0; i < str.length; i++)
|
|
|
|
{
|
|
|
|
if (emoji.URLS[str[i]] != undefined)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
text = text.replace(
|
|
|
|
`:${str[i]}:`,
|
|
|
|
`<img src="${emoji.URLS[str[i]]}" class="emoji">`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text;
|
2019-12-07 16:18:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-07 16:18:12 +00:00
|
|
|
module.exports.updateHTML = (username, opts) =>
|
|
|
|
{
|
|
|
|
const
|
|
|
|
{
|
|
|
|
includeFork,
|
2019-12-08 17:14:52 +00:00
|
|
|
codepen,
|
|
|
|
dev,
|
2019-12-07 16:18:12 +00:00
|
|
|
dribbble,
|
2019-12-08 16:23:21 +00:00
|
|
|
email,
|
2019-12-08 17:14:52 +00:00
|
|
|
instagram,
|
2019-12-08 16:23:21 +00:00
|
|
|
twitter
|
2019-12-07 16:18:12 +00:00
|
|
|
} = opts;
|
2019-11-17 02:27:32 +00:00
|
|
|
//add data to assets/index.html
|
|
|
|
jsdom
|
|
|
|
.fromFile(`${__dirname}/assets/index.html`, options)
|
2019-12-07 16:18:12 +00:00
|
|
|
.then(function(dom)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
let window = dom.window,
|
|
|
|
document = window.document;
|
2019-12-07 16:18:12 +00:00
|
|
|
(async () =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
console.log("Building HTML/CSS...");
|
|
|
|
const repos = await getRepos(username, opts);
|
|
|
|
|
2019-12-07 16:18:12 +00:00
|
|
|
for (var i = 0; i < repos.length; i++)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
let element;
|
2019-12-07 16:18:12 +00:00
|
|
|
if (repos[i].fork == false)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
element = document.getElementById("work_section");
|
2019-12-07 16:18:12 +00:00
|
|
|
}
|
|
|
|
else if (includeFork == true)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
document.getElementById("forks").style.display = "block";
|
|
|
|
element = document.getElementById("forks_section");
|
2019-12-07 16:18:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
element.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"
|
2019-12-08 16:02:06 +00:00
|
|
|
};"><i class="mdi mdi-code-tags"></i> ${
|
2019-11-17 02:27:32 +00:00
|
|
|
repos[i].language
|
|
|
|
}</span>
|
2019-12-08 16:02:06 +00:00
|
|
|
<span><i class="mdi mdi-star"></i> ${
|
2019-11-17 02:27:32 +00:00
|
|
|
repos[i].stargazers_count
|
|
|
|
}</span>
|
2019-12-08 16:02:06 +00:00
|
|
|
<span><i class="mdi mdi-source-branch"></i> ${
|
2019-11-17 02:27:32 +00:00
|
|
|
repos[i].forks_count
|
|
|
|
}</span>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</a>`;
|
|
|
|
}
|
|
|
|
const user = await getUser(username);
|
|
|
|
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);
|
2019-12-07 16:23:08 +00:00
|
|
|
document.getElementsByTagName("head")[0].innerHTML += `
|
|
|
|
<meta name="description" content="${user.bio}" />
|
|
|
|
<meta property="og:image" content="${user.avatar_url}" />
|
|
|
|
<meta property="og:type" content="profile" />
|
|
|
|
<meta property="og:title" content="${user.login}" />
|
|
|
|
<meta property="og:url" content="${user.html_url}" />
|
|
|
|
<meta property="og:description" content="${user.bio}" />
|
|
|
|
<meta property="profile:username" content="${user.login}" />
|
|
|
|
<meta name="twitter:image:src" content="${user.avatar_url}" />
|
|
|
|
<meta name="twitter:card" content="summary" />
|
|
|
|
<meta name="twitter:title" content="${user.login}" />
|
|
|
|
<meta name="twitter:description" content="${user.bio}" />`;
|
2019-11-17 02:27:32 +00:00
|
|
|
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><a href="${user.html_url}">@${user.login}</a>`;
|
|
|
|
//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"
|
2019-12-08 16:02:06 +00:00
|
|
|
};"><i class="mdi-face"></i> ${user.company}</span>
|
2019-11-17 02:27:32 +00:00
|
|
|
<span style="display:${
|
|
|
|
user.email == null || !user.email ? "none" : "block"
|
2019-12-08 16:02:06 +00:00
|
|
|
};"><i class="mdi mdi-email"></i> ${user.email}</span>
|
2019-11-17 02:27:32 +00:00
|
|
|
<span style="display:${
|
|
|
|
user.location == null || !user.location ? "none" : "block"
|
2019-12-08 16:02:06 +00:00
|
|
|
};"><i class="mdi mdi-map-marker"></i> ${
|
2019-11-17 02:27:32 +00:00
|
|
|
user.location
|
|
|
|
}</span>
|
|
|
|
<span style="display:${
|
|
|
|
user.hireable == false || !user.hireable ? "none" : "block"
|
2019-12-08 16:02:06 +00:00
|
|
|
};"><i class="mdi mdi-account-tie"></i> Available for hire</span>
|
2019-11-17 02:27:32 +00:00
|
|
|
<div class="socials">
|
2019-12-08 17:14:52 +00:00
|
|
|
<span style="display:${
|
|
|
|
codepen == null ? "none !important" : "block"
|
|
|
|
};"><a href="https://codepen.io/${codepen}" target="_blank" class="socials"><i class="mdi mdi-codepen"></i></a></span>
|
|
|
|
<span style="display:${
|
|
|
|
dev == null ? "none !important" : "block"
|
|
|
|
};"><a href="https://dev.to/${dev}" target="_blank" class="socials"><i class="mdi mdi-dev-to"></i></a></span>
|
2019-11-17 02:27:32 +00:00
|
|
|
<span style="display:${
|
|
|
|
dribbble == null ? "none !important" : "block"
|
2019-12-08 16:02:06 +00:00
|
|
|
};"><a href="https://www.dribbble.com/${dribbble}" target="_blank" class="socials"><i class="mdi mdi-dribbble"></i></a></span>
|
2019-12-07 16:18:12 +00:00
|
|
|
<span style="display:${
|
|
|
|
email == null ? "none !important" : "block"
|
2019-12-08 16:02:06 +00:00
|
|
|
};"><a href="mailto:${email}" target="_blank" class="socials"><i class="mdi mdi-email"></i></a></span>
|
2019-12-08 17:14:52 +00:00
|
|
|
<span style="display:${
|
|
|
|
instagram == null ? "none !important" : "block"
|
|
|
|
};"><a href="https://www.instagram.com/${instagram}" target="_blank" class="socials"><i class="mdi mdi-instagram"></i></a></span>
|
2019-12-08 16:23:21 +00:00
|
|
|
<span style="display:${
|
|
|
|
twitter == null ? "none !important" : "block"
|
|
|
|
};"><a href="https://www.twitter.com/${twitter}" target="_blank" class="socials"><i class="mdi mdi-twitter"></i></a></span>
|
2019-11-17 02:27:32 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
//add data to config.json
|
|
|
|
const data = await getConfig();
|
|
|
|
data[0].username = user.login;
|
|
|
|
data[0].name = user.name;
|
|
|
|
data[0].userimg = user.avatar_url;
|
|
|
|
|
|
|
|
await fs.writeFile(
|
|
|
|
`${outDir}/config.json`,
|
|
|
|
JSON.stringify(data, null, " "),
|
2019-12-07 16:18:12 +00:00
|
|
|
function(err)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
if (err) throw err;
|
|
|
|
console.log("Config file updated.");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
await fs.writeFile(
|
|
|
|
`${outDir}/index.html`,
|
|
|
|
"<!DOCTYPE html>" + window.document.documentElement.outerHTML,
|
2019-12-07 16:18:12 +00:00
|
|
|
function(error)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
if (error) throw error;
|
|
|
|
console.log(`Build Complete, Files can be Found @ ${outDir}\n`);
|
|
|
|
}
|
|
|
|
);
|
2019-12-07 16:18:12 +00:00
|
|
|
}
|
|
|
|
catch (error)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
})
|
2019-12-07 16:18:12 +00:00
|
|
|
.catch(function(error)
|
|
|
|
{
|
2019-11-17 02:27:32 +00:00
|
|
|
console.log(error);
|
|
|
|
});
|
2019-12-07 16:18:12 +00:00
|
|
|
};
|