mirror of
https://github.com/dilllxd/gitfolio.git
synced 2024-08-14 22:28:09 +00:00
9c3538a387
* 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
71 lines
3.1 KiB
JavaScript
71 lines
3.1 KiB
JavaScript
const program = require('commander');
|
|
const fs = require('fs');
|
|
const jsdom = require('jsdom').JSDOM,
|
|
options = {
|
|
resources: "usable"
|
|
};
|
|
|
|
program
|
|
.version('0.1.1')
|
|
.option('-t, --title [title]', 'give blog a title')
|
|
.option('-s, --subtitle [subtitle]', 'give blog a subtitle', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
|
|
.option('-p, --pagetitle [pagetitle]', 'give blog page a title')
|
|
.option('-f, --folder [folder]', 'give folder a title (use "-" instead of spaces)')
|
|
.parse(process.argv);
|
|
|
|
function createBlog(title, subtitle, pagetitle, folder) {
|
|
if (!fs.existsSync(`./dist/blog/${folder}`)){
|
|
fs.mkdirSync(`./dist/blog/${folder}`, { recursive: true });
|
|
}
|
|
fs.copyFile('./assets/blog/blogTemplate.html', `./dist/blog/${folder}/index.html`, (err) => {
|
|
if (err) throw err;
|
|
jsdom.fromFile(`./dist/blog/${folder}/index.html`, options).then(function (dom) {
|
|
let window = dom.window, document = window.document;
|
|
var style = document.createElement("link");
|
|
style.setAttribute("rel","stylesheet")
|
|
style.setAttribute("href","../../index.css");
|
|
document.getElementsByTagName("head")[0].appendChild(style);
|
|
|
|
document.getElementsByTagName("title")[0].textContent = pagetitle;
|
|
document.getElementById("blog_title").textContent = title;
|
|
document.getElementById("blog_sub_title").textContent = subtitle;
|
|
|
|
fs.writeFile(`./dist/blog/${folder}/index.html`, '<!DOCTYPE html>'+window.document.documentElement.outerHTML, function (error){
|
|
if (error) throw error;
|
|
var blog_data = {
|
|
"url_title": pagetitle,
|
|
"title": title,
|
|
"sub_title": subtitle,
|
|
"top_image": "https://images.unsplash.com/photo-1553748024-d1b27fb3f960?w=1450",
|
|
"visible": true }
|
|
fs.readFile("./dist/blog.json", function (err , data) {
|
|
if (err) throw err;
|
|
var old_blogs = JSON.parse(data);
|
|
old_blogs.push(blog_data);
|
|
fs.writeFile('./dist/blog.json', JSON.stringify(old_blogs, null, ' '), function(err){
|
|
if (err) throw err;
|
|
console.log('Blog Created Successfully in "blog" folder.');
|
|
});
|
|
});
|
|
});
|
|
}).catch(function(error){
|
|
console.log(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
if (program.title) {
|
|
/* Check if build has been executed before blog this will prevent it from giving "link : index.css" error */
|
|
if (!fs.existsSync(`./dist/index.html`) || !fs.existsSync(`./dist/index.css`)){
|
|
return console.log("You need to run build command before using blog one");
|
|
}
|
|
if (!program.pagetitle) {
|
|
program.pagetitle = program.title;
|
|
}
|
|
if (!program.folder) {
|
|
program.folder = program.title;
|
|
}
|
|
createBlog(program.title, program.subtitle, program.pagetitle, program.folder);
|
|
} else {
|
|
console.log("Provide a title to create a new blog");
|
|
}
|