2015-10-28 14:36:45 +03:00
|
|
|
let makeRoute = function (root, args) {
|
|
|
|
let slashAtStart = /^\//;
|
|
|
|
let slashAtEnd = /\/$/;
|
|
|
|
let parts = Array.prototype.slice.call(args, 0);
|
|
|
|
let route = root.replace(slashAtEnd, '');
|
|
|
|
|
|
|
|
parts.forEach((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
|
|
|
});
|
2015-10-28 14:36:45 +03:00
|
|
|
|
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 () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let path = window.location.pathname;
|
|
|
|
let subdir = path.substr(0, path.search('/ghost/'));
|
2016-06-09 18:41:16 +03:00
|
|
|
let adminRoot = `${subdir}/ghost/`;
|
2015-10-28 14:36:45 +03:00
|
|
|
let apiRoot = `${subdir}/ghost/api/v0.1`;
|
2014-07-13 08:01:26 +04:00
|
|
|
|
|
|
|
function assetUrl(src) {
|
|
|
|
return subdir + src;
|
|
|
|
}
|
2014-05-15 05:56:43 +04:00
|
|
|
|
|
|
|
return {
|
2015-10-28 14:36:45 +03:00
|
|
|
adminRoot,
|
|
|
|
apiRoot,
|
|
|
|
subdir,
|
|
|
|
blogRoot: `${subdir}/`,
|
2016-02-09 13:20:24 +03:00
|
|
|
count: 'https://count.ghost.org/',
|
2014-07-13 08:01:26 +04:00
|
|
|
|
|
|
|
url: {
|
2015-10-28 14:36:45 +03:00
|
|
|
admin() {
|
2014-07-13 08:01:26 +04:00
|
|
|
return makeRoute(adminRoot, arguments);
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
api() {
|
2014-07-13 08:01:26 +04:00
|
|
|
return makeRoute(apiRoot, arguments);
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
join() {
|
2014-12-15 13:11:29 +03:00
|
|
|
if (arguments.length > 1) {
|
|
|
|
return makeRoute(arguments[0], Array.prototype.slice.call(arguments, 1));
|
|
|
|
} else if (arguments.length === 1) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let [arg] = arguments;
|
|
|
|
return arg.slice(-1) === '/' ? arg : `${arg}/`;
|
2014-12-15 13:11:29 +03:00
|
|
|
}
|
|
|
|
return '/';
|
|
|
|
},
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
asset: assetUrl
|
2015-10-28 14:36:45 +03:00
|
|
|
}
|
2014-05-15 05:56:43 +04:00
|
|
|
};
|
2014-06-09 15:02:51 +04:00
|
|
|
}
|