mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 01:42:29 +03:00
cb59388c5b
no issue - adds `eslint-plugin-sort-imports-es6-autofix` dependency - implements ESLint's base `sort-imports` rule but has a distinction in that `import {foo} from 'bar';` is considered `multiple` rather than `single` - fixes ESLint's autofix behaviour so `eslint --fix` will actually fix the sort order - updates all unordered import rules by using `eslint --fix` With the increased number of `import` statements since Ember+ecosystem started moving towards es6 modules I've found it frustrating at times trying to search through randomly ordered import statements. Recently I've been sorting imports manually when I've added new code or touched old code so I thought I'd add an ESLint rule to codify it.
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
|
import {helper} from 'ember-helper';
|
|
import {htmlSafe} from 'ember-string';
|
|
|
|
// 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/)
|
|
//
|
|
// DO NOT USE - admin asset paths are now relative because we are using hash urls
|
|
// and the gh-path helper can get in the way of asset rewriting
|
|
// {{gh-path 'asset' '/img/hi.png'}} for resolved url (/myblog/ghost/assets/img/hi.png)
|
|
|
|
export default helper(function (params) {
|
|
let paths = ghostPaths();
|
|
let [path, url] = params;
|
|
let base;
|
|
|
|
if (!path) {
|
|
path = 'blog';
|
|
}
|
|
|
|
if (!/^(blog|admin|asset|api)$/.test(path)) {
|
|
url = path;
|
|
path = 'blog';
|
|
}
|
|
|
|
switch (path.toString()) {
|
|
case 'blog':
|
|
base = paths.blogRoot;
|
|
break;
|
|
case 'admin':
|
|
base = paths.adminRoot;
|
|
break;
|
|
case 'asset':
|
|
base = paths.assetRoot;
|
|
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 htmlSafe(base);
|
|
});
|