mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
3d6856614f
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
import Ember from 'ember';
|
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
|
|
|
// Handlebars Helper {{gh-path}}
|
|
// Usage: Assume 'http://www.myghostblog.org/myblog/'
|
|
// {{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/)
|
|
// {{gh-path 'admin' '/assets/hi.png'}} for resolved url (/myblog/ghost/assets/hi.png)
|
|
|
|
const {Helper} = Ember;
|
|
|
|
export default Helper.helper(function (params) {
|
|
let paths = ghostPaths();
|
|
let [path, url] = params;
|
|
let base;
|
|
|
|
if (!path) {
|
|
path = 'blog';
|
|
}
|
|
|
|
if (!/^(blog|admin|api)$/.test(path)) {
|
|
url = path;
|
|
path = 'blog';
|
|
}
|
|
|
|
switch (path.toString()) {
|
|
case 'blog':
|
|
base = paths.blogRoot;
|
|
break;
|
|
case 'admin':
|
|
base = paths.adminRoot;
|
|
break;
|
|
case 'api':
|
|
base = paths.apiRoot;
|
|
break;
|
|
default:
|
|
base = paths.blogRoot;
|
|
break;
|
|
}
|
|
|
|
// handle leading and trailing slashes
|
|
|
|
base = base[base.length - 1] !== '/' ? `${base}/` : base;
|
|
|
|
if (url && url.length > 0) {
|
|
if (url[0] === '/') {
|
|
url = url.substr(1);
|
|
}
|
|
|
|
base = base + url;
|
|
}
|
|
|
|
return Ember.String.htmlSafe(base);
|
|
});
|