mirror of
https://github.com/dilllxd/gitfolio.git
synced 2024-08-14 22:28:09 +00:00
Change the background image on every build
This commit is contained in:
parent
5e512a6ce5
commit
5d963803be
2 changed files with 30 additions and 68 deletions
47
build.js
47
build.js
|
@ -6,15 +6,8 @@ const hbs = require("handlebars");
|
||||||
/* Creates promise-returning async functions
|
/* Creates promise-returning async functions
|
||||||
from callback-passed async functions */
|
from callback-passed async functions */
|
||||||
const fs = bluebird.promisifyAll(require("fs"));
|
const fs = bluebird.promisifyAll(require("fs"));
|
||||||
const
|
const { updateHTML } = require("./populate");
|
||||||
{
|
const { getConfig, outDir } = require("./utils");
|
||||||
updateHTML
|
|
||||||
} = require("./populate");
|
|
||||||
const
|
|
||||||
{
|
|
||||||
getConfig,
|
|
||||||
outDir
|
|
||||||
} = require("./utils");
|
|
||||||
|
|
||||||
const assetDir = path.resolve(`${__dirname}/assets/`);
|
const assetDir = path.resolve(`${__dirname}/assets/`);
|
||||||
const config = path.join(outDir, "config.json");
|
const config = path.join(outDir, "config.json");
|
||||||
|
@ -25,23 +18,18 @@ const config = path.join(outDir, "config.json");
|
||||||
* Theme styles are added to the new stylesheet depending on command line
|
* Theme styles are added to the new stylesheet depending on command line
|
||||||
* arguments.
|
* arguments.
|
||||||
*/
|
*/
|
||||||
async function populateCSS(
|
async function populateCSS({
|
||||||
{
|
|
||||||
theme = "light",
|
theme = "light",
|
||||||
background = "https://images.unsplash.com/photo-1553748024-d1b27fb3f960?w=1500&q=80"
|
background = "https://source.unsplash.com/1600x900/?wallpaper"
|
||||||
} = {})
|
} = {}) {
|
||||||
{
|
|
||||||
/* Get the theme the user requests. Defaults to 'light' */
|
/* Get the theme the user requests. Defaults to 'light' */
|
||||||
theme = `${theme}.css`;
|
theme = `${theme}.css`;
|
||||||
let template = path.resolve(assetDir, "index.css");
|
let template = path.resolve(assetDir, "index.css");
|
||||||
let stylesheet = path.join(outDir, "index.css");
|
let stylesheet = path.join(outDir, "index.css");
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
await fs.accessAsync(outDir, fs.constants.F_OK);
|
await fs.accessAsync(outDir, fs.constants.F_OK);
|
||||||
}
|
} catch (err) {
|
||||||
catch (err)
|
|
||||||
{
|
|
||||||
await fs.mkdirAsync(outDir);
|
await fs.mkdirAsync(outDir);
|
||||||
}
|
}
|
||||||
/* Copy over the template CSS stylesheet */
|
/* Copy over the template CSS stylesheet */
|
||||||
|
@ -50,8 +38,7 @@ async function populateCSS(
|
||||||
/* Get an array of every available theme */
|
/* Get an array of every available theme */
|
||||||
let themes = await fs.readdirAsync(path.join(assetDir, "themes"));
|
let themes = await fs.readdirAsync(path.join(assetDir, "themes"));
|
||||||
|
|
||||||
if (!themes.includes(theme))
|
if (!themes.includes(theme)) {
|
||||||
{
|
|
||||||
console.error('Error: Requested theme not found. Defaulting to "light".');
|
console.error('Error: Requested theme not found. Defaulting to "light".');
|
||||||
theme = "light";
|
theme = "light";
|
||||||
}
|
}
|
||||||
|
@ -59,8 +46,7 @@ async function populateCSS(
|
||||||
let themeSource = await fs.readFileSync(path.join(assetDir, "themes", theme));
|
let themeSource = await fs.readFileSync(path.join(assetDir, "themes", theme));
|
||||||
themeSource = themeSource.toString("utf-8");
|
themeSource = themeSource.toString("utf-8");
|
||||||
let themeTemplate = hbs.compile(themeSource);
|
let themeTemplate = hbs.compile(themeSource);
|
||||||
let styles = themeTemplate(
|
let styles = themeTemplate({
|
||||||
{
|
|
||||||
background: `${background}`
|
background: `${background}`
|
||||||
});
|
});
|
||||||
/* Add the user-specified styles to the new stylesheet */
|
/* Add the user-specified styles to the new stylesheet */
|
||||||
|
@ -72,23 +58,18 @@ async function populateCSS(
|
||||||
await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
|
await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function populateConfig(opts)
|
async function populateConfig(opts) {
|
||||||
{
|
|
||||||
const data = await getConfig();
|
const data = await getConfig();
|
||||||
Object.assign(data[0], opts);
|
Object.assign(data[0], opts);
|
||||||
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 types;
|
let types;
|
||||||
if (!program.include || !program.include.length)
|
if (!program.include || !program.include.length) {
|
||||||
{
|
|
||||||
types = ["all"];
|
types = ["all"];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
types = program.include;
|
types = program.include;
|
||||||
}
|
}
|
||||||
const opts = {
|
const opts = {
|
||||||
|
@ -112,4 +93,4 @@ module.exports = {
|
||||||
buildCommand,
|
buildCommand,
|
||||||
populateCSS,
|
populateCSS,
|
||||||
populateConfig
|
populateConfig
|
||||||
};
|
};
|
||||||
|
|
51
ui.js
51
ui.js
|
@ -1,31 +1,19 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const
|
const { updateHTML } = require("./populate");
|
||||||
{
|
const { populateCSS, populateConfig } = require("./build");
|
||||||
updateHTML
|
const { updateCommand } = require("./update");
|
||||||
} = require("./populate");
|
|
||||||
const
|
|
||||||
{
|
|
||||||
populateCSS,
|
|
||||||
populateConfig
|
|
||||||
} = require("./build");
|
|
||||||
const
|
|
||||||
{
|
|
||||||
updateCommand
|
|
||||||
} = require("./update");
|
|
||||||
const app = express();
|
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(
|
app.use(
|
||||||
express.json(
|
express.json({
|
||||||
{
|
|
||||||
limit: "50mb"
|
limit: "50mb"
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
app.use(
|
app.use(
|
||||||
express.urlencoded(
|
express.urlencoded({
|
||||||
{
|
|
||||||
limit: "50mb",
|
limit: "50mb",
|
||||||
extended: true
|
extended: true
|
||||||
})
|
})
|
||||||
|
@ -39,17 +27,13 @@ const jsdom = require("jsdom").JSDOM,
|
||||||
};
|
};
|
||||||
global.DOMParser = new jsdom().window.DOMParser;
|
global.DOMParser = new jsdom().window.DOMParser;
|
||||||
|
|
||||||
function uiCommand()
|
function uiCommand() {
|
||||||
{
|
app.get("/", function(req, res) {
|
||||||
app.get("/", function(req, res)
|
|
||||||
{
|
|
||||||
res.render("index.ejs");
|
res.render("index.ejs");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/update", function(req, res)
|
app.get("/update", function(req, res) {
|
||||||
{
|
if (!fs.existsSync(`${outDir}/config.json`)) {
|
||||||
if (!fs.existsSync(`${outDir}/config.json`))
|
|
||||||
{
|
|
||||||
return res.send(
|
return res.send(
|
||||||
'You need to run build command before using update<br><a href="/">Go Back</a>'
|
'You need to run build command before using update<br><a href="/">Go Back</a>'
|
||||||
);
|
);
|
||||||
|
@ -58,11 +42,9 @@ function uiCommand()
|
||||||
res.redirect("/");
|
res.redirect("/");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/build", function(req, res)
|
app.post("/build", function(req, res) {
|
||||||
{
|
|
||||||
let username = req.body.username;
|
let username = req.body.username;
|
||||||
if (!username)
|
if (!username) {
|
||||||
{
|
|
||||||
return res.send("username can't be empty");
|
return res.send("username can't be empty");
|
||||||
}
|
}
|
||||||
let sort = req.body.sort ? req.body.sort : "created";
|
let sort = req.body.sort ? req.body.sort : "created";
|
||||||
|
@ -75,9 +57,9 @@ function uiCommand()
|
||||||
let email = req.body.email ? req.body.email : null;
|
let email = req.body.email ? req.body.email : null;
|
||||||
let instagram = req.body.instagram ? req.body.instagram : null;
|
let instagram = req.body.instagram ? req.body.instagram : null;
|
||||||
let twitter = req.body.twitter ? req.body.twitter : null;
|
let twitter = req.body.twitter ? req.body.twitter : null;
|
||||||
let background = req.body.background ?
|
let background = req.body.background
|
||||||
req.body.background :
|
? req.body.background
|
||||||
"https://images.unsplash.com/photo-1553748024-d1b27fb3f960?w=1500&q=80";
|
: "https://source.unsplash.com/1600x900/?wallpaper";
|
||||||
let theme = req.body.theme == "on" ? "dark" : "light";
|
let theme = req.body.theme == "on" ? "dark" : "light";
|
||||||
const opts = {
|
const opts = {
|
||||||
sort: sort,
|
sort: sort,
|
||||||
|
@ -93,8 +75,7 @@ function uiCommand()
|
||||||
};
|
};
|
||||||
|
|
||||||
updateHTML(username, opts);
|
updateHTML(username, opts);
|
||||||
populateCSS(
|
populateCSS({
|
||||||
{
|
|
||||||
background: background,
|
background: background,
|
||||||
theme: theme
|
theme: theme
|
||||||
});
|
});
|
||||||
|
@ -111,4 +92,4 @@ function uiCommand()
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
uiCommand
|
uiCommand
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue