Skip to content

Commit

Permalink
Fix skip_render doesn't work in asset generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jan 9, 2016
1 parent c6515ed commit 58971dc
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/models/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = function(ctx) {
var Asset = new Schema({
_id: {type: String, required: true},
path: {type: String, required: true},
modified: {type: Boolean, default: true}
modified: {type: Boolean, default: true},
renderable: {type: Boolean, default: true}
});

Asset.virtual('source').get(function() {
Expand Down
3 changes: 2 additions & 1 deletion lib/models/post_asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = function(ctx) {
_id: {type: String, required: true},
slug: {type: String, required: true},
modified: {type: Boolean, default: true},
post: {type: Schema.Types.CUID, ref: 'Post'}
post: {type: Schema.Types.CUID, ref: 'Post'},
renderable: {type: Boolean, default: true}
});

PostAsset.virtual('path').get(function() {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/generator/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function assetGenerator(locals) {
modified: asset.modified
};

if (self.render.isRenderable(path)) {
if (asset.renderable && self.render.isRenderable(path)) {
// Replace extension name if the asset is renderable
var extname = pathFn.extname(path);
var filename = path.substring(0, path.length - extname.length);
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/processor/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ module.exports = function(ctx) {
return Asset.save({
_id: id,
path: file.path,
modified: changed
modified: changed,
renderable: file.params.renderable
});
});
}
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/processor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ module.exports = function(ctx) {
_id: id,
slug: file.source.substring(post.asset_dir.length),
post: post._id,
modified: changed
modified: changed,
renderable: file.params.renderable
});
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/scripts/generators/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ describe('asset', function() {
});
});

it('skip render', function() {
var path = 'test.yml';
var source = pathFn.join(hexo.base_dir, path);
var content = 'foo: bar';

return Promise.all([
Asset.insert({_id: path, path: path, renderable: false}),
fs.writeFile(source, content)
]).then(function() {
return generator(hexo.locals);
}).then(function(data) {
data[0].path.should.eql('test.yml');
data[0].data.modified.should.be.true;

return checkStream(data[0].data.data(), content);
}).then(function() {
return Promise.all([
Asset.removeById(path),
fs.unlink(source)
]);
});
});

it('remove assets which does not exist', function() {
var path = 'test.txt';

Expand Down
2 changes: 2 additions & 0 deletions test/scripts/processors/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('asset', function() {
asset._id.should.eql(id);
asset.path.should.eql(file.path);
asset.modified.should.be.true;
asset.renderable.should.be.false;

return asset.remove();
}).finally(function() {
Expand Down Expand Up @@ -118,6 +119,7 @@ describe('asset', function() {
asset._id.should.eql(id);
asset.path.should.eql(file.path);
asset.modified.should.be.true;
asset.renderable.should.be.false;

return asset.remove();
}).finally(function() {
Expand Down
1 change: 1 addition & 0 deletions test/scripts/processors/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe('post', function() {
asset._id.should.eql(id);
asset.post.should.eql(postId);
asset.modified.should.be.true;
asset.renderable.should.be.false;
}).finally(function() {
hexo.config.post_asset_folder = false;

Expand Down

0 comments on commit 58971dc

Please sign in to comment.