mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Fix argument handling in gh-path helper.
No Issue - Make helper behave as stated in description when variable number of arguments are passed in. - Handle leading and trailing slashes when creating output url partial.
This commit is contained in:
parent
20fbcc1e59
commit
d810fe1ca7
1 changed files with 24 additions and 5 deletions
|
@ -7,24 +7,43 @@
|
||||||
import ghostPaths from 'ghost/utils/ghost-paths';
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
||||||
|
|
||||||
function ghostPathsHelper(path, url) {
|
function ghostPathsHelper(path, url) {
|
||||||
var base;
|
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';
|
||||||
|
}
|
||||||
|
|
||||||
switch (path.toString()) {
|
switch (path.toString()) {
|
||||||
case 'blog':
|
case 'blog':
|
||||||
base = ghostPaths().blogRoot;
|
base = paths.blogRoot;
|
||||||
break;
|
break;
|
||||||
case 'admin':
|
case 'admin':
|
||||||
base = ghostPaths().adminRoot;
|
base = paths.adminRoot;
|
||||||
break;
|
break;
|
||||||
case 'api':
|
case 'api':
|
||||||
base = ghostPaths().apiRoot;
|
base = paths.apiRoot;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
base = ghostPaths().blogRoot;
|
base = paths.blogRoot;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle leading and trailing slashes
|
||||||
|
|
||||||
|
base = base[base.length - 1] !== '/' ? base + '/' : base;
|
||||||
|
|
||||||
if (url && url.length > 0) {
|
if (url && url.length > 0) {
|
||||||
|
if (url[0] === '/') {
|
||||||
|
url = url.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
base = base + url;
|
base = base + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue