diff --git a/scripts/filters/comment/changyan.js b/scripts/filters/comment/changyan.js index eaa3f1e620..a49a1780c2 100644 --- a/scripts/filters/comment/changyan.js +++ b/scripts/filters/comment/changyan.js @@ -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; @@ -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; diff --git a/scripts/filters/comment/disqus.js b/scripts/filters/comment/disqus.js index 5fd3defe85..e44cc95bdb 100644 --- a/scripts/filters/comment/disqus.js +++ b/scripts/filters/comment/disqus.js @@ -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; @@ -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; diff --git a/scripts/filters/comment/disqusjs.js b/scripts/filters/comment/disqusjs.js index 177711b148..a6ae1201e2 100644 --- a/scripts/filters/comment/disqusjs.js +++ b/scripts/filters/comment/disqusjs.js @@ -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; diff --git a/scripts/filters/comment/facebook-comments-plugin.js b/scripts/filters/comment/facebook-comments-plugin.js index d2f66d1d34..7f34b8a79c 100644 --- a/scripts/filters/comment/facebook-comments-plugin.js +++ b/scripts/filters/comment/facebook-comments-plugin.js @@ -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; @@ -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; diff --git a/scripts/filters/comment/gitalk.js b/scripts/filters/comment/gitalk.js index 8c6e9f1fe4..e39b68156e 100644 --- a/scripts/filters/comment/gitalk.js +++ b/scripts/filters/comment/gitalk.js @@ -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; diff --git a/scripts/filters/comment/livere.js b/scripts/filters/comment/livere.js index e3b78d6ac6..d876bd8c01 100644 --- a/scripts/filters/comment/livere.js +++ b/scripts/filters/comment/livere.js @@ -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; diff --git a/scripts/filters/comment/valine.js b/scripts/filters/comment/valine.js index 7f03f42297..b71dd5462b 100644 --- a/scripts/filters/comment/valine.js +++ b/scripts/filters/comment/valine.js @@ -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; @@ -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; diff --git a/scripts/filters/comment/vkontakte.js b/scripts/filters/comment/vkontakte.js index 9782dc051a..d8c19e0773 100644 --- a/scripts/filters/comment/vkontakte.js +++ b/scripts/filters/comment/vkontakte.js @@ -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; diff --git a/scripts/filters/comment/warn.js b/scripts/filters/comment/warn.js index d0bf36ad88..f040d90d9b 100644 --- a/scripts/filters/comment/warn.js +++ b/scripts/filters/comment/warn.js @@ -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.'); diff --git a/scripts/filters/default-injects.js b/scripts/filters/default-injects.js index a6e4294eed..1a6c1e88c1 100644 --- a/scripts/filters/default-injects.js +++ b/scripts/filters/default-injects.js @@ -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', ` - - `, {}, {cache: true}); - hexo.log.warn(`WARNING: 'footer.custom_text' will not longer be supported. Please use 'custom_file_path.footer' instead`); - } - }, 99); diff --git a/scripts/filters/exturl.js b/scripts/filters/exturl.js index c9eaae9796..451598792d 100644 --- a/scripts/filters/exturl.js +++ b/scripts/filters/exturl.js @@ -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; @@ -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 $(`${$(this).html()}`); }); diff --git a/scripts/filters/lazyload.js b/scripts/filters/lazyload.js index c6e434de2d..5e7ab56d03 100644 --- a/scripts/filters/lazyload.js +++ b/scripts/filters/lazyload.js @@ -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(); diff --git a/scripts/helpers/engine.js b/scripts/helpers/engine.js index c61dae868b..959501be44 100644 --- a/scripts/helpers/engine.js +++ b/scripts/helpers/engine.js @@ -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]; }); diff --git a/scripts/helpers/font.js b/scripts/helpers/font.js index 0aaaf15be9..213bd280ae 100644 --- a/scripts/helpers/font.js +++ b/scripts/helpers/font.js @@ -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) { @@ -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('|'); diff --git a/scripts/merge-configs.js b/scripts/hexo-event.js similarity index 95% rename from scripts/merge-configs.js rename to scripts/hexo-event.js index d71f9a54e0..a57ee687fe 100644 --- a/scripts/merge-configs.js +++ b/scripts/hexo-event.js @@ -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'); @@ -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])); }; @@ -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'); diff --git a/scripts/injects.js b/scripts/injects.js index 98c72baea3..3cca3672e1 100644 --- a/scripts/injects.js +++ b/scripts/injects.js @@ -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'; diff --git a/scripts/tags/button.js b/scripts/tags/button.js index ea530e24eb..1ab9a9ff00 100644 --- a/scripts/tags/button.js +++ b/scripts/tags/button.js @@ -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(); diff --git a/scripts/tags/caniuse.js b/scripts/tags/caniuse.js index bed97508ea..1f5fc303cb 100644 --- a/scripts/tags/caniuse.js +++ b/scripts/tags/caniuse.js @@ -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 ``; -}; +} hexo.extend.tag.register('caniuse', caniUse, {async: true}); hexo.extend.tag.register('can', caniUse, {async: true}); diff --git a/scripts/tags/full-image.js b/scripts/tags/full-image.js index d13414bae3..7814deaed1 100644 --- a/scripts/tags/full-image.js +++ b/scripts/tags/full-image.js @@ -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 = [` { 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; diff --git a/source/js/utils.js b/source/js/utils.js index 2a79e989ff..d55dfbbf26 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -161,7 +161,7 @@ NexT.utils = { registerCanIUseTag: function() { // GET RESPONSIVE HEIGHT PASSED FROM IFRAME - window.addEventListener('message', function(e) { + window.addEventListener('message', e => { var data = e.data; if ((typeof data === 'string') && (data.indexOf('ciu_embed') > -1)) { var featureID = data.split(':')[1];