diff --git a/lib/models/asset.js b/lib/models/asset.js index 21ec75817a..ecfeb1381f 100644 --- a/lib/models/asset.js +++ b/lib/models/asset.js @@ -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() { diff --git a/lib/models/post_asset.js b/lib/models/post_asset.js index 6d78fe28da..075ed60aed 100644 --- a/lib/models/post_asset.js +++ b/lib/models/post_asset.js @@ -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() { diff --git a/lib/plugins/generator/asset.js b/lib/plugins/generator/asset.js index 890de6a25b..87f907f24e 100644 --- a/lib/plugins/generator/asset.js +++ b/lib/plugins/generator/asset.js @@ -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); diff --git a/lib/plugins/processor/asset.js b/lib/plugins/processor/asset.js index 495618376f..bf49e6ee47 100644 --- a/lib/plugins/processor/asset.js +++ b/lib/plugins/processor/asset.js @@ -102,7 +102,8 @@ module.exports = function(ctx) { return Asset.save({ _id: id, path: file.path, - modified: changed + modified: changed, + renderable: file.params.renderable }); }); } diff --git a/lib/plugins/processor/post.js b/lib/plugins/processor/post.js index fd98f1eefb..f668822a6e 100644 --- a/lib/plugins/processor/post.js +++ b/lib/plugins/processor/post.js @@ -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 }); } } diff --git a/test/scripts/generators/asset.js b/test/scripts/generators/asset.js index aae0e85c97..105ceddc16 100644 --- a/test/scripts/generators/asset.js +++ b/test/scripts/generators/asset.js @@ -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'; diff --git a/test/scripts/processors/asset.js b/test/scripts/processors/asset.js index 08f2f7b2de..d25149292f 100644 --- a/test/scripts/processors/asset.js +++ b/test/scripts/processors/asset.js @@ -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() { @@ -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() { diff --git a/test/scripts/processors/post.js b/test/scripts/processors/post.js index 41d71878cd..4009f9cd01 100644 --- a/test/scripts/processors/post.js +++ b/test/scripts/processors/post.js @@ -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;