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

Fix some mistakes and use xo

This commit is contained in:
Kaustubh Ladiya 2020-01-11 22:18:56 +05:30
parent b7a21d8bd7
commit 957ada3ea7
No known key found for this signature in database
GPG key ID: A77FFE5465BD4E7D
14 changed files with 4316 additions and 560 deletions

View file

@ -1,18 +0,0 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
}
}

View file

@ -1,4 +1,5 @@
{
"singleQuote": false,
"overrides": [
{
"files": ["*.html", "*.ejs"],

View file

@ -2,3 +2,4 @@
[![Dependency Status](https://img.shields.io/david/k4ustu3h/gitfolio?style=for-the-badge)](https://david-dm.org/k4ustu3h/gitfolio)
[![devDependencies Status](https://img.shields.io/david/dev/k4ustu3h/gitfolio?style=for-the-badge)](https://david-dm.org/k4ustu3h/gitfolio?type=dev)
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge)](https://github.com/prettier/prettier)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg?style=for-the-badge)](https://github.com/xojs/xo)

15
api.js
View file

@ -14,7 +14,7 @@ async function getRepos(username, opts = {}) {
let page = 1;
let repos = [];
const sort = opts.sort;
const {sort} = opts;
const order = opts.order || (sort === "full_name" ? "asc" : "desc");
const types = opts.types || [];
let type = "all";
@ -33,18 +33,19 @@ async function getRepos(username, opts = {}) {
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);
} while (tempRepos.length === 100);
if (sort == "star") {
repos = repos.sort(function(a, b) {
if (order == "desc") {
if (sort === "star") {
repos = repos.sort((a, b) => {
if (order === "desc") {
return b.stargazers_count - a.stargazers_count;
} else {
return a.stargazers_count - b.stargazers_count;
}
return a.stargazers_count - b.stargazers_count;
});
}

View file

@ -7,7 +7,7 @@ if (workbox) {
debug: false
});
var defaultStrategy = workbox.strategies.networkFirst({
const defaultStrategy = workbox.strategies.networkFirst({
cacheName: "fallback",
plugins: [
new workbox.expiration.Plugin({
@ -16,16 +16,16 @@ if (workbox) {
purgeOnQuotaError: true // Opt-in to automatic cleanup
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200] // for opague requests
statuses: [0, 200] // For opague requests
})
]
});
workbox.routing.setDefaultHandler(args => {
if (args.event.request.method === "GET") {
return defaultStrategy.handle(args); // use default strategy
} else {
return null;
return defaultStrategy.handle(args); // Use default strategy
}
return null;
});
workbox.routing.registerRoute(
@ -38,5 +38,5 @@ if (workbox) {
workbox.strategies.cacheFirst()
);
} else {
console.log(`No workbox on this browser 😬`);
console.log("No workbox on this browser 😬");
}

View file

@ -5,11 +5,11 @@ const program = require("commander");
process.env.OUT_DIR = process.env.OUT_DIR || process.cwd();
const { buildCommand } = require("../build");
const { updateCommand } = require("../update");
const { uiCommand } = require("../ui");
const { runCommand } = require("../run");
const { version } = require("../package.json");
const {buildCommand} = require("../build");
const {updateCommand} = require("../update");
const {uiCommand} = require("../ui");
const {runCommand} = require("../run");
const {version} = require("../package.json");
function collect(val, memo) {
memo.push(val);
@ -41,6 +41,11 @@ program
.description("Update user and repository data")
.action(updateCommand);
program
.command("ui")
.description("Create and Manage gitfolio with ease")
.action(uiCommand);
program
.command("run")
.description("Run build files")
@ -57,4 +62,6 @@ program
.usage("<command> [options]")
.parse(process.argv);
if (program.args.length === 0) program.help();
if (program.args.length === 0) {
program.help();
}

View file

@ -6,8 +6,8 @@ const hbs = require("handlebars");
/* Creates promise-returning async functions
from callback-passed async functions */
const fs = bluebird.promisifyAll(require("fs"));
const { updateHTML } = require("./populate");
const { getConfig, outDir } = require("./utils");
const {updateHTML} = require("./populate");
const {getConfig, outDir} = require("./utils");
const assetDir = path.resolve(`${__dirname}/assets/`);
const config = path.join(outDir, "config.json");
@ -24,29 +24,31 @@ async function populateCSS({
} = {}) {
/* Get the theme the user requests. Defaults to 'light' */
theme = `${theme}.css`;
let template = path.resolve(assetDir, "index.css");
let stylesheet = path.join(outDir, "index.css");
const template = path.resolve(assetDir, "index.css");
const stylesheet = path.join(outDir, "index.css");
try {
await fs.accessAsync(outDir, fs.constants.F_OK);
} catch (err) {
} catch (error) {
await fs.mkdirAsync(outDir);
}
/* Copy over the template CSS stylesheet */
await fs.copyFileAsync(template, stylesheet);
/* Get an array of every available theme */
let themes = await fs.readdirAsync(path.join(assetDir, "themes"));
const themes = await fs.readdirAsync(path.join(assetDir, "themes"));
if (!themes.includes(theme)) {
console.error('Error: Requested theme not found. Defaulting to "light".');
theme = "light";
}
/* Read in the theme stylesheet */
let themeSource = await fs.readFileSync(path.join(assetDir, "themes", theme));
themeSource = themeSource.toString("utf-8");
let themeTemplate = hbs.compile(themeSource);
let styles = themeTemplate({
const themeTemplate = hbs.compile(themeSource);
const styles = themeTemplate({
background: `${background}`
});
/* Add the user-specified styles to the new stylesheet */
@ -72,10 +74,11 @@ async function buildCommand(username, program) {
} else {
types = program.include;
}
const opts = {
sort: program.sort,
order: program.order,
includeFork: program.fork ? true : false,
includeFork: Boolean(program.fork),
types,
codepen: program.codepen,
dev: program.dev,

3791
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,98 +1,52 @@
{
"name": "gitfolio",
"version": "0.1.5",
"description": "a portfolio website for everyone to showcase their work",
"main": "build.js",
"bin": "bin/gitfolio.js",
"scripts": {
"cli": "OUT_DIR='./dist' node bin/gitfolio.js",
"clean": "rm -rf ./dist/*",
"prettier": "prettier --write \"./**/*.{js,jsx,json,html,css,md}\"",
"test": "OUT_DIR='./dist' node bin/gitfolio.js build k4ustu3h --fork --theme dark --sort updated --twitter k4ustu3h_ --dribbble k4ustu3h --email k4ustu3h@gmail.com --codepen k4ustu3h --dev k4ustu3h --instagram k4ustu3h --telegram k4ustu3h --reddit kaustubhladiya"
},
"author": {
"name": "@imfunniee and community",
"email": "imfunny@wybemf.com",
"url": "https://imfunniee.github.io"
},
"bugs": "https://github.com/imfunniee/gitfolio/issues",
"homepage": "https://github.com/imfunniee/gitfolio",
"keywords": [
"personal-website",
"github",
"portfolio",
"portfolio website",
"gitfolio",
"git"
],
"repository": {
"type": "git",
"url": "https://github.com/imfunniee/gitfolio"
},
"license": "GPL-3.0",
"dependencies": {
"bluebird": "^3.7.2",
"body-parser": "^1.19.0",
"commander": "4.0.1",
"ejs": "3.0.1",
"express": "^4.17.1",
"github-emoji": "^1.1.1",
"got": "10.0.4",
"handlebars": "^4.5.3",
"jsdom": "^15.2.1",
"ncp": "^2.0.0"
},
"devDependencies": {
"eslint": "^6.7.2",
"prettier": "1.19.1"
"name": "gitfolio",
"version": "0.1.5",
"description": "a portfolio website for everyone to showcase their work",
"main": "build.js",
"bin": "bin/gitfolio.js",
"scripts": {
"cli": "OUT_DIR='./dist' node bin/gitfolio.js",
"clean": "rm -rf ./dist/*",
"prettier": "prettier --write \"./**/*.{js,jsx,json,html,css,md}\"",
"test": "xo && OUT_DIR='./dist' node bin/gitfolio.js build k4ustu3h --fork --theme dark --sort updated --twitter k4ustu3h_ --dribbble k4ustu3h --email k4ustu3h@gmail.com --codepen k4ustu3h --dev k4ustu3h --instagram k4ustu3h --telegram k4ustu3h --reddit kaustubhladiya"
},
"xo": {
"prettier": true
},
"author": {
"name": "@imfunniee and community",
"email": "imfunny@wybemf.com",
"url": "https://imfunniee.github.io"
},
"bugs": "https://github.com/imfunniee/gitfolio/issues",
"homepage": "https://github.com/imfunniee/gitfolio",
"keywords": [
"personal-website",
"github",
"portfolio",
"portfolio website",
"gitfolio",
"git"
],
"repository": {
"type": "git",
"url": "https://github.com/imfunniee/gitfolio"
},
"license": "GPL-3.0",
"dependencies": {
"bluebird": "^3.5.4",
"body-parser": "^1.19.0",
"commander": "^2.20.0",
"ejs": "^2.6.2",
"express": "^4.17.0",
"github-emoji": "^1.1.1",
"got": "^9.6.0",
"handlebars": "^4.1.2",
"jsdom": "^15.1.0",
"ncp": "^2.0.0"
},
"devDependencies": {
"prettier": "1.19.1",
"xo": "^0.25.3"
}
}
}

View file

@ -1,33 +1,37 @@
const fs = require("fs");
const emoji = require("github-emoji");
const jsdom = require("jsdom").JSDOM,
options = {
const jsdom = require("jsdom").JSDOM;
const options = {
resources: "usable"
};
const { getConfig, outDir } = require("./utils");
const { getRepos, getUser } = require("./api");
};
const {getConfig, outDir} = require("./utils");
const {getRepos, getUser} = require("./api");
function convertToEmoji(text) {
if (text == null) return;
if (text === null) {
return;
}
text = text.toString();
var pattern = /(?<=:\s*).*?(?=\s*:)/gs;
if (text.match(pattern) != null) {
var str = text.match(pattern);
str = str.filter(function(arr) {
const pattern = /(?<=:\s*).*?(?=\s*:)/gs;
if (text.match(pattern) !== null) {
let str = text.match(pattern);
str = str.filter(arr => {
return /\S/.test(arr);
});
for (i = 0; i < str.length; i++) {
if (emoji.URLS[str[i]] != undefined) {
if (emoji.URLS[str[i]] !== undefined) {
text = text.replace(
`:${str[i]}:`,
`<img src="${emoji.URLS[str[i]]}" class="emoji">`
);
}
}
return text;
} else {
return text;
}
return text;
}
module.exports.updateHTML = (username, opts) => {
@ -42,65 +46,67 @@ module.exports.updateHTML = (username, opts) => {
telegram,
twitter
} = opts;
//add data to assets/index.html
// add data to assets/index.html
jsdom
.fromFile(`${__dirname}/assets/index.html`, options)
.then(function(dom) {
let window = dom.window,
document = window.document;
.then(dom => {
const {window} = dom;
const {document} = window;
(async () => {
try {
console.log("Building HTML/CSS...");
const repos = await getRepos(username, opts);
for (var i = 0; i < repos.length; i++) {
for (const element of repos) {
let element;
if (repos[i].fork == false) {
element = document.getElementById("work_section");
} else if (includeFork == true) {
document.getElementById("forks").style.display = "block";
element = document.getElementById("forks_section");
if (element.fork === false) {
element = document.querySelector("#work_section");
} else if (includeFork === true) {
document.querySelector("#forks").style.display = "block";
element = document.querySelector("#forks_section");
} else {
continue;
}
element.innerHTML += `
<a href="${repos[i].html_url}" target="_blank">
<a href="${element.html_url}" target="_blank">
<section>
<div class="section_title">${repos[i].name}</div>
<div class="section_title">${element.name}</div>
<div class="about_section">
<span style="display:${
repos[i].description == undefined
element.description === undefined
? "none"
: "block"
};">${convertToEmoji(repos[i].description)}</span>
};">${convertToEmoji(element.description)}</span>
</div>
<div class="bottom_section">
<span style="display:${
repos[i].language == null
element.language === null
? "none"
: "inline-block"
};"><i class="mdi mdi-code-tags"></i>&nbsp; ${
repos[i].language
element.language
}</span>
<span><i class="mdi mdi-star"></i>&nbsp; ${
repos[i].stargazers_count
element.stargazers_count
}</span>
<span><i class="mdi mdi-source-branch"></i>&nbsp; ${
repos[i].forks_count
element.forks_count
}</span>
</div>
</section>
</a>`;
}
const user = await getUser(username);
document.title = user.login;
var icon = document.createElement("link");
const 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.getElementsByTagName("head")[0].innerHTML += `
document.querySelectorAll("head")[0].append(icon);
document.querySelectorAll("head")[0].innerHTML += `
<meta name="description" content="${user.bio}" />
<meta property="og:image" content="${user.avatar_url}" />
<meta property="og:type" content="profile" />
@ -112,20 +118,20 @@ module.exports.updateHTML = (username, opts) => {
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="${user.login}" />
<meta name="twitter:description" content="${user.bio}" />`;
document.getElementById(
"username"
document.querySelector(
"#username"
).innerHTML = `<span id="text" style="display:${
user.name == null || !user.name ? "none" : "block"
user.name === null || !user.name ? "none" : "block"
};"></span><div class='console-underscore' id='console'>&#95;</div><br><a href="${
user.html_url
}">@${user.login}</a>`;
//document.getElementById("github_link").href = `https://github.com/${user.login}`;
document.getElementById("userbio").innerHTML = convertToEmoji(
// document.getElementById("github_link").href = `https://github.com/${user.login}`;
document.querySelector("#userbio").innerHTML = convertToEmoji(
user.bio
);
document.getElementById("userbio").style.display =
document.querySelector("#userbio").style.display =
user.bio == null || !user.bio ? "none" : "block";
document.getElementById("about").innerHTML = `
document.querySelector("#about").innerHTML = `
<span style="display:${
user.company == null || !user.company ? "none" : "block"
};"><i class="mdi-face"></i> &nbsp; ${user.company}</span>
@ -167,7 +173,7 @@ module.exports.updateHTML = (username, opts) => {
};"><a href="https://www.twitter.com/${twitter}" target="_blank" class="socials"><i class="mdi mdi-twitter"></i></a></span>
</div>
`;
//add data to config.json
// add data to config.json
const data = await getConfig();
data[0].username = user.login;
data[0].name = user.name;
@ -176,16 +182,22 @@ module.exports.updateHTML = (username, opts) => {
await fs.writeFile(
`${outDir}/config.json`,
JSON.stringify(data, null, " "),
function(err) {
if (err) throw err;
err => {
if (err) {
throw err;
}
console.log("Config file updated.");
}
);
await fs.writeFile(
`${outDir}/index.html`,
"<!DOCTYPE html>" + window.document.documentElement.outerHTML,
function(error) {
if (error) throw error;
error => {
if (error) {
throw error;
}
console.log(`Build Complete, Files can be Found @ ${outDir}\n`);
}
);
@ -194,7 +206,7 @@ module.exports.updateHTML = (username, opts) => {
}
})();
})
.catch(function(error) {
.catch(error => {
console.log(error);
});
};

6
run.js
View file

@ -1,13 +1,13 @@
const express = require("express");
const path = require("path");
const express = require("express");
const outDir = path.resolve("./dist/" || process.env.OUT_DIR);
const app = express();
app.use(express.static(`${outDir}`));
function runCommand(program) {
let port = program.port ? program.port : 3000;
const port = program.port ? program.port : 3000;
app.get("/", function(req, res) {
app.get("/", (req, res) => {
res.sendFile("/index.html");
});

78
ui.js
View file

@ -1,8 +1,12 @@
const fs = require("fs");
const express = require("express");
const { updateHTML } = require("./populate");
const { populateCSS, populateConfig } = require("./build");
const { updateCommand } = require("./update");
const jsdom = require("jsdom").JSDOM;
const options = {
resources: "usable"
};
const {updateHTML} = require("./populate");
const {populateCSS, populateConfig} = require("./build");
const {updateCommand} = require("./update");
const app = express();
app.set("view engine", "ejs");
app.use(express.static(__dirname + "/views"));
@ -21,67 +25,65 @@ app.use(
const port = 3000;
const jsdom = require("jsdom").JSDOM,
options = {
resources: "usable"
};
global.DOMParser = new jsdom().window.DOMParser;
function uiCommand() {
app.get("/", function(req, res) {
app.get("/", (req, res) => {
res.render("index.ejs");
});
app.get("/update", function(req, res) {
app.get("/update", (req, res) => {
if (!fs.existsSync(`${outDir}/config.json`)) {
return res.send(
'You need to run build command before using update<br><a href="/">Go Back</a>'
);
}
updateCommand();
res.redirect("/");
});
app.post("/build", function(req, res) {
let username = req.body.username;
app.post("/build", (req, res) => {
const {username} = req.body;
if (!username) {
return res.send("username can't be empty");
}
let sort = req.body.sort ? req.body.sort : "created";
let order = req.body.order ? req.body.order : "asc";
let includeFork = req.body.fork == "true" ? true : false;
let types = ["owner"];
let codepen = req.body.codepen ? req.body.codepen : null;
let dev = req.body.dev ? req.body.dev : null;
let dribbble = req.body.dribbble ? req.body.dribbble : null;
let email = req.body.email ? req.body.email : null;
let instagram = req.body.instagram ? req.body.instagram : null;
let reddit = req.body.reddit ? req.body.reddit : null;
let telegram = req.body.telegram ? req.body.telegram : null;
let twitter = req.body.twitter ? req.body.twitter : null;
let background = req.body.background
const sort = req.body.sort ? req.body.sort : "created";
const order = req.body.order ? req.body.order : "asc";
const includeFork = req.body.fork === "true";
const types = ["owner"];
const codepen = req.body.codepen ? req.body.codepen : null;
const dev = req.body.dev ? req.body.dev : null;
const dribbble = req.body.dribbble ? req.body.dribbble : null;
const email = req.body.email ? req.body.email : null;
const instagram = req.body.instagram ? req.body.instagram : null;
const reddit = req.body.reddit ? req.body.reddit : null;
const telegram = req.body.telegram ? req.body.telegram : null;
const twitter = req.body.twitter ? req.body.twitter : null;
const background = req.body.background
? req.body.background
: "https://source.unsplash.com/1280x720/?wallpaper";
let theme = req.body.theme == "on" ? "dark" : "light";
const theme = req.body.theme === "on" ? "dark" : "light";
const opts = {
sort: sort,
order: order,
includeFork: includeFork,
sort,
order,
includeFork,
types,
codepen: codepen,
dev: dev,
dribbble: dribbble,
email: email,
instagram: instagram,
reddit: reddit,
telegram: telegram,
twitter: twitter
codepen,
dev,
dribbble,
email,
instagram,
reddit,
telegram,
twitter
};
updateHTML(username, opts);
populateCSS({
background: background,
theme: theme
background,
theme
});
populateConfig(opts);
res.redirect("/");

View file

@ -1,15 +1,16 @@
const { getConfig } = require("./utils");
const { updateHTML } = require("./populate");
const {getConfig} = require("./utils");
const {updateHTML} = require("./populate");
async function updateCommand() {
const data = await getConfig();
var username = data[0].username;
if (username == null) {
const {username} = data[0];
if (username === null) {
console.log(
"username not found in config.json, please run build command before using update"
);
return;
}
const opts = {
sort: data[0].sort,
order: data[0].order,

View file

@ -14,10 +14,11 @@ const defaultConfigPath = path.resolve(`${__dirname}/default/config.json`);
async function getFileWithDefaults(file, defaultFile) {
try {
await fs.accessAsync(file, fs.constants.F_OK);
} catch (err) {
} catch (error) {
const defaultData = await fs.readFileAsync(defaultFile);
return JSON.parse(defaultData);
}
const data = await fs.readFileAsync(file);
return JSON.parse(data);
}