mirror of https://gitlab.com/curben/blog
refactor: direct call without using function()
This commit is contained in:
parent
0cc5bbb017
commit
0dee19bfdf
|
@ -6,7 +6,7 @@
|
||||||
* https://github.com/hexojs/hexo/pull/3690
|
* https://github.com/hexojs/hexo/pull/3690
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function cssHelper (...args) {
|
hexo.extend.helper.register('addCss', (...args) => {
|
||||||
let result = '\n'
|
let result = '\n'
|
||||||
let items = args
|
let items = args
|
||||||
|
|
||||||
|
@ -29,6 +29,4 @@ function cssHelper (...args) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
}
|
})
|
||||||
|
|
||||||
hexo.extend.helper.register('addCss', cssHelper)
|
|
||||||
|
|
|
@ -6,30 +6,28 @@
|
||||||
* https://github.com/hexojs/hexo/pull/3681
|
* https://github.com/hexojs/hexo/pull/3681
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function jsHelper (...args) {
|
hexo.extend.helper.register('addJs', (...args) => {
|
||||||
let result = '\n';
|
let result = '\n'
|
||||||
let items = args;
|
let items = args
|
||||||
|
|
||||||
if (!Array.isArray(args)) {
|
if (!Array.isArray(args)) {
|
||||||
items = [args];
|
items = [args]
|
||||||
}
|
}
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
// Old syntax
|
// Old syntax
|
||||||
if (typeof item === 'string' || item instanceof String) {
|
if (typeof item === 'string' || item instanceof String) {
|
||||||
result += `<script src="${item}"></script>\n`;
|
result += `<script src="${item}"></script>\n`
|
||||||
} else {
|
} else {
|
||||||
// New syntax
|
// New syntax
|
||||||
let tmpResult = '<script';
|
let tmpResult = '<script'
|
||||||
for (const attribute in item) {
|
for (const attribute in item) {
|
||||||
if (item[attribute] === true) tmpResult += ' ' + attribute;
|
if (item[attribute] === true) tmpResult += ' ' + attribute
|
||||||
else tmpResult += ` ${attribute}="${item[attribute]}"`;
|
else tmpResult += ` ${attribute}="${item[attribute]}"`
|
||||||
}
|
}
|
||||||
tmpResult += '></script>\n';
|
tmpResult += '></script>\n'
|
||||||
result += tmpResult;
|
result += tmpResult
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
return result;
|
return result
|
||||||
}
|
})
|
||||||
|
|
||||||
hexo.extend.helper.register('addJs', jsHelper)
|
|
||||||
|
|
|
@ -9,11 +9,13 @@
|
||||||
|
|
||||||
const { htmlTag } = require('hexo-util')
|
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, '')
|
if (!text) text = path.replace(/^https?:\/\/|\/$/g, '')
|
||||||
|
|
||||||
const attrs = Object.assign({
|
const attrs = Object.assign({
|
||||||
href: this.url_for(path)
|
href: urlFor(path)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (attrs.class && Array.isArray(attrs.class)) {
|
if (attrs.class && Array.isArray(attrs.class)) {
|
||||||
|
@ -21,6 +23,4 @@ function linkHelper (path, text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return htmlTag('a', attrs, text)
|
return htmlTag('a', attrs, text)
|
||||||
}
|
})
|
||||||
|
|
||||||
hexo.extend.helper.register('link', linkHelper)
|
|
||||||
|
|
Loading…
Reference in New Issue