2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-08-19 21:06:35 +04:00
|
|
|
// Handlebars Helper {{gh-path}}
|
|
|
|
// Usage: Assume 'http://www.myghostblog.org/myblog/'
|
2015-05-13 17:08:04 +03:00
|
|
|
// {{gh-path}} or {{gh-path 'blog'}} for Ghost's root (/myblog/)
|
|
|
|
// {{gh-path 'admin'}} for Ghost's admin root (/myblog/ghost/)
|
|
|
|
// {{gh-path 'api'}} for Ghost's api root (/myblog/ghost/api/v0.1/)
|
2014-08-19 21:06:35 +04:00
|
|
|
// {{gh-path 'admin' '/assets/hi.png'}} for resolved url (/myblog/ghost/assets/hi.png)
|
|
|
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
function ghostPathsHelper(path, url) {
|
2014-10-27 05:17:07 +03:00
|
|
|
var base,
|
|
|
|
argsLength = arguments.length,
|
|
|
|
paths = ghostPaths();
|
|
|
|
|
|
|
|
// function is always invoked with at least one parameter, so if
|
|
|
|
// arguments.length is 1 there were 0 arguments passed in explicitly
|
|
|
|
if (argsLength === 1) {
|
|
|
|
path = 'blog';
|
|
|
|
} else if (argsLength === 2 && !/^(blog|admin|api)$/.test(path)) {
|
|
|
|
url = path;
|
|
|
|
path = 'blog';
|
|
|
|
}
|
2014-08-19 21:06:35 +04:00
|
|
|
|
|
|
|
switch (path.toString()) {
|
|
|
|
case 'blog':
|
2014-10-27 05:17:07 +03:00
|
|
|
base = paths.blogRoot;
|
2014-08-19 21:06:35 +04:00
|
|
|
break;
|
|
|
|
case 'admin':
|
2014-10-27 05:17:07 +03:00
|
|
|
base = paths.adminRoot;
|
2014-08-19 21:06:35 +04:00
|
|
|
break;
|
|
|
|
case 'api':
|
2014-10-27 05:17:07 +03:00
|
|
|
base = paths.apiRoot;
|
2014-08-19 21:06:35 +04:00
|
|
|
break;
|
|
|
|
default:
|
2014-10-27 05:17:07 +03:00
|
|
|
base = paths.blogRoot;
|
2014-08-19 21:06:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-27 05:17:07 +03:00
|
|
|
// handle leading and trailing slashes
|
|
|
|
|
|
|
|
base = base[base.length - 1] !== '/' ? base + '/' : base;
|
|
|
|
|
2014-08-19 21:06:35 +04:00
|
|
|
if (url && url.length > 0) {
|
2014-10-27 05:17:07 +03:00
|
|
|
if (url[0] === '/') {
|
|
|
|
url = url.substr(1);
|
|
|
|
}
|
|
|
|
|
2014-08-19 21:06:35 +04:00
|
|
|
base = base + url;
|
|
|
|
}
|
|
|
|
|
2015-02-09 18:57:50 +03:00
|
|
|
return Ember.String.htmlSafe(base);
|
2014-10-25 01:09:50 +04:00
|
|
|
}
|
2014-08-19 21:06:35 +04:00
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
export default ghostPathsHelper;
|