mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
Added tool for generating original filename
- this allows us to have a shared tool for generating _o filenames
This commit is contained in:
parent
6d6785ae99
commit
46d95ed306
@ -1,6 +1,7 @@
|
|||||||
const Promise = require('bluebird');
|
const Promise = require('bluebird');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NOTE: Sharp cannot operate on the same image path, that's why we have to use in & out paths.
|
* @NOTE: Sharp cannot operate on the same image path, that's why we have to use in & out paths.
|
||||||
@ -80,6 +81,12 @@ const makeSafe = fn => (...args) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generateOriginalImageName = (originalPath) => {
|
||||||
|
const parsedFileName = path.parse(originalPath);
|
||||||
|
return path.join(parsedFileName.dir, `${parsedFileName.name}_o${parsedFileName.ext}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.generateOriginalImageName = generateOriginalImageName;
|
||||||
module.exports.canTransformFileExtension = canTransformFileExtension;
|
module.exports.canTransformFileExtension = canTransformFileExtension;
|
||||||
module.exports.resizeFromPath = makeSafe(unsafeResizeFromPath);
|
module.exports.resizeFromPath = makeSafe(unsafeResizeFromPath);
|
||||||
module.exports.resizeFromBuffer = makeSafe(unsafeResizeFromBuffer);
|
module.exports.resizeFromBuffer = makeSafe(unsafeResizeFromBuffer);
|
||||||
|
@ -132,4 +132,13 @@ describe('Transform', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('generateOriginalImageName', function () {
|
||||||
|
it('correctly adds suffix', function () {
|
||||||
|
transform.generateOriginalImageName('test.jpg').should.eql('test_o.jpg');
|
||||||
|
transform.generateOriginalImageName('content/images/test.jpg').should.eql('content/images/test_o.jpg');
|
||||||
|
transform.generateOriginalImageName('content/images/test_o.jpg').should.eql('content/images/test_o_o.jpg');
|
||||||
|
transform.generateOriginalImageName('content/images/test-1.jpg').should.eql('content/images/test-1_o.jpg');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user