refactor: direct call without using function()

This commit is contained in:
curben 2019-08-26 13:33:23 +09:30
parent 0cc5bbb017
commit 0dee19bfdf
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
3 changed files with 20 additions and 24 deletions

View File

@ -6,7 +6,7 @@
* https://github.com/hexojs/hexo/pull/3690
*/
function cssHelper (...args) {
hexo.extend.helper.register('addCss', (...args) => {
let result = '\n'
let items = args
@ -29,6 +29,4 @@ function cssHelper (...args) {
}
})
return result
}
hexo.extend.helper.register('addCss', cssHelper)
})

View File

@ -6,30 +6,28 @@
* https://github.com/hexojs/hexo/pull/3681
*/
function jsHelper (...args) {
let result = '\n';
let items = args;
hexo.extend.helper.register('addJs', (...args) => {
let result = '\n'
let items = args
if (!Array.isArray(args)) {
items = [args];
items = [args]
}
items.forEach(item => {
// Old syntax
if (typeof item === 'string' || item instanceof String) {
result += `<script src="${item}"></script>\n`;
result += `<script src="${item}"></script>\n`
} else {
// New syntax
let tmpResult = '<script';
let tmpResult = '<script'
for (const attribute in item) {
if (item[attribute] === true) tmpResult += ' ' + attribute;
else tmpResult += ` ${attribute}="${item[attribute]}"`;
if (item[attribute] === true) tmpResult += ' ' + attribute
else tmpResult += ` ${attribute}="${item[attribute]}"`
}
tmpResult += '></script>\n';
result += tmpResult;
tmpResult += '></script>\n'
result += tmpResult
}
});
return result;
}
hexo.extend.helper.register('addJs', jsHelper)
})
return result
})

View File

@ -9,11 +9,13 @@
const { htmlTag } = require('hexo-util')
function linkHelper (path, text) {
hexo.extend.helper.register('link', (path, text) => {
const urlFor = hexo.extend.helper.get('url_for').bind(hexo)
if (!text) text = path.replace(/^https?:\/\/|\/$/g, '')
const attrs = Object.assign({
href: this.url_for(path)
href: urlFor(path)
})
if (attrs.class && Array.isArray(attrs.class)) {
@ -21,6 +23,4 @@ function linkHelper (path, text) {
}
return htmlTag('a', attrs, text)
}
hexo.extend.helper.register('link', linkHelper)
})