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
npm-debug.log

View File

@ -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)).

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",
"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,

View File

@ -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 };
});