Extract album creation as separate step + consolidate progress bar logic

pull/47/head
Romain 8 years ago
parent ed605abeb4
commit b023b72cc0

@ -1,9 +1,11 @@
var fs = require('fs-extra');
var pad = require('pad');
var path = require('path');
var async = require('async');
var make = require('./utils/make');
var metadata = require('./input/metadata');
var thumbs = require('./output-media/thumbs');
var hierarchy = require('./output-website/album-hierarchy.js')
var website = require('./output-website/website');
var collection = require('./collection');
@ -14,7 +16,12 @@ exports.build = function(opts) {
fs.mkdirpSync(opts.output);
var media = path.join(opts.output, 'media');
var meta = null;
// ---------------------
// These variables are set later during the async phase
// ---------------------
var meta = null; // metadata file to be read later
var album = null; // root album with nested albums
var allFiles = collection.fromMetadata({});
function buildStep(options) {
@ -27,6 +34,21 @@ exports.build = function(opts) {
}
}
function callbackStep(name, fn) {
return function(next) {
process.stdout.write(pad(name, 20));
fn(function(err) {
if (err) {
console.log('[====================] error');
next(err);
} else {
console.log('[====================] done');
next();
}
});
}
}
function copyFile(task, callback) {
fs.copy(task.src, task.dest, callback);
}
@ -92,9 +114,14 @@ exports.build = function(opts) {
func: thumbs.videoSquare
}),
function staticWebsite(callback) {
website.build(allFiles, opts, callback);
}
callbackStep('Album hierarchy', function(next) {
albums = hierarchy.from(allFiles, opts);
next();
}),
callbackStep('Static website', function(next) {
website.build(albums, opts, next);
})
], finish);

@ -0,0 +1,27 @@
var _ = require('lodash');
var gm = require('gm');
var pad = require('pad');
var path = require('path');
var Album = require('./album');
var byFolder = require('./by-folder');
var byDate = require('./by-date');
exports.from = function(collection, opts) {
// top-level album for the home page
var home = new Album('Home');
home.filename = opts.index || 'index';
// create albums
if (opts.albumsFrom === 'folders') {
home.albums = byFolder.albums(collection, opts);
} else if (opts.albumsFrom === 'date') {
home.albums = byDate.albums(collection, opts);
} else {
throw 'Invalid <albumsFrom> option';
}
// finalize all albums recursively (calculate stats, etc...)
home.finalize();
return home;
};

@ -13,27 +13,15 @@ var byDate = require('./by-date');
var DIR_PUBLIC = path.join(__dirname, '..', '..', 'public');
var DIR_TEMPLATES = path.join(__dirname, '..', '..', 'templates');
exports.build = function(collection, opts, callback) {
exports.build = function(rootAlbum, opts, callback) {
// create the right renderer (theme, download path, etc...)
var renderer = template.create(opts);
function website(callback) {
// top-level album for the home page
var home = new Album('Home');
home.filename = opts.index || 'index';
// create albums
if (opts.albumsFrom === 'folders') {
home.albums = byFolder.albums(collection, opts);
} else if (opts.albumsFrom === 'date') {
home.albums = byDate.albums(collection, opts);
} else {
throw 'Invalid <albumsFrom> option';
}
home.finalize();
// create top level gallery
var gallery = {
home: home,
home: rootAlbum,
css: opts.css ? path.basename(opts.css) : null,
title: opts.title,
titleWords: opts.title.split(' '),
@ -42,7 +30,7 @@ exports.build = function(collection, opts, callback) {
googleAnalytics: opts.googleAnalytics
};
// render entire album hierarchy
var tasks = renderAlbum(gallery, [], home);
var tasks = renderAlbum(gallery, [], rootAlbum);
async.parallel(tasks, callback);
}
@ -98,14 +86,12 @@ exports.build = function(collection, opts, callback) {
});
}
process.stdout.write(pad('Static website', 20));
async.series([
website,
support,
website,
lightGallery,
renderStyles
], function(err) {
console.log('[====================] done');
callback(err);
});

Loading…
Cancel
Save