Skip to content

Commit

Permalink
Merge pull request #3399 from xiaomingplus/master
Browse files Browse the repository at this point in the history
fix: Global asset folder not working when source dir is changed  another path (#3398)
  • Loading branch information
yoshinorin authored Mar 24, 2019
2 parents 6b9acc0 + 2a96c85 commit 979c988
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/processor/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const common = require('./common');
const Promise = require('bluebird');
const yfm = require('hexo-front-matter');
const { extname } = require('path');
const { extname, relative } = require('path');
const { Pattern } = require('hexo-util');

module.exports = ctx => {
Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports = ctx => {
}

function processAsset(file) {
const id = file.source.substring(ctx.base_dir.length).replace(/\\/g, '/');
const id = relative(ctx.base_dir, file.source).replace(/\\/g, '/');
const Asset = ctx.model('Asset');
const doc = Asset.findById(id);

Expand Down
21 changes: 21 additions & 0 deletions test/scripts/processors/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,28 @@ describe('asset', () => {
return asset.remove();
}).finally(() => fs.unlink(file.source));
});
it('asset - type: create (when source path is configed to parent directory)', () => {
const file = newFile({
path: '../../source/foo.jpg',
type: 'create',
renderable: false
});

return fs.writeFile(file.source, 'foo').then(() => process(file)).then(() => {
const id = '../source/foo.jpg'; // The id should a relative path,because the 'lib/models/assets.js' use asset path by joining base path with "_id" directly.
const asset = Asset.findById(id);

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(() => {
fs.unlink(file.source);
fs.rmdir(pathFn.dirname(file.source));
});
});
it('asset - type: update', () => {
const file = newFile({
path: 'foo.jpg',
Expand Down

0 comments on commit 979c988

Please sign in to comment.