Skip to content

Commit

Permalink
Only persist blogdown.meta when publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Apr 28, 2013
1 parent 86e129c commit ecfbfc3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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 : '<p>parsed from markdown</p>',

Expand Down
4 changes: 3 additions & 1 deletion lib/blogdown.js
Expand Up @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion test/blogdown-test.js
Expand Up @@ -245,6 +245,7 @@ test('blogdown', {
});
renderer.render.returns([]);
writer.write.yields();
this.options.meta = { publish : true };

blogdown('source', 'target', this.options, function () {});

Expand All @@ -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 () {});

Expand All @@ -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);
Expand All @@ -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 : [] });
Expand Down

0 comments on commit ecfbfc3

Please sign in to comment.