1
0
mirror of https://github.com/tomasvarg/gallerymaker.git synced 2026-03-01 08:28:48 +00:00

Added default config file, adjusted logging priorities

This commit is contained in:
Tomas Varga 2016-10-31 00:09:48 +01:00
parent 7c8b5188da
commit 2fbf0f7f3e
5 changed files with 30 additions and 25 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules node_modules
npm-debug.log

View File

@ -1,6 +1,6 @@
# Gallery Maker for Node # Gallery Maker for Node
A static html gallery maker based on Node. A Node based static html gallery maker.
## Usage ## Usage
@ -17,26 +17,25 @@ Commands:
as a source for image captions. as a source for image captions.
list Prepares gallery contents list html (list.html). list Prepares gallery contents list html (list.html).
gallery Prepares gallery contents html (gallery.html). gallery Prepares gallery contents html (gallery.html).
all Runs all the commands (with proper chaning - prepare first). all Runs all the commands (properly chanined - prepare first).
``` ```
## Image Processing
Image resizing done by [sharp](http://sharp.dimens.io/) ([github](https://github.com/lovell/sharp)).
## TODO ## TODO
- ~~image processing test~~ - ~~image processing test~~
- ~~read images from a dir~~ - ~~read images from a dir~~
- ~~resize the images~~ - ~~resize the images~~
- ~~save them with sanitized names~~ - ~~save them with sanitized names~~
- create html frontend for image list - create html frontend for file list
- ~~list the images~~ - ~~list the images (text based)~~
- provide thumbnails
- provide <img/> tag literals for copy-pasting - provide <img/> tag literals for copy-pasting
- create the gallery - create the gallery
- site index page creation (from a template) with gallery integration - list the images (thumbnail based)
- use some lightbox on the prepared directory - use some lightbox on the prepared directory
- further development - further development
- integration with other projects (iframe? ajax? web component? Polymer?) - integration with other projects (iframe? ajax? web component? Polymer?)
- ~~config.json support (for specifying conversion settings)~~ - ~~config.json support (for specifying conversion settings)~~
## Attributions
Image processing done by [sharp](http://sharp.dimens.io/) ([github](https://github.com/lovell/sharp)).

5
config.json Normal file
View File

@ -0,0 +1,5 @@
{
"width": 700,
"quality": 80,
"debug": true
}

View File

@ -1,17 +1,16 @@
{ {
"name": "gallerymaker", "name": "gallerymaker",
"version": "0.0.1", "version": "0.0.2",
"description": "A static html gallery maker", "description": "A static html gallery maker",
"keywords": [ "keywords": [
"gallery", "gallery",
"images", "images",
"static" "static"
], ],
"main": "src/index.js", "engines": {
"scripts": { "node": ">=4"
"serve": "node scripts/server.dev.js",
"test": "node test/index.js"
}, },
"main": "src/index.js",
"eslintConfig": { "eslintConfig": {
"env": { "env": {
"browser": true, "browser": true,

View File

@ -26,7 +26,7 @@ if (!conf.templates.index) conf.templates.index = 'index.html';
if (!conf.assets) conf.assets = {}; // clientDir if (!conf.assets) conf.assets = {}; // clientDir
if (!conf.assets.common) conf.assets.common = ['index.js', 'index.css']; if (!conf.assets.common) conf.assets.common = ['index.js', 'index.css'];
if (!conf.ignored_files || !conf.ignored_files.push) conf.ignored_files = []; if (!conf.ignored_files || !conf.ignored_files.push) conf.ignored_files = [];
if (conf.debug === undefined) conf.debug = true; if (conf.debug === undefined) conf.debug = false;
for (var ak in conf.assets) conf.ignored_files.push.apply(conf.ignored_files, conf.assets[ak]); for (var ak in conf.assets) conf.ignored_files.push.apply(conf.ignored_files, conf.assets[ak]);
for (var fk in conf.fnames) conf.ignored_files.push(conf.fnames[fk]); for (var fk in conf.fnames) conf.ignored_files.push(conf.fnames[fk]);
@ -43,7 +43,7 @@ var logi = function () {
var ind = depth => utils.indent(depth, DEPTH); var ind = depth => utils.indent(depth, DEPTH);
var cmds = { var cmds = {
prepare: () => prepareImages().then(copyAssets('common')), prepare: () => prepareImages().then(() => copyAssets('common')),
list: generateList, list: generateList,
gallery: generateGallery, gallery: generateGallery,
all: () => prepareImages() all: () => prepareImages()
@ -53,7 +53,7 @@ var cmds = {
generateList(cont), generateList(cont),
generateGallery(cont) generateGallery(cont)
])) ]))
.then(res => log('All tasks finished! Files:', res.reduce((c, n) => c.concat(n), []).join(', '))) .then(res => log('All tasks done! Files:', res.reduce((c, n) => c.concat(n), []).join(', ')))
}; };
if (!cmd || !idir) { if (!cmd || !idir) {
@ -88,7 +88,7 @@ else {
} }
function prepareImages() { function prepareImages() {
log('Preparing images - recreating gallery directories with sanitized names and resized images') log('Preparing content')
return mirrorDirTree(idir, (file, srcDir, destDir) => { return mirrorDirTree(idir, (file, srcDir, destDir) => {
var fname = sanitize(file); var fname = sanitize(file);
@ -100,14 +100,14 @@ function prepareImages() {
.toFile(path.join(destDir, fname)) .toFile(path.join(destDir, fname))
.then(() => ({ file: fname, name: name })) .then(() => ({ file: fname, name: name }))
.catch(sharpErr => utils.copyFile(srcDir, file, destDir, fname) .catch(sharpErr => utils.copyFile(srcDir, file, destDir, fname)
.then(() => ({ file: fname, name: name, error: '' + sharpErr })) .then(() => ({ file: fname, name: name, warn: '' + sharpErr }))
.catch(writeErr => ({ file: '', name: name, error: writeErr })) .catch(writeErr => ({ file: '', name: name, error: writeErr }))
); );
}) })
.then(cont => utils.writeFile(cont, 'content.json', odir)) .then(cont => utils.writeFile(cont, 'content.json', odir))
.then(cont => { .then(cont => {
//log('Preparing images finished. Content:', util.inspect(cont, { showHidden: false, depth: null })); //log('Preparing images done. Content:', util.inspect(cont, { showHidden: false, depth: null }));
log('Preparing images finished:', ['content.json'].concat(cont.cont.map(c => c.dir)).join(', ')); console.log('Preparing content done:', ['content.json'].concat(cont.cont.map(c => c.dir)).join(', '));
return cont; return cont;
}); });
} }
@ -122,7 +122,7 @@ function generateList(cont) {
utils.writeFile(html, conf.fnames.list, odir, true) utils.writeFile(html, conf.fnames.list, odir, true)
])) ]))
.then(res => { .then(res => {
log('Generating file list finished:', res.join(', ')); console.log('Generating file list done:', res.join(', '));
return res; return res;
}); });
} }
@ -137,7 +137,7 @@ function generateGallery(cont) {
utils.writeFile(html, conf.fnames.gallery, odir, true) utils.writeFile(html, conf.fnames.gallery, odir, true)
])) ]))
.then(files => { .then(files => {
log('Generating gallery finished:', files.join(', ')); console.log('Generating gallery done:', files.join(', '));
return files; return files;
}); });
} }
@ -148,7 +148,7 @@ function copyAssets(asskey) {
return Promise.all(fnames.map(fname => utils.copyFile(clientDir, fname, odir))) return Promise.all(fnames.map(fname => utils.copyFile(clientDir, fname, odir)))
.then(files => { .then(files => {
log('Copying', asskey, 'assets finished:', files.join(', ')); console.log('Copying', asskey, 'assets done:', files.join(', '));
return files; return files;
}); });
} }
@ -187,6 +187,7 @@ function mirrorDirTree(dir, cb, nomkdir, depth) {
.then(items => { .then(items => {
logi(depth, '[dir]', dir); logi(depth, '[dir]', dir);
items.forEach(item => logi(depth + 1, item.error ? '[error] ' + item.file + ' ' + item.error items.forEach(item => logi(depth + 1, item.error ? '[error] ' + item.file + ' ' + item.error
: item.warn ? '[warn] ' + item.file + ' ' + item.warn
: item.file ? '[file] ' + item.file : item.dir ? '[dir] ' + item.dir : item)); : item.file ? '[file] ' + item.file : item.dir ? '[dir] ' + item.dir : item));
return { dir: destDir.replace(/^.*\//, ''), name: dir.replace(/^.*\//, ''), cont: items }; return { dir: destDir.replace(/^.*\//, ''), name: dir.replace(/^.*\//, ''), cont: items };
}); });