Skip to content

Commit

Permalink
Use arrow function expression (theme-next#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Aug 1, 2019
1 parent 4ad5393 commit 72e7318
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 77 deletions.
4 changes: 2 additions & 2 deletions scripts/filters/comment/changyan.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {iconText} = require('./common');
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return;

Expand All @@ -22,7 +22,7 @@ hexo.extend.filter.register('theme_inject', function(injects) {
}, priority.changyan);

// Add post_meta
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return;

Expand Down
4 changes: 2 additions & 2 deletions scripts/filters/comment/disqus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {iconText} = require('./common');
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.disqus.enable || !theme.disqus.shortname) return;

Expand All @@ -26,7 +26,7 @@ hexo.extend.filter.register('theme_inject', function(injects) {
}, priority.disqus);

// Add post_meta
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.disqus.enable || !theme.disqus.shortname || !theme.disqus.count) return;

Expand Down
2 changes: 1 addition & 1 deletion scripts/filters/comment/disqusjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.disqusjs.enable || !theme.disqusjs.shortname || !theme.disqusjs.apikey) return;

Expand Down
4 changes: 2 additions & 2 deletions scripts/filters/comment/facebook-comments-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {iconText} = require('./common');
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.facebook_sdk.enable || !theme.facebook_comments_plugin.enable) return;

Expand All @@ -24,7 +24,7 @@ hexo.extend.filter.register('theme_inject', function(injects) {
}, priority.facebook_comments_plugin);

// Add post_meta
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.facebook_sdk.enable || !theme.facebook_comments_plugin.enable) return;

Expand Down
2 changes: 1 addition & 1 deletion scripts/filters/comment/gitalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.gitalk.enable) return;

Expand Down
2 changes: 1 addition & 1 deletion scripts/filters/comment/livere.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.livere_uid) return;

Expand Down
4 changes: 2 additions & 2 deletions scripts/filters/comment/valine.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {iconText} = require('./common');
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.valine.enable || !theme.valine.appid || !theme.valine.appkey) return;

Expand All @@ -18,7 +18,7 @@ hexo.extend.filter.register('theme_inject', function(injects) {
}, priority.valine);

// Add post_meta
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.valine.enable || !theme.valine.appid || !theme.valine.appkey) return;

Expand Down
2 changes: 1 addition & 1 deletion scripts/filters/comment/vkontakte.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const priority = hexo.config.inject_priority || {};

// Add comment
hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.vkontakte_api.enable || !theme.vkontakte_api.comments) return;

Expand Down
2 changes: 1 addition & 1 deletion scripts/filters/comment/warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';

hexo.extend.filter.register('theme_inject', function(injects) {
hexo.extend.filter.register('theme_inject', injects => {
if (injects.comment.raws.length > 1) {
hexo.log.warn('It is currently not supported to launch mutli-comments systems at the same time, so stay tuned for subsequent versions of iteration.');
hexo.log.warn('Please keep one of the following.');
Expand Down
22 changes: 4 additions & 18 deletions scripts/filters/default-injects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,25 @@

'use strict';

const points = require('./../injects-point');
const points = require('../injects-point');

hexo.extend.filter.register('theme_inject', (injects) => {
hexo.extend.filter.register('theme_inject', injects => {
let filePath = hexo.theme.config.custom_file_path;

if (!filePath) {
return;
}

points.views.forEach((key) => {
points.views.forEach(key => {
if (filePath[key]) {
injects[key].file('custom', filePath[key]);
}
});

points.styles.forEach((key) => {
points.styles.forEach(key => {
if (filePath[key]) {
injects[key].push(filePath[key]);
}
// Compatible, but like head header etc, it shouldn't add 's' suffix.
let oldKey = key + 's';
if (filePath[oldKey]) {
injects[key].push(filePath[oldKey]);
hexo.log.warn(`WARNING: Format. Please use 'custom_file_path.${key}' instead 'custom_file_path.${oldKey}'.`);
}
});

// Compatible, but please use custom_file_path.
if (hexo.theme.config.footer.custom_text) {
injects.footer.raw('custom-text', `
<div class="footer-custom">{{ theme.footer.custom_text }}</div>
`, {}, {cache: true});
hexo.log.warn(`WARNING: 'footer.custom_text' will not longer be supported. Please use 'custom_file_path.footer' instead`);
}

}, 99);
17 changes: 9 additions & 8 deletions scripts/filters/exturl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

'use strict';

hexo.extend.filter.register('after_post_render', function(data) {
let cheerio;

hexo.extend.filter.register('after_post_render', data => {
var theme = hexo.theme.config;
// Exit if `exturl` option disable in NexT.
if (!theme.exturl) return;

var url = require('url');
var cheerio;

var config = this.config;
const url = require('url');

if (!cheerio) cheerio = require('cheerio');

var $ = cheerio.load(data.content, {decodeEntities: false});
const $ = cheerio.load(data.content, {decodeEntities: false});

var config = this.config;
var siteHost = url.parse(config.url).hostname || config.url;

$('a').each(function() {
$('a').each(() => {
var href = $(this).attr('href');
// Exit if the href attribute doesn't exists.
if (!href) return;
Expand All @@ -35,7 +36,7 @@ hexo.extend.filter.register('after_post_render', function(data) {

var encoded = Buffer.from(href).toString('base64');

$(this).replaceWith(function() {
$(this).replaceWith(() => {
return $(`<span class="exturl" data-url="${encoded}" title="${title}">${$(this).html()}<i class="fa fa-external-link"></i></span>`);
});

Expand Down
17 changes: 10 additions & 7 deletions scripts/filters/lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

'use strict';

hexo.extend.filter.register('after_post_render', function(data) {
let cheerio;

hexo.extend.filter.register('after_post_render', data => {
var theme = hexo.theme.config;
// Exit if `lazyload` option disable in NexT.
if (!theme.lazyload) return;

var cheerio;

if (!cheerio) cheerio = require('cheerio');

var $ = cheerio.load(data.content, {decodeEntities: false});
const $ = cheerio.load(data.content, {decodeEntities: false});

const images = $('img');
if (!images.length) return data;

$('img').each(function() {
var $image = $(this);
$image.attr('data-src', $image.attr('src')).removeAttr('src');
Array.from(images).forEach(img => {
let src = $(img).attr('src');
$(img).attr('data-src', src).removeAttr('src');
});

data.content = $.html();
Expand Down
10 changes: 4 additions & 6 deletions scripts/helpers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

'use strict';

hexo.extend.helper.register('hexo_env', function(type) {
return this.env[type];
});
hexo.extend.helper.register('hexo_env', type => hexo.env[type]);

hexo.extend.helper.register('next_env', function(type) {
var path = require('path');
var env = require(path.normalize('../../package.json'));
hexo.extend.helper.register('next_env', type => {
const path = require('path');
const env = require(path.normalize('../../package.json'));
return env[type];
});

Expand Down
9 changes: 3 additions & 6 deletions scripts/helpers/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';

hexo.extend.helper.register('next_font', function() {
hexo.extend.helper.register('next_font', () => {
var fontConfig = hexo.theme.config.font;

if (!fontConfig || !fontConfig.enable) {
Expand All @@ -15,17 +15,14 @@ hexo.extend.helper.register('next_font', function() {
var fontHost = fontConfig.host || '//fonts.googleapis.com';

//Get a font list from fontConfig
var fontFamilies = ['global', 'title', 'headings', 'posts', 'codes'].map(function(item) {
var fontFamilies = ['global', 'title', 'headings', 'posts', 'codes'].map(item => {
if (fontConfig[item] && fontConfig[item].family && fontConfig[item].external) {
return fontConfig[item].family + fontStyles;
}
return '';
});

fontFamilies = fontFamilies.filter(function(item) {
return item !== '';
});

fontFamilies = fontFamilies.filter(item => item !== '');
fontFamilies = Array.from(new Set(fontFamilies));
fontFamilies = fontFamilies.join('|');

Expand Down
6 changes: 3 additions & 3 deletions scripts/merge-configs.js → scripts/hexo-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const merge = require('lodash/merge');

hexo.on('generateBefore', function() {
hexo.on('generateBefore', () => {
if (hexo.locals.get) {
var data = hexo.locals.get('data');

Expand All @@ -29,7 +29,7 @@ hexo.on('generateBefore', function() {
var lang = this.config.language;
var i18n = this.theme.i18n;

var mergeLang = function(lang) {
var mergeLang = lang => {
i18n.set(lang, merge(i18n.get([lang]), data.languages[lang]));
};

Expand All @@ -48,7 +48,7 @@ hexo.on('generateBefore', function() {

});

hexo.on('generateAfter', function() {
hexo.on('generateAfter', () => {
if (!hexo.theme.config.reminder) return;
const https = require('https');
const path = require('path');
Expand Down
12 changes: 6 additions & 6 deletions scripts/injects.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ class ViewInject {
// Init injects
function initInject() {
let injects = {};
points.styles.forEach((item) => {
points.styles.forEach(item => {
injects[item] = new StylusInject();
});
points.views.forEach((item) => {
points.views.forEach(item => {
injects[item] = new ViewInject();
});
return injects;
}

module.exports = function(hexo) {
module.exports = hexo => {
// Exec theme_inject filter
let injects = initInject();
hexo.execFilterSync('theme_inject', injects);
hexo.theme.config.injects = {};

// Inject stylus, and get relative path base on hexo dir.
points.styles.forEach((type) => {
points.styles.forEach(type => {
hexo.theme.config.injects[type] = injects[type].files.map((item) => path.relative(hexo.base_dir, item));
});

// Inject views
points.views.forEach((type) => {
points.views.forEach(type => {
hexo.theme.config.injects[type] = [];
injects[type].raws.forEach((injectObj) => {
injects[type].raws.forEach(injectObj => {
// If there is no suffix, will add `.swig`
if (injectObj.name.indexOf('.') < 0) {
injectObj.name += '.swig';
Expand Down
2 changes: 1 addition & 1 deletion scripts/tags/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function postButton(args) {
var title = args[3] || '';

if (!url) {
hexo.log.warn('URL can NOT be empty');
hexo.log.warn('URL can NOT be empty.');
}

text = text.trim();
Expand Down
10 changes: 5 additions & 5 deletions scripts/tags/caniuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

'use strict';

const caniUse = (args) => {
function caniUse(args) {
args = args.join('').split('@');
let feature = args[0];
let periods = args[1] || 'current';
var feature = args[0];
var periods = args[1] || 'current';

if (!feature) {
hexo.log.w('Caniuse feature can NOT be empty');
hexo.log.warn('Caniuse feature can NOT be empty.');
return '';
}

return `<iframe data-feature="${feature}" src="https://caniuse.bitsofco.de/embed/index.html?feat=${feature}&periods=${periods}&accessible-colours=false" frameborder="0" width="100%" height="400px"></iframe>`;
};
}

hexo.extend.tag.register('caniuse', caniUse, {async: true});
hexo.extend.tag.register('can', caniUse, {async: true});
2 changes: 1 addition & 1 deletion scripts/tags/full-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function fullImage(args) {
var width = args[3] || '';

if (!src) {
hexo.log.warn('Image src can NOT be empty');
hexo.log.warn('Image src can NOT be empty.');
}

var image = [`<span itemprop="image" itemscope itemtype="http://schema.org/ImageObject"><img itemprop="url image" src="${src}" class="full-image"`];
Expand Down
4 changes: 2 additions & 2 deletions scripts/tags/include-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ var fs = require('hexo-fs');
function includeRaw(args) {
var path = pathFn.join(hexo.source_dir, args[0]);

return fs.exists(path).then(function(exist) {
return fs.exists(path).then(exist => {
if (!exist) {
hexo.log.error('Include file not found!');
return;
}
return fs.readFile(path).then(function(contents) {
return fs.readFile(path).then(contents => {
if (!contents) {
hexo.log.warn('Include file empty.');
return;
Expand Down
Loading

0 comments on commit 72e7318

Please sign in to comment.