mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Navigation menu support for subdomains of blog url
Closes #5033 - Added unit tests for the nav context of urlFor - Fixed issue in the nav context of urlFor where subdomains of blog url were truncated - Fixed issue in the nav context of urlFor where there was sometimes an extra preceding /
This commit is contained in:
parent
61b86bf821
commit
e74a329b8a
@ -156,10 +156,14 @@ function urlFor(context, data, absolute) {
|
||||
urlPath = data.nav.url;
|
||||
baseUrl = (secure && ghostConfig.urlSSL) ? ghostConfig.urlSSL : ghostConfig.url;
|
||||
hostname = baseUrl.split('//')[1] + ghostConfig.paths.subdir;
|
||||
if (urlPath.indexOf(hostname) > -1) {
|
||||
if (urlPath.indexOf(hostname) > -1 && urlPath.indexOf('.' + hostname) === -1) {
|
||||
// make link relative to account for possible
|
||||
// mismatch in http/https etc, force absolute
|
||||
urlPath = '/' + urlPath.split(hostname)[1];
|
||||
// do not do so if link is a subdomain of blog url
|
||||
urlPath = urlPath.split(hostname)[1];
|
||||
if (urlPath.substring(0, 1) !== '/') {
|
||||
urlPath = '/' + urlPath;
|
||||
}
|
||||
absolute = true;
|
||||
}
|
||||
}
|
||||
|
@ -225,6 +225,26 @@ describe('Config', function () {
|
||||
config.urlFor(testContext, testData).should.equal('/blog/tag/kitchen-sink/');
|
||||
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/tag/kitchen-sink/');
|
||||
});
|
||||
|
||||
it('should return a url for a nav item when asked for it', function () {
|
||||
var testContext = 'nav',
|
||||
testData;
|
||||
|
||||
config.set({url: 'http://my-ghost-blog.com', urlSSL: 'https://my-ghost-blog.com'});
|
||||
|
||||
testData = {nav: {url: 'http://my-ghost-blog.com/short-and-sweet/'}};
|
||||
config.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com/short-and-sweet/');
|
||||
|
||||
testData = {nav: {url: 'http://my-ghost-blog.com/short-and-sweet/'}, secure: true};
|
||||
config.urlFor(testContext, testData).should.equal('https://my-ghost-blog.com/short-and-sweet/');
|
||||
|
||||
testData = {nav: {url: 'http://sub.my-ghost-blog.com/'}};
|
||||
config.urlFor(testContext, testData).should.equal('http://sub.my-ghost-blog.com/');
|
||||
|
||||
config.set({url: 'http://my-ghost-blog.com/blog'});
|
||||
testData = {nav: {url: 'http://my-ghost-blog.com/blog/short-and-sweet/'}};
|
||||
config.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com/blog/short-and-sweet/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('urlPathForPost', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user