0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

Merge pull request #4465 from jaswilli/subdir-image-url

Fix invalid image helper URLs when using a subdir.
This commit is contained in:
Hannah Wolfe 2014-11-17 13:51:18 +00:00
commit 06544a0cb0
2 changed files with 44 additions and 0 deletions

View file

@ -139,6 +139,9 @@ function urlFor(context, data, absolute) {
imagePathRe = new RegExp('^' + ghostConfig.paths.subdir + '/' + ghostConfig.paths.imagesRelPath);
absolute = imagePathRe.test(data.image) ? absolute : false;
secure = data.image.secure;
// Remove the sub-directory from the URL because createUrl() will add it back.
urlPath = urlPath.replace(new RegExp('^' + ghostConfig.paths.subdir), '');
}
// other objects are recognised but not yet supported
} else if (_.isString(context) && _.indexOf(_.keys(knownPaths), context) !== -1) {

View file

@ -67,3 +67,44 @@ describe('{{image}} helper', function () {
}).catch(done);
});
});
describe('{{image}} helper when Ghost is running on a sub-directory', function () {
var sandbox;
before(function () {
sandbox = sinon.sandbox.create();
utils.overrideConfig({url: 'http://testurl.com/blog'});
utils.loadHelpers();
});
afterEach(function () {
sandbox.restore();
});
after(function () {
utils.restoreConfig();
});
it('should output relative url of image', function (done) {
helpers.image.call({
image: '/blog/content/images/image-relative-url.png',
author: {
image: '/blog/content/images/author-image-relatve-url.png'
}
}).then(function (rendered) {
should.exist(rendered);
rendered.should.equal('/blog/content/images/image-relative-url.png');
done();
}).catch(done);
});
it('should output absolute url of image if the option is present ', function (done) {
helpers.image.call({image: '/blog/content/images/image-relative-url.png',
author: {image: '/blog/content/images/author-image-relatve-url.png'}},
{hash: {absolute: 'true'}}).then(function (rendered) {
should.exist(rendered);
rendered.should.equal('http://testurl.com/blog/content/images/image-relative-url.png');
done();
}).catch(done);
});
});