diff --git a/CHANGES.md b/CHANGES.md index b13d201..0e5b4c2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ - A global `publish` flag is available to all files which allows to exclude some things from rendering when testing the site locally (e.g. analytics scripts) +- Only writing the meta file when called with `--publish` - Always generate all the output files and compare them with what already exists in the target directory. This makes `--force` obsolete, hence it was removed. diff --git a/README.md b/README.md index cf09b7f..2398d13 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,9 @@ The model of each item that is passed to Mustache for rendering looks like this: active : true // if this file is currently rendered, otherwise false }, + // True if blogdown was called with --publish, otherwise false + publish : true, + // Markdown: md : '

parsed from markdown

', diff --git a/lib/blogdown.js b/lib/blogdown.js index 72ba0ee..db9a59f 100644 --- a/lib/blogdown.js +++ b/lib/blogdown.js @@ -40,10 +40,12 @@ module.exports = function (source, target, options, callback) { writer.write(files, target, function (err) { if (err) { callback(err); - } else { + } else if (metaOptions.publish) { meta.persist(metaResult.meta, metaOptions, function (err) { callback(err, { files : files.length }); }); + } else { + callback(null, { files : files.length }); } }); if (metaResult.deleted.length) { diff --git a/test/blogdown-test.js b/test/blogdown-test.js index 159ff1f..7da6932 100644 --- a/test/blogdown-test.js +++ b/test/blogdown-test.js @@ -245,6 +245,7 @@ test('blogdown', { }); renderer.render.returns([]); writer.write.yields(); + this.options.meta = { publish : true }; blogdown('source', 'target', this.options, function () {}); @@ -258,7 +259,7 @@ test('blogdown', { meta.update.yields(null, EMPTY_META_RESULT); renderer.render.returns([]); writer.write.yields(); - this.options.meta = { file : 'other.meta' }; + this.options.meta = { file : 'other.meta', publish : true }; blogdown('source', 'target', this.options, function () {}); @@ -272,6 +273,7 @@ test('blogdown', { meta.update.yields(null, EMPTY_META_RESULT); renderer.render.returns([]); writer.write.yields(); + this.options.meta = { publish : true }; var spy = sinon.spy(); blogdown('source', 'target', this.options, spy); @@ -284,6 +286,20 @@ test('blogdown', { }, + 'yields without persisting if publish is false': function () { + reader.read.yields(null, { items : [] }); + meta.update.yields(null, EMPTY_META_RESULT); + renderer.render.returns([]); + writer.write.yields(); + var spy = sinon.spy(); + + blogdown('source', 'target', this.options, spy); + + sinon.assert.notCalled(meta.persist); + sinon.assert.calledOnce(spy); + }, + + 'logs files that may be deleted': sinon.test(function () { this.stub(console, 'warn'); reader.read.yields(null, { items : [] });