2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2015-06-13 17:34:09 +03:00
|
|
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
|
|
|
|
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)
|
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
function ghostPathsHelper(params/*, hash */) {
|
2014-10-27 05:17:07 +03:00
|
|
|
var base,
|
2015-06-13 17:34:09 +03:00
|
|
|
paths = ghostPaths(),
|
|
|
|
[path, url] = params;
|
2014-10-27 05:17:07 +03:00
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
if (!path) {
|
2014-10-27 05:17:07 +03:00
|
|
|
path = 'blog';
|
2015-06-13 17:34:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!/^(blog|admin|api)$/.test(path)) {
|
2014-10-27 05:17:07 +03:00
|
|
|
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
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
export default Ember.HTMLBars.makeBoundHelper(ghostPathsHelper);
|