mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 09:53:32 +03:00
Merge pull request #4567 from cobbspur/imagesubdir
Fix image helper for subdirectories
This commit is contained in:
commit
5f9620cde0
@ -32,7 +32,6 @@ function setConfig(config) {
|
||||
function createUrl(urlPath, absolute, secure) {
|
||||
urlPath = urlPath || '/';
|
||||
absolute = absolute || false;
|
||||
|
||||
var output = '', baseUrl;
|
||||
|
||||
// create base of url, always ends without a slash
|
||||
@ -103,7 +102,7 @@ function urlPathForPost(post, permalinks) {
|
||||
function urlFor(context, data, absolute) {
|
||||
var urlPath = '/',
|
||||
secure, imagePathRe,
|
||||
knownObjects = ['post', 'tag', 'author', 'image'],
|
||||
knownObjects = ['post', 'tag', 'author', 'image'], baseUrl,
|
||||
|
||||
// this will become really big
|
||||
knownPaths = {
|
||||
@ -140,8 +139,15 @@ function urlFor(context, data, absolute) {
|
||||
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), '');
|
||||
if (absolute) {
|
||||
// Remove the sub-directory from the URL because ghostConfig will add it back.
|
||||
urlPath = urlPath.replace(new RegExp('^' + ghostConfig.paths.subdir), '');
|
||||
baseUrl = (secure && ghostConfig.urlSSL) ? ghostConfig.urlSSL : ghostConfig.url;
|
||||
baseUrl = baseUrl.replace(/\/$/, '');
|
||||
urlPath = baseUrl + urlPath;
|
||||
}
|
||||
|
||||
return urlPath;
|
||||
}
|
||||
// other objects are recognised but not yet supported
|
||||
} else if (_.isString(context) && _.indexOf(_.keys(knownPaths), context) !== -1) {
|
||||
|
@ -34,7 +34,7 @@ describe('{{image}} helper', function () {
|
||||
helpers.image.call({
|
||||
image: '/content/images/image-relative-url.png',
|
||||
author: {
|
||||
image: '/content/images/author-image-relatve-url.png'
|
||||
image: '/content/images/author-image-relative-url.png'
|
||||
}
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
@ -45,7 +45,7 @@ describe('{{image}} helper', function () {
|
||||
|
||||
it('should output absolute url of image if the option is present ', function (done) {
|
||||
helpers.image.call({image: '/content/images/image-relative-url.png',
|
||||
author: {image: '/content/images/author-image-relatve-url.png'}},
|
||||
author: {image: '/content/images/author-image-relative-url.png'}},
|
||||
{hash: {absolute: 'true'}}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://testurl.com/content/images/image-relative-url.png');
|
||||
@ -89,7 +89,7 @@ describe('{{image}} helper when Ghost is running on a sub-directory', function (
|
||||
helpers.image.call({
|
||||
image: '/blog/content/images/image-relative-url.png',
|
||||
author: {
|
||||
image: '/blog/content/images/author-image-relatve-url.png'
|
||||
image: '/blog/content/images/author-image-relative-url.png'
|
||||
}
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
@ -107,4 +107,17 @@ describe('{{image}} helper when Ghost is running on a sub-directory', function (
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('should not change output for an external url', function (done) {
|
||||
helpers.image.call({
|
||||
image: 'http://example.com/picture.jpg',
|
||||
author: {
|
||||
image: '/blog/content/images/author-image-relative-url.png'
|
||||
}
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://example.com/picture.jpg');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user