mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
chore(cloudfunc) getPathLink: es2015-ify
This commit is contained in:
parent
e2950fbdef
commit
6cddde08eb
1 changed files with 21 additions and 26 deletions
|
|
@ -41,44 +41,39 @@ module.exports.getTitle = (path) => {
|
|||
* @param url - адрес каталога
|
||||
*/
|
||||
function getPathLink(url, prefix, template) {
|
||||
var namesRaw, names, length,
|
||||
pathHTML = '',
|
||||
path = '/';
|
||||
|
||||
if (!url)
|
||||
throw Error('url could not be empty!');
|
||||
|
||||
if (!template)
|
||||
throw Error('template could not be empty!');
|
||||
|
||||
namesRaw = url.split('/')
|
||||
.slice(1, -1),
|
||||
const names = url
|
||||
.split('/')
|
||||
.slice(1, -1);
|
||||
|
||||
names = [].concat('/', namesRaw),
|
||||
const allNames = ['/', ...names];
|
||||
const length = allNames.length - 1;
|
||||
|
||||
length = names.length - 1;
|
||||
let path = '/';
|
||||
|
||||
names.forEach((name, index) => {
|
||||
var slash = '',
|
||||
isLast = index === length;
|
||||
const pathHTML = allNames.map((name, index) => {
|
||||
const isLast = index === length;
|
||||
|
||||
if (index)
|
||||
path += name + '/';
|
||||
path += name + '/';
|
||||
|
||||
if (index && isLast) {
|
||||
pathHTML += name + '/';
|
||||
} else {
|
||||
if (index)
|
||||
slash = '/';
|
||||
|
||||
pathHTML += rendy(template, {
|
||||
path: path,
|
||||
name: name,
|
||||
slash: slash,
|
||||
prefix: prefix
|
||||
});
|
||||
}
|
||||
});
|
||||
if (index && isLast)
|
||||
return name + '/';
|
||||
|
||||
const slash = index ? '/' : '';
|
||||
|
||||
return rendy(template, {
|
||||
path,
|
||||
name,
|
||||
slash,
|
||||
prefix,
|
||||
});
|
||||
}).join('');
|
||||
|
||||
return pathHTML;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue