1
0
Fork 0
mirror of https://github.com/dilllxd/gitfolio.git synced 2024-08-14 22:28:09 +00:00

Fixed Issues and added a UI

This commit is contained in:
imfunny 2019-08-13 15:24:14 +05:30 committed by GitHub
parent 39ffee2944
commit 870758aa69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 614 additions and 580 deletions

View file

@ -14,21 +14,21 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment Examples of behavior that contributes to creating a positive environment
include: include:
* Using welcoming and inclusive language - Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences - Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism - Gracefully accepting constructive criticism
* Focusing on what is best for the community - Focusing on what is best for the community
* Showing empathy towards other community members - Showing empathy towards other community members
Examples of unacceptable behavior by participants include: Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or - The use of sexualized language or imagery and unwelcome sexual attention or
advances advances
* Trolling, insulting/derogatory comments, and personal or political attacks - Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment - Public or private harassment
* Publishing others' private information, such as a physical or electronic - Publishing others' private information, such as a physical or electronic
address, without explicit permission address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a - Other conduct which could reasonably be considered inappropriate in a
professional setting professional setting
## Our Responsibilities ## Our Responsibilities

View file

@ -1,6 +1,6 @@
<img src="https://i.imgur.com/eA6clZr.png"> <img src="https://i.imgur.com/eA6clZr.png">
# Gitfolio [![Tweet](https://img.shields.io/twitter/url/https/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=personal%20website%20and%20a%20blog%20for%20every%20github%20user%20@imfunnieee%20&url=https://github.com/imfunniee/gitfolio) ![GitHub release](https://img.shields.io/github/release/imfunniee/gitfolio.svg?style=popout-square) ![npm](https://img.shields.io/npm/dm/gitfolio.svg?style=popout-square) ![GitHub top language](https://img.shields.io/github/languages/top/imfunniee/gitfolio.svg?style=popout-square) ![GitHub last commit](https://img.shields.io/github/last-commit/imfunniee/gitfolio.svg?style=popout-square) ![GitHub](https://img.shields.io/github/license/imfunniee/gitfolio.svg?style=popout-square) # Gitfolio [![Tweet](https://img.shields.io/twitter/url/https/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=personal%20website%20and%20a%20blog%20for%20every%20github%20user%20@imfunnieee%20&url=https://github.com/imfunniee/gitfolio) ![GitHub release](https://img.shields.io/github/release/imfunniee/gitfolio.svg?style=popout-square) ![npm](https://img.shields.io/npm/dm/gitfolio.svg?style=popout-square) ![GitHub top language](https://img.shields.io/github/languages/top/imfunniee/gitfolio.svg?style=popout-square) ![GitHub last commit](https://img.shields.io/github/last-commit/imfunniee/gitfolio.svg?style=popout-square) ![GitHub](https://img.shields.io/github/license/imfunniee/gitfolio.svg?style=popout-square) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
### personal website + blog for every github user ### personal website + blog for every github user

66
api.js Normal file
View file

@ -0,0 +1,66 @@
const got = require("got");
/**
* The defaults here are the same as the API
* @see https://developer.github.com/v3/repos/#list-user-repositories
* @param {string} username
* @param {Object} opts
* @param {('all' | 'owner' | 'member')[]} [opts.types]
* @param {'created' | 'updated' | 'pushed' | 'full_name' | 'star'} [opts.sort]
* @param {'desc' | 'asc'} [opts.order]
*/
async function getRepos(username, opts = {}) {
let tempRepos;
let page = 1;
let repos = [];
const sort = opts.sort;
const order = opts.order || (sort === "full_name" ? "asc" : "desc");
const types = opts.types || [];
let type = "all";
if (
types.includes("all") ||
(types.includes("owner") && types.includes("member"))
) {
type = "all";
} else if (types.includes("member")) {
type = "member";
}
do {
let requestUrl = `https://api.github.com/users/${username}/repos?per_page=100&page=${page++}&type=${type}`;
if (sort && sort !== "star") {
requestUrl += `&sort=${sort}&direction=${order}`;
}
tempRepos = await got(requestUrl);
tempRepos = JSON.parse(tempRepos.body);
repos = repos.concat(tempRepos);
} while (tempRepos.length == 100);
if (sort == "star") {
repos = repos.sort(function(a, b) {
if (order == "desc") {
return b.stargazers_count - a.stargazers_count;
} else {
return a.stargazers_count - b.stargazers_count;
}
});
}
return repos;
}
/**
* @see https://developer.github.com/v3/users/#get-a-single-user
* @param {string} username
*/
async function getUser(username) {
const res = await got(`https://api.github.com/users/${username}`);
return JSON.parse(res.body);
}
module.exports = {
getRepos,
getUser
};

View file

@ -103,9 +103,9 @@
icon.setAttribute("href", user[0].userimg); icon.setAttribute("href", user[0].userimg);
icon.setAttribute("type", "image/png"); icon.setAttribute("type", "image/png");
document.getElementsByTagName("head")[0].appendChild(icon); document.getElementsByTagName("head")[0].appendChild(icon);
document.getElementById("profile_img_blog").style.background = `url('${ document.getElementById(
user[0].userimg "profile_img_blog"
}') center center`; ).style.background = `url('${user[0].userimg}') center center`;
document.getElementById( document.getElementById(
"username_blog" "username_blog"
).innerHTML = `<span style="display:${ ).innerHTML = `<span style="display:${

View file

@ -1,5 +1,5 @@
@import url('https://fonts.googleapis.com/css?family=Poppins'); @import url("https://fonts.googleapis.com/css?family=Poppins");
@import url('https://fonts.googleapis.com/css?family=Questrial'); @import url("https://fonts.googleapis.com/css?family=Questrial");
body { body {
margin: 0%; margin: 0%;
@ -10,7 +10,7 @@ body {
max-width: 100vw; max-width: 100vw;
overflow-x: hidden; overflow-x: hidden;
align-items: center; align-items: center;
font-family: 'Poppins', sans-serif; font-family: "Poppins", sans-serif;
} }
#loading { #loading {
@ -76,7 +76,7 @@ body {
font-size: 50px; font-size: 50px;
color: var(--text-color); color: var(--text-color);
font-weight: bold; font-weight: bold;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
} }
.emoji { .emoji {
@ -95,18 +95,18 @@ body {
#username_blog { #username_blog {
font-size: 18px; font-size: 18px;
color: var(--text-color); color: var(--text-color);
font-family: 'Poppins', sans-serif; font-family: "Poppins", sans-serif;
font-weight: bold; font-weight: bold;
} }
#username_blog span { #username_blog span {
font-size: 24px; font-size: 24px;
font-family: 'Questrial', sans-serif !important; font-family: "Questrial", sans-serif !important;
} }
#username_blog b { #username_blog b {
font-size: 12px; font-size: 12px;
font-family: 'Poppins', sans-serif; font-family: "Poppins", sans-serif;
font-weight: bold; font-weight: bold;
} }
@ -150,7 +150,7 @@ body {
font-size: 50px; font-size: 50px;
color: var(--text-color); color: var(--text-color);
font-weight: bold; font-weight: bold;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
} }
#blog-display h2 { #blog-display h2 {
@ -159,7 +159,7 @@ body {
#blog-display { #blog-display {
padding: 1vh 0px; padding: 1vh 0px;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
} }
#blog p { #blog p {
@ -205,7 +205,7 @@ body {
#footer_blog a { #footer_blog a {
color: var(--text-color) !important; color: var(--text-color) !important;
text-decoration: none; text-decoration: none;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
font-weight: bold; font-weight: bold;
} }
@ -218,7 +218,7 @@ body {
#footer a { #footer a {
color: var(--text-color) !important; color: var(--text-color) !important;
text-decoration: none; text-decoration: none;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
font-weight: bold; font-weight: bold;
} }
@ -250,13 +250,13 @@ body {
#userbio { #userbio {
font-size: 26px; font-size: 26px;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
width: 100%; width: 100%;
} }
#about { #about {
font-size: 18px; font-size: 18px;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
} }
#about a, #about a,
@ -333,7 +333,7 @@ body {
.about_section { .about_section {
font-size: 18px; font-size: 18px;
font-family: 'Questrial', sans-serif; font-family: "Questrial", sans-serif;
margin: 2vh 0px; margin: 2vh 0px;
font-weight: bold; font-weight: bold;
word-wrap: break-word; word-wrap: break-word;

View file

@ -2,9 +2,17 @@
--bg-color: rgb(10, 10, 10); --bg-color: rgb(10, 10, 10);
--text-color: #fff; --text-color: #fff;
--blog-gray-color: rgb(180, 180, 180); --blog-gray-color: rgb(180, 180, 180);
--background-image: linear-gradient(90deg, rgba(10, 10, 10, 0.3), rgb(10, 10, 10, 1)), --background-image: linear-gradient(
90deg,
rgba(10, 10, 10, 0.3),
rgb(10, 10, 10, 1)
),
url("{{{background}}}"); url("{{{background}}}");
--background-background: linear-gradient(0deg, rgba(10, 10, 10, 1), rgba(10, 10, 10, 0.6)), --background-background: linear-gradient(
0deg,
rgba(10, 10, 10, 1),
rgba(10, 10, 10, 0.6)
),
url("{{{background}}}") center center fixed; url("{{{background}}}") center center fixed;
--height: 50vh; --height: 50vh;
} }
@ -31,7 +39,11 @@
@media (max-width: 800px) { @media (max-width: 800px) {
:root { :root {
--background-image: linear-gradient(0deg, rgba(10, 10, 10, 1), rgba(10, 10, 10, 0)), --background-image: linear-gradient(
0deg,
rgba(10, 10, 10, 1),
rgba(10, 10, 10, 0)
),
url("{{{background}}}") !important; url("{{{background}}}") !important;
} }
} }

View file

@ -2,6 +2,11 @@
--bg-color: #fff; --bg-color: #fff;
--text-color: rgb(10, 10, 10); --text-color: rgb(10, 10, 10);
--blog-gray-color: rgb(80, 80, 80); --blog-gray-color: rgb(80, 80, 80);
--background-image: linear-gradient(90deg, rgba(10, 10, 10, 0.4), rgb(10, 10, 10, 0.4)), url("{{{background}}}"); --background-image: linear-gradient(
90deg,
rgba(10, 10, 10, 0.4),
rgb(10, 10, 10, 0.4)
),
url("{{{background}}}");
--background-background: #fff; --background-background: #fff;
} }

View file

@ -10,6 +10,11 @@ const { uiCommand } = require("../ui");
const { runCommand } = require("../run"); const { runCommand } = require("../run");
const { version } = require("../package.json"); const { version } = require("../package.json");
function collect(val, memo) {
memo.push(val);
return memo;
}
program program
.command("build <username>") .command("build <username>")
.description( .description(

View file

@ -58,54 +58,33 @@ async function populateCSS({
await fs.writeFileAsync(config, JSON.stringify(data, null, " ")); await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
} }
async function populateConfig( async function populateConfig(opts) {
sort,
order,
includeFork,
twitter,
linkedin,
medium,
dribbble
) {
const data = await getConfig(); const data = await getConfig();
data[0].sort = sort; Object.assign(data[0], opts);
data[0].order = order;
data[0].includeFork = includeFork;
data[0].twitter = twitter; // added twitter
data[0].linkedin = linkedin; // added linkedin
data[0].medium = medium; // added medium
data[0].dribbble = dribbble; // added dribbble
await fs.writeFileAsync(config, JSON.stringify(data, null, " ")); await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
} }
async function buildCommand(username, program) { async function buildCommand(username, program) {
await populateCSS(program); await populateCSS(program);
let sort = program.sort ? program.sort : "created"; let types;
let order = program.order ? program.order : "asc"; if (!program.include || !program.include.length) {
let includeFork = program.fork ? true : false; types = ["all"];
let twitter = program.twitter ? program.twitter : null; } else {
let linkedin = program.linkedin ? program.linkedin : null; types = program.include;
let medium = program.medium ? program.medium : null; }
let dribbble = program.dribbble ? program.dribbble : null; const opts = {
await populateConfig( sort: program.sort,
sort, order: program.order,
order, includeFork: program.fork ? true : false,
includeFork, types,
twitter, twitter: program.twitter,
linkedin, linkedin: program.linkedin,
medium, medium: program.medium,
dribbble dribbble: program.dribbble
); };
updateHTML(
("%s", username), await populateConfig(opts);
sort, updateHTML(("%s", username), opts);
order,
includeFork,
twitter,
linkedin,
medium,
dribbble
);
} }
module.exports = { module.exports = {

38
package-lock.json generated
View file

@ -152,17 +152,32 @@
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
}, },
"cacheable-request": { "cacheable-request": {
"version": "6.0.0", "version": "6.1.0",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.0.0.tgz", "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz",
"integrity": "sha512-2N7AmszH/WPPpl5Z3XMw1HAP+8d+xugnKQAeKvxFZ/04dbT/CAznqwbl+7eSr3HkwdepNwtb2yx3CAMQWvG01Q==", "integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==",
"requires": { "requires": {
"clone-response": "^1.0.2", "clone-response": "^1.0.2",
"get-stream": "^4.0.0", "get-stream": "^5.1.0",
"http-cache-semantics": "^4.0.0", "http-cache-semantics": "^4.0.0",
"keyv": "^3.0.0", "keyv": "^3.0.0",
"lowercase-keys": "^1.0.1", "lowercase-keys": "^2.0.0",
"normalize-url": "^3.1.0", "normalize-url": "^4.1.0",
"responselike": "^1.0.2" "responselike": "^1.0.2"
},
"dependencies": {
"get-stream": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"requires": {
"pump": "^3.0.0"
}
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA=="
}
} }
}, },
"caseless": { "caseless": {
@ -773,9 +788,9 @@
"integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==" "integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw=="
}, },
"normalize-url": { "normalize-url": {
"version": "3.3.0", "version": "4.3.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-3.3.0.tgz", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.3.0.tgz",
"integrity": "sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==" "integrity": "sha512-0NLtR71o4k6GLP+mr6Ty34c5GA6CMoEsncKJxvQd8NzPxaHRJNnb5gZE8R1XF4CPIS7QPHLJ74IFszwtNVAHVQ=="
}, },
"nwsapi": { "nwsapi": {
"version": "2.1.4", "version": "2.1.4",
@ -872,6 +887,11 @@
"resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz",
"integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=" "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc="
}, },
"prettier": {
"version": "1.18.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz",
"integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw=="
},
"proxy-addr": { "proxy-addr": {
"version": "2.0.5", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",

View file

@ -7,10 +7,11 @@
"scripts": { "scripts": {
"cli": "OUT_DIR='./dist' node bin/gitfolio.js", "cli": "OUT_DIR='./dist' node bin/gitfolio.js",
"clean": "rm -rf ./dist/*", "clean": "rm -rf ./dist/*",
"prettier": "prettier --write \"./**/*.{js,jsx,json,html,css,md}\"",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": { "author": {
"name": "imfunny and community", "name": "@imfunniee and community",
"email": "imfunny@wybemf.com", "email": "imfunny@wybemf.com",
"url": "https://imfunniee.github.io" "url": "https://imfunniee.github.io"
}, },
@ -41,6 +42,7 @@
"got": "^9.6.0", "got": "^9.6.0",
"handlebars": "^4.1.2", "handlebars": "^4.1.2",
"jsdom": "^15.1.0", "jsdom": "^15.1.0",
"ncp": "^2.0.0" "ncp": "^2.0.0",
"prettier": "^1.18.2"
} }
} }

