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

Added extra functionality to blog creation

This commit is contained in:
Benjamin Stigsen 2019-05-09 20:30:36 +02:00 committed by GitHub
parent ecc8467857
commit 37e0160a35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

41
blog.js
View file

@ -8,26 +8,34 @@ options = {
program
.version('0.1.1')
.option('-t, --title [title]', 'give blog a title')
.option('-t, --subtitle [subtitle]', 'give blog asubtitle', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
.option('-t, --pagetitle [pagetitle]', 'give page a title')
.option('-t, --folder [folder]', 'give folder a title')
.parse(process.argv);
function createBlog(title) {
if (!fs.existsSync(`./blog/${title}`)){
fs.mkdirSync(`./blog/${title}`);
function createBlog(title, subtitle, pagetitle, folder) {
if (!fs.existsSync(`./blog/${folder}`)){
fs.mkdirSync(`./blog/${folder}`);
}
fs.copyFile('./blog/blog_template.html', `./blog/${title}/index.html`, (err) => {
fs.copyFile('./blog/blog_template.html', `./blog/${folder}/index.html`, (err) => {
if (err) throw err;
jsdom.fromFile(`./blog/${title}/index.html`, options).then(function (dom) {
jsdom.fromFile(`./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);
fs.writeFile(`./blog/${title}/index.html`, '<!DOCTYPE html>'+window.document.documentElement.outerHTML, function (error){
document.getElementsByTagName("title")[0].textContent = pagetitle;
document.getElementById("blog_title").textContent = title;
document.getElementById("blog_sub_title").textContent = subtitle;
fs.writeFile(`./blog/${folder}/index.html`, '<!DOCTYPE html>'+window.document.documentElement.outerHTML, function (error){
if (error) throw error;
var blog_data = {
"url_title": title,
"title": "Lorem ipsum dolor sit amet",
"sub_title": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"url_title": pagetitle,
"title": title,
"sub_title": subtitle,
"top_image": "https://images.unsplash.com/photo-1553748024-d1b27fb3f960?w=1450",
"visible": true }
fs.readFile("./blog/blog.json", function (err , data) {
@ -47,7 +55,18 @@ function createBlog(title) {
}
if (program.title) {
createBlog(('%s', program.title));
if (!program.pagetitle) {
program.pagetitle = program.title;
}
if (!program.folder) {
program.folder = program.title;
}
program.folder = program.folder.replace(/[^A-Za-z0-9_-\s]/g, "").trim();
program.folder = program.folder.replace(/\s/g, "-");
createBlog(program.title, program.subtitle, program.pagetitle, program.folder);
} else {
console.log("provide a title to create a new blog");
}
}