mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
2b7fbb2da6
refs https://github.com/TryGhost/Toolbox/issues/222 - Admin API has the latest version alliased without a verion to prepare to the switch in Ghost v5. As we completely control Ghost Admin it makes sense to dogfood our latest changes - Starting with Ghost v5 there will be no API versioning in the URL, this is groundwork for those new realities
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
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) => {
|
|
if (part) {
|
|
route = [route, part.replace(slashAtStart, '').replace(slashAtEnd, '')].join('/');
|
|
}
|
|
});
|
|
|
|
return route += '/';
|
|
};
|
|
|
|
export default function () {
|
|
let path = window.location.pathname;
|
|
let subdir = path.substr(0, path.search('/ghost/'));
|
|
let adminRoot = `${subdir}/ghost/`;
|
|
let assetRoot = `${subdir}/ghost/assets/`;
|
|
let apiRoot = `${subdir}/ghost/api/admin`;
|
|
|
|
function assetUrl(src) {
|
|
return subdir + src;
|
|
}
|
|
|
|
return {
|
|
adminRoot,
|
|
assetRoot,
|
|
apiRoot,
|
|
subdir,
|
|
blogRoot: `${subdir}/`,
|
|
|
|
url: {
|
|
admin() {
|
|
return makeRoute(adminRoot, arguments);
|
|
},
|
|
|
|
api() {
|
|
return makeRoute(apiRoot, arguments);
|
|
},
|
|
|
|
join() {
|
|
if (arguments.length > 1) {
|
|
return makeRoute(arguments[0], Array.prototype.slice.call(arguments, 1));
|
|
} else if (arguments.length === 1) {
|
|
let [arg] = arguments;
|
|
return arg.slice(-1) === '/' ? arg : `${arg}/`;
|
|
}
|
|
return '/';
|
|
},
|
|
|
|
asset: assetUrl
|
|
}
|
|
};
|
|
}
|