View file

@ -1,11 +1,11 @@
const fs = require("fs"); const fs = require("fs");
const got = require("got");
const emoji = require("github-emoji"); const emoji = require("github-emoji");
const jsdom = require("jsdom").JSDOM, const jsdom = require("jsdom").JSDOM,
options = { options = {
resources: "usable" resources: "usable"
}; };
const { getConfig, outDir } = require("./utils"); const { getConfig, outDir } = require("./utils");
const { getRepos, getUser } = require("./api");
function convertToEmoji(text) { function convertToEmoji(text) {
if (text == null) return; if (text == null) return;
@ -35,16 +35,8 @@ function convertToEmoji(text) {
} }
} }
module.exports.updateHTML = ( module.exports.updateHTML = (username, opts) => {
username, const { includeFork, twitter, linkedin, medium, dribbble } = opts;
sort,
order,
includeFork,
twitter,
linkedin,
medium,
dribbble
) => {
//add data to assets/index.html //add data to assets/index.html
jsdom jsdom
.fromFile(`${__dirname}/assets/index.html`, options) .fromFile(`${__dirname}/assets/index.html`, options)
@ -54,38 +46,19 @@ module.exports.updateHTML = (
(async () => { (async () => {
try { try {
console.log("Building HTML/CSS..."); console.log("Building HTML/CSS...");
var repos = []; const repos = await getRepos(username, opts);
var tempRepos;
var page = 1;
if (sort == "star") {
do {
tempRepos = await got(
`https://api.github.com/users/${username}/repos?per_page=100&page=${page++}`
);
tempRepos = JSON.parse(tempRepos.body);
repos = repos.concat(tempRepos);
} while (tempRepos.length == 100);
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 {
do {
tempRepos = await got(
`https://api.github.com/users/${username}/repos?sort=${sort}&order=${order}&per_page=100&page=${page++}`
);
tempRepos = JSON.parse(tempRepos.body);
repos = repos.concat(tempRepos);
} while (tempRepos.length == 100);
}
for (var i = 0; i < repos.length; i++) { for (var i = 0; i < repos.length; i++) {
let element;
if (repos[i].fork == false) { if (repos[i].fork == false) {
document.getElementById("work_section").innerHTML += ` element = document.getElementById("work_section");
} else if (includeFork == true) {
document.getElementById("forks").style.display = "block";
element = document.getElementById("forks_section");
} else {
continue;
}
element.innerHTML += `
<a href="${repos[i].html_url}" target="_blank"> <a href="${repos[i].html_url}" target="_blank">
<section> <section>
<div class="section_title">${repos[i].name}</div> <div class="section_title">${repos[i].name}</div>
@ -113,55 +86,18 @@ module.exports.updateHTML = (
</div> </div>
</section> </section>
</a>`; </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>&nbsp; ${
repos[i].language
}</span>
<span><i class="fas fa-star"></i>&nbsp; ${
repos[i].stargazers_count
}</span>
<span><i class="fas fa-code-branch"></i>&nbsp; ${
repos[i].forks_count
}</span>
</div>
</section>
</a>`;
} }
} const user = await getUser(username);
}
var user = await got(`https://api.github.com/users/${username}`);
user = JSON.parse(user.body);
document.title = user.login; document.title = user.login;
var icon = document.createElement("link"); var icon = document.createElement("link");
icon.setAttribute("rel", "icon"); icon.setAttribute("rel", "icon");
icon.setAttribute("href", user.avatar_url); icon.setAttribute("href", user.avatar_url);
icon.setAttribute("type", "image/png"); icon.setAttribute("type", "image/png");
document.getElementsByTagName("head")[0].appendChild(icon); document.getElementsByTagName("head")[0].appendChild(icon);
document.getElementById("profile_img").style.background = `url('${ document.getElementById(
user.avatar_url "profile_img"
}') center center`; ).style.background = `url('${user.avatar_url}') center center`;
document.getElementById( document.getElementById(
"username" "username"
).innerHTML = `<span style="display:${ ).innerHTML = `<span style="display:${
@ -206,19 +142,20 @@ module.exports.updateHTML = (
<span style="display:${ <span style="display:${
medium == null ? "none !important" : "block" medium == null ? "none !important" : "block"
};"><a href="https://www.medium.com/@${medium}/" target="_blank" class="socials"><i class="fab fa-medium-m"></i></a></span> };"><a href="https://www.medium.com/@${medium}/" target="_blank" class="socials"><i class="fab fa-medium-m"></i></a></span>
</div>`; </div>
`;
//add data to config.json //add data to config.json
const data = await getConfig(); const data = await getConfig();
data[0].username = user.login; data[0].username = user.login;
data[0].name = user.name; data[0].name = user.name;
data[0].userimg = user.avatar_url; data[0].userimg = user.avatar_url;
await fs.writeFile( await fs.writeFile(
`${outDir}/config.json`, `${outDir}/config.json`,
JSON.stringify(data, null, " "), JSON.stringify(data, null, " "),
function(err) { function(err) {
if (err) throw err; if (err) throw err;
console.log("Config file updated.\n"); console.log("Config file updated.");
} }
); );
await fs.writeFile( await fs.writeFile(

75
ui.js
View file

@ -1,6 +1,5 @@
const fs = require("fs"); const fs = require("fs");
const express = require("express"); const express = require("express");
let bodyParser = require("body-parser");
const { updateHTML } = require("./populate"); const { updateHTML } = require("./populate");
const { populateCSS, populateConfig } = require("./build"); const { populateCSS, populateConfig } = require("./build");
const { updateCommand } = require("./update"); const { updateCommand } = require("./update");
@ -8,8 +7,17 @@ const app = express();
app.set("view engine", "ejs"); app.set("view engine", "ejs");
app.use(express.static(__dirname + "/views")); app.use(express.static(__dirname + "/views"));
app.set("views", __dirname + "/views"); app.set("views", __dirname + "/views");
app.use(express.json({ limit: "50mb" })); app.use(
app.use(express.urlencoded({ limit: "50mb", extended: true })); express.json({
limit: "50mb"
})
);
app.use(
express.urlencoded({
limit: "50mb",
extended: true
})
);
const port = 3000; const port = 3000;
@ -24,11 +32,19 @@ function createBlog(title, subtitle, folder, topImage, images, content) {
// Checks to make sure this directory actually exists // Checks to make sure this directory actually exists
// and creates it if it doesn't // and creates it if it doesn't
if (!fs.existsSync(`${outDir}/blog/`)) { if (!fs.existsSync(`${outDir}/blog/`)) {
fs.mkdirSync(`${outDir}/blog/`, { recursive: true }, err => {}); fs.mkdirSync(
`${outDir}/blog/`,
{
recursive: true
},
err => {}
);
} }
if (!fs.existsSync(`${outDir}/blog/${folder}`)) { if (!fs.existsSync(`${outDir}/blog/${folder}`)) {
fs.mkdirSync(`${outDir}/blog/${folder}`, { recursive: true }); fs.mkdirSync(`${outDir}/blog/${folder}`, {
recursive: true
});
} }
fs.copyFile( fs.copyFile(
@ -70,7 +86,9 @@ function createBlog(title, subtitle, folder, topImage, images, content) {
item.split("/")[1].split(";")[0] item.split("/")[1].split(";")[0]
}`, }`,
base64Image, base64Image,
{ encoding: "base64" }, {
encoding: "base64"
},
function(err) { function(err) {
if (err) throw err; if (err) throw err;
} }
@ -89,7 +107,9 @@ function createBlog(title, subtitle, folder, topImage, images, content) {
topImage.split("/")[1].split(";")[0] topImage.split("/")[1].split(";")[0]
}`, }`,
base64ImageTop, base64ImageTop,
{ encoding: "base64" }, {
encoding: "base64"
},
function(err) { function(err) {
if (err) throw err; if (err) throw err;
} }
@ -147,6 +167,7 @@ function uiCommand() {
let sort = req.body.sort ? req.body.sort : "created"; let sort = req.body.sort ? req.body.sort : "created";
let order = req.body.order ? req.body.order : "asc"; let order = req.body.order ? req.body.order : "asc";
let includeFork = req.body.fork == "true" ? true : false; let includeFork = req.body.fork == "true" ? true : false;
let types = ["owner"];
let twitter = req.body.twitter ? req.body.twitter : null; let twitter = req.body.twitter ? req.body.twitter : null;
let linkedin = req.body.linkedin ? req.body.linkedin : null; let linkedin = req.body.linkedin ? req.body.linkedin : null;
let medium = req.body.medium ? req.body.medium : null; let medium = req.body.medium ? req.body.medium : null;
@ -155,27 +176,23 @@ function uiCommand() {
? req.body.background ? req.body.background
: "https://images.unsplash.com/photo-1553748024-d1b27fb3f960?w=1500&q=80"; : "https://images.unsplash.com/photo-1553748024-d1b27fb3f960?w=1500&q=80";
let theme = req.body.theme == "on" ? "dark" : "light"; let theme = req.body.theme == "on" ? "dark" : "light";
const opts = {
sort: sort,
order: order,
includeFork: includeFork,
types,
twitter: twitter,
linkedin: linkedin,
medium: medium,
dribbble: dribbble
};
updateHTML( updateHTML(username, opts);
username, populateCSS({
sort, background: background,
order, theme: theme
includeFork, });
twitter, populateConfig(opts);
linkedin,
medium,
dribbble
);
populateCSS({ background: background, theme: theme });
populateConfig(
sort,
order,
includeFork,
twitter,
linkedin,
medium,
dribbble
);
res.redirect("/"); res.redirect("/");
}); });
@ -186,7 +203,9 @@ function uiCommand() {
); );
} }
fs.readFile(`${outDir}/config.json`, function(err, data) { fs.readFile(`${outDir}/config.json`, function(err, data) {
res.render("blog.ejs", { profile: JSON.parse(data) }); res.render("blog.ejs", {
profile: JSON.parse(data)
});
}); });
}); });

View file

@ -4,34 +4,23 @@ const { updateHTML } = require("./populate");
async function updateCommand() { async function updateCommand() {
const data = await getConfig(); const data = await getConfig();
var username = data[0].username; var username = data[0].username;
var sort = data[0].sort; if (username == null) {
var order = data[0].order;
var includeFork = data[0].includeFork;
var twitter = data[0].twitter;
var linkedin = data[0].linkedin;
var medium = data[0].medium;
var dribbble = data[0].dribbble;
if (
username == null ||
sort == null ||
order == null ||
includeFork == null
) {
console.log( console.log(
"username not found in config.json, please run build command before using update" "username not found in config.json, please run build command before using update"
); );
return; return;
} }
updateHTML( const opts = {
username, sort: data[0].sort,
sort, order: data[0].order,
order, includeFork: data[0].includeFork,
includeFork, types: data[0].types,
twitter, twitter: data[0].twitter,
linkedin, linkedin: data[0].linkedin,
medium, medium: data[0].medium,
dribbble dribbble: data[0].dribbble
); };
updateHTML(username, opts);
} }
module.exports = { module.exports = {

View file

@ -1,10 +1,10 @@
const path = require('path'); const path = require("path");
const bluebird = require('bluebird'); const bluebird = require("bluebird");
const fs = bluebird.promisifyAll(require('fs')); const fs = bluebird.promisifyAll(require("fs"));
const outDir = path.resolve('./dist/' || process.env.OUT_DIR); const outDir = path.resolve("./dist/" || process.env.OUT_DIR);
const configPath = path.join(outDir, 'config.json'); const configPath = path.join(outDir, "config.json");
const blogPath = path.join(outDir, 'blog.json'); const blogPath = path.join(outDir, "blog.json");
const defaultConfigPath = path.resolve(`${__dirname}/default/config.json`); const defaultConfigPath = path.resolve(`${__dirname}/default/config.json`);
const defaultBlogPath = path.resolve(`${__dirname}/default/blog.json`); const defaultBlogPath = path.resolve(`${__dirname}/default/blog.json`);