Skip to content
Snippets Groups Projects
Verified Commit adf46878 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Option --themedir

parent 83dab11b
No related branches found
No related tags found
No related merge requests found
......@@ -51,19 +51,19 @@ var sitegin = function(config) {
.catch(function(e) {
isRunning = false;
console.log('Generator crashed in',moment().diff(startTime,'seconds'),'seconds')
if(config.options.noserver) process.exit(13);
if(runAgain) run();
if(e.stack)
console.log(e.stack)
else
console.log(e)
if(config.options.noserver) process.exit(13);
});
}
console.log('Sitegin successfully loaded');
run();
copyStaticFiles(config.builddir, config.staticDir);
rendersass(config.builddir);
copyStaticFiles(config.builddir, config.staticDir, config.themeDir);
rendersass(config.builddir, config.themeDir);
if(!options.noserver) {
var sync = require('browser-sync').create();
......@@ -82,7 +82,7 @@ var sitegin = function(config) {
var chokidar = require('chokidar');
// article or theme reload
chokidar.watch([config.sourceDir,'theme/'], {ignoreInitial: true})
chokidar.watch([config.sourceDir,config.themeDir], {ignoreInitial: true})
.on('all', function(event, path) {
console.log('Content or theme changed. Rebuilding...');
run();
......@@ -101,7 +101,7 @@ var sitegin = function(config) {
});
}
var copyStaticFiles = function(builddir, staticdir) {
var copyStaticFiles = function(builddir, staticdir,themedir) {
// STATIC FILES
var fsextra = require('node-fs-extra');
fsextra.copy(
......@@ -116,19 +116,19 @@ var copyStaticFiles = function(builddir, staticdir) {
function(){console.log('copy static/articles done');}
);
fsextra.copy(
'theme/static',
themedir+'/static',
builddir,
function(file){ return !file.match('\\.git') },
function(){console.log('copy theme/static done');}
function(){console.log('copy '+themedir+'/static done');}
);
}
var rendersass = function(builddir) {
var rendersass = function(builddir, themedir) {
// SASS
var sass = require('node-sass');
var fs = require('fs');
sass.render ({file: 'theme/sass/style.scss'},function(err, result) {
sass.render ({file: themedir+'/sass/style.scss'},function(err, result) {
if(err === null) {
console.log('compiled sass');
fs.writeFile(builddir+'/theme/style.css',result.css);
......
......@@ -13,15 +13,18 @@ var options = cli.parse({
uiport: [null, 'BrowserSync UI port', 'number', 'port+1'],
httpsonly: [null, 'Converts all http://ok1kvk.cz links to https'],
httponly: [null, 'Converts all https://ok1kvk.cz links to http'],
contentdir: [null, 'Allows to specify arbitrary content directory. '+
'Can also be http(s) url to zip file.', 'string', 'content'],
staticdir: [null, 'Allows to specify arbitrary directory for static files. '+
'Can also be http(s) url to zip file.', 'string', 'static']
contentdir: [null, 'Allows to specify arbitrary content directory.', 'string', 'static'],
themedir: [null, 'Allows to specify arbitrary content directory.', 'string', 'theme'],
builddir: [null, 'Allows to specify arbitrary content directory.', 'string', null],
staticdir: [null, 'Allows to specify arbitrary directory for static files.', 'string', 'static']
});
module.exports = function() {
console.log('Build step: Config');
var builddir = 'build';
if(!options.noserver) builddir = 'build-debug';
if(options.builddir)
builddir = options.builddir;
else if(!options.noserver) builddir = 'build-debug';
if(options.uiport == 'port+1') {
options.uiport = options.port+1;
......@@ -34,6 +37,7 @@ module.exports = function() {
builddir: builddir,
sourceDir: options.contentdir,
staticDir: options.staticdir,
themeDir: options.themedir,
articlesLocation: 'articles',
linksPerPage: 6
}});
......@@ -42,3 +46,4 @@ module.exports = function() {
})
}
module.exports.watch = !options.noserver;
module.exports.themeDir = options.themedir;
......@@ -7,7 +7,7 @@ var nodegit = require('nodegit');
var path = require('path');
var moment = require('moment');
var pathToRepo = path.resolve('content');
var pathToRepo;
// Returns promise for patch of single commit
var gitShow = function(repo, commitData) {
......@@ -116,6 +116,8 @@ var getFilesHistory = function() {
}
module.exports = function(obj) {
console.log('Build step: GitInfo');
pathToRepo = path.resolve(obj.config.sourceDir);
return getFilesHistory()
.then((filesHistory) => {
obj.pages.forEach(function(article) {
......
......@@ -113,6 +113,7 @@ marked.setOptions({
});
module.exports = function(obj) {
console.log('Build step: Markdown');
var options = obj.config.options;
renderer.link = function(href, title, text) {
if(options.httponly) {
......
......@@ -8,10 +8,10 @@ var fs = require('fs');
var dateFilter = require('nunjucks-date-filter');
var util = require('util');
var watch = require('./config').watch;
console.log('watch: '+watch);
var config = require('./config');
console.log('watch: '+config.watch);
var env = new nunjucks.Environment(
new nunjucks.FileSystemLoader('theme/templates',{watch: watch})
new nunjucks.FileSystemLoader(config.themeDir+'/templates',{watch: config.watch})
);
env.addFilter('date', dateFilter);
......@@ -56,8 +56,11 @@ module.exports = function(data, type) {
return new Promise(function(resolve, reject) {
if(formats[type]) resolve(formats[type]);
else {
fs.readdir('theme/templates',function(err, files) {
if(err) return reject(new Error('Error listing files in theme/templates'));
fs.readdir(config.themeDir+'/templates',function(err, files) {
if(err) {
console.log(config);
return reject(new Error('Error listing files in '+config.themeDir+'/templates'));
}
files = files.filter(function(file) {
return file.match(type+'\..*\.nunj');
......@@ -66,8 +69,8 @@ module.exports = function(data, type) {
var filteredFiles = [];
var todo = 0;
files.forEach(function(file) {
fs.stat('theme/templates/'+file,function(err, stat) {
if(err) reject(new Error('Error stating theme/templates/'+file));
fs.stat(config.themeDir+'/templates/'+file,function(err, stat) {
if(err) reject(new Error('Error stating '+config.themeDir+'/templates'+file));
if(stat.isFile())
filteredFiles.push(file);
todo--;
......
......@@ -27,6 +27,7 @@ var readPageWorker = function(content, obj) {
}
module.exports = function(obj) {
console.log('Build step: ParseHugo');
return new Promise(function(resolve, reject) {
var pages = [];
obj.pages.forEach(function(page) {
......
......@@ -6,6 +6,7 @@ var fs = require('fs');
var path = require('path');
module.exports = function(obj) {
console.log('Build step: ReadFiles');
return new Promise(function(resolve, reject) {
var pages = [];
walk.walk(path.join(obj.config.sourceDir,obj.config.articlesLocation))
......
var fs = require('fs');
module.exports = function(obj) {
console.log('Build step: Sitemap');
return new Promise(function(resolve, reject) {
var file = '<?xml version="1.0" encoding="UTF-8"?>\n'+
'<urlset\n'+
......
......@@ -8,6 +8,7 @@ var toURL = function(url) {
}
module.exports = function(obj) {
console.log('Build step: Tags');
return new Promise(function(resolve, reject) {
var tags = [];
var tagPages = {};
......
var jobs = require('./jobs');
module.exports = function(obj) {
console.log('Build step: Theme');
return new Promise(function(resolve,reject){
var todo = 0;
var done = function(){
......
......@@ -3,6 +3,7 @@
*/
module.exports = function(obj) {
console.log('Build step: URLs');
return new Promise(function(resolve, reject) {
obj.pages.forEach(function(page) {
var file = page.file;
......
......@@ -4,6 +4,7 @@ var path = require('path');
var mkdirp = require('mkdirp');
module.exports = function(obj) {
console.log('Build step: WriteFiles');
return new Promise(function(resolve,reject) {
var builddir = obj.config.builddir;
var todo = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment