1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/utils/ghost-paths.js
Hannah Wolfe 5f5b17cab7 Change URL for download count service
no issue

- we're moving the internal endpoint for fetching counts to count.ghost.org
2016-02-09 10:20:24 +00:00

55 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 apiRoot = `${subdir}/ghost/api/v0.1`;
function assetUrl(src) {
return subdir + src;
}
return {
adminRoot,
apiRoot,
subdir,
blogRoot: `${subdir}/`,
count: 'https://count.ghost.org/',
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
}
};
}