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