2014-05-15 05:56:43 +04:00
|
|
|
var makeRoute = function (root, args) {
|
2014-12-15 13:11:29 +03:00
|
|
|
var slashAtStart,
|
|
|
|
slashAtEnd,
|
|
|
|
parts,
|
|
|
|
route;
|
|
|
|
|
|
|
|
slashAtStart = /^\//;
|
|
|
|
slashAtEnd = /\/$/;
|
|
|
|
route = root.replace(slashAtEnd, '');
|
|
|
|
parts = Array.prototype.slice.call(args, 0);
|
|
|
|
|
|
|
|
parts.forEach(function (part) {
|
2015-05-13 17:08:04 +03:00
|
|
|
if (part) {
|
|
|
|
route = [route, part.replace(slashAtStart, '').replace(slashAtEnd, '')].join('/');
|
|
|
|
}
|
2014-12-15 13:11:29 +03:00
|
|
|
});
|
|
|
|
return route += '/';
|
2014-05-15 05:56:43 +04:00
|
|
|
};
|
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default function () {
|
2014-05-15 05:56:43 +04:00
|
|
|
var path = window.location.pathname,
|
2014-07-13 08:01:26 +04:00
|
|
|
subdir = path.substr(0, path.search('/ghost/')),
|
|
|
|
adminRoot = subdir + '/ghost',
|
|
|
|
apiRoot = subdir + '/ghost/api/v0.1';
|
|
|
|
|
|
|
|
function assetUrl(src) {
|
|
|
|
return subdir + src;
|
|
|
|
}
|
2014-05-15 05:56:43 +04:00
|
|
|
|
|
|
|
return {
|
|
|
|
subdir: subdir,
|
2014-06-24 03:24:13 +04:00
|
|
|
blogRoot: subdir + '/',
|
2014-07-13 08:01:26 +04:00
|
|
|
adminRoot: adminRoot,
|
|
|
|
apiRoot: apiRoot,
|
|
|
|
|
|
|
|
url: {
|
|
|
|
admin: function () {
|
|
|
|
return makeRoute(adminRoot, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
api: function () {
|
|
|
|
return makeRoute(apiRoot, arguments);
|
|
|
|
},
|
|
|
|
|
2014-12-15 13:11:29 +03:00
|
|
|
join: function () {
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
return makeRoute(arguments[0], Array.prototype.slice.call(arguments, 1));
|
|
|
|
} else if (arguments.length === 1) {
|
|
|
|
var arg = arguments[0];
|
|
|
|
return arg.slice(-1) === '/' ? arg : arg + '/';
|
|
|
|
}
|
|
|
|
return '/';
|
|
|
|
},
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
asset: assetUrl
|
2015-03-29 21:10:53 +03:00
|
|
|
},
|
|
|
|
count: 'https://ghost.org/count/'
|
2014-05-15 05:56:43 +04:00
|
|
|
};
|
2014-06-09 15:02:51 +04:00
|
|
|
}
|