From 2fbf0f7f3e88a94c975d875cde4263245c9648b1 Mon Sep 17 00:00:00 2001 From: Tomas Varga Date: Mon, 31 Oct 2016 00:09:48 +0100 Subject: [PATCH] Added default config file, adjusted logging priorities --- .gitignore | 1 + README.md | 19 +++++++++---------- config.json | 5 +++++ package.json | 9 ++++----- src/index.js | 21 +++++++++++---------- 5 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 config.json diff --git a/.gitignore b/.gitignore index 3c3629e..93f1361 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +npm-debug.log diff --git a/README.md b/README.md index 15c9804..5f9f838 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Gallery Maker for Node -A static html gallery maker based on Node. +A Node based static html gallery maker. ## Usage @@ -17,26 +17,25 @@ Commands: as a source for image captions. list Prepares gallery contents list html (list.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 - ~~image processing test~~ - ~~read images from a dir~~ - ~~resize the images~~ - ~~save them with sanitized names~~ -- create html frontend for image list - - ~~list the images~~ - - provide thumbnails +- create html frontend for file list + - ~~list the images (text based)~~ - provide <img/> tag literals for copy-pasting - 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 - further development - integration with other projects (iframe? ajax? web component? Polymer?) - ~~config.json support (for specifying conversion settings)~~ + +## Attributions + +Image processing done by [sharp](http://sharp.dimens.io/) ([github](https://github.com/lovell/sharp)). diff --git a/config.json b/config.json new file mode 100644 index 0000000..f8b7913 --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "width": 700, + "quality": 80, + "debug": true +} diff --git a/package.json b/package.json index eb61a36..3c57dc9 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,16 @@ { "name": "gallerymaker", - "version": "0.0.1", + "version": "0.0.2", "description": "A static html gallery maker", "keywords": [ "gallery", "images", "static" ], - "main": "src/index.js", - "scripts": { - "serve": "node scripts/server.dev.js", - "test": "node test/index.js" + "engines": { + "node": ">=4" }, + "main": "src/index.js", "eslintConfig": { "env": { "browser": true, diff --git a/src/index.js b/src/index.js index fa90cea..795592f 100644 --- a/src/index.js +++ b/src/index.js @@ -26,7 +26,7 @@ if (!conf.templates.index) conf.templates.index = 'index.html'; if (!conf.assets) conf.assets = {}; // clientDir if (!conf.assets.common) conf.assets.common = ['index.js', 'index.css']; 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 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 cmds = { - prepare: () => prepareImages().then(copyAssets('common')), + prepare: () => prepareImages().then(() => copyAssets('common')), list: generateList, gallery: generateGallery, all: () => prepareImages() @@ -53,7 +53,7 @@ var cmds = { generateList(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) { @@ -88,7 +88,7 @@ else { } function prepareImages() { - log('Preparing images - recreating gallery directories with sanitized names and resized images') + log('Preparing content') return mirrorDirTree(idir, (file, srcDir, destDir) => { var fname = sanitize(file); @@ -100,14 +100,14 @@ function prepareImages() { .toFile(path.join(destDir, fname)) .then(() => ({ file: fname, name: name })) .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 })) ); }) .then(cont => utils.writeFile(cont, 'content.json', odir)) .then(cont => { - //log('Preparing images finished. Content:', util.inspect(cont, { showHidden: false, depth: null })); - log('Preparing images finished:', ['content.json'].concat(cont.cont.map(c => c.dir)).join(', ')); + //log('Preparing images done. Content:', util.inspect(cont, { showHidden: false, depth: null })); + console.log('Preparing content done:', ['content.json'].concat(cont.cont.map(c => c.dir)).join(', ')); return cont; }); } @@ -122,7 +122,7 @@ function generateList(cont) { utils.writeFile(html, conf.fnames.list, odir, true) ])) .then(res => { - log('Generating file list finished:', res.join(', ')); + console.log('Generating file list done:', res.join(', ')); return res; }); } @@ -137,7 +137,7 @@ function generateGallery(cont) { utils.writeFile(html, conf.fnames.gallery, odir, true) ])) .then(files => { - log('Generating gallery finished:', files.join(', ')); + console.log('Generating gallery done:', files.join(', ')); return files; }); } @@ -148,7 +148,7 @@ function copyAssets(asskey) { return Promise.all(fnames.map(fname => utils.copyFile(clientDir, fname, odir))) .then(files => { - log('Copying', asskey, 'assets finished:', files.join(', ')); + console.log('Copying', asskey, 'assets done:', files.join(', ')); return files; }); } @@ -187,6 +187,7 @@ function mirrorDirTree(dir, cb, nomkdir, depth) { .then(items => { logi(depth, '[dir]', dir); 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)); return { dir: destDir.replace(/^.*\//, ''), name: dir.replace(/^.*\//, ''), cont: items }; });