Ghost/ghost/admin/app/utils/ghost-paths.js
Kevin Ansfield 12cda07e94 deps: ember@2.6.0
no issue
- bugfix & cleanup release https://github.com/emberjs/ember.js/releases/tag/v2.6.0
- fix tests that were relying on not having the `rootURL` prefixed in `href`s
2016-06-09 16:58:09 +01:00

56 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
}
};
}