New eslint rule prefer-const

This commit is contained in:
Mimi 2020-07-15 11:55:42 +08:00
parent c485d9d1f3
commit 9ea66544c6
23 changed files with 67 additions and 67 deletions

View File

@ -8,7 +8,7 @@ try {
}
module.exports = hexo => {
let data = hexo.locals.get('data');
const data = hexo.locals.get('data');
/**
* Merge configs from _data/next.yml into hexo.theme.config.
@ -36,15 +36,15 @@ module.exports = hexo => {
// Custom languages support. Introduced in NexT v6.3.0.
if (data.languages) {
let { language } = hexo.config;
let { i18n } = hexo.theme;
const { language } = hexo.config;
const { i18n } = hexo.theme;
const mergeLang = lang => {
if (data.languages[lang]) i18n.set(lang, merge(i18n.get([lang]), data.languages[lang]));
};
if (Array.isArray(language)) {
for (let lang of language) {
for (const lang of language) {
mergeLang(lang);
}
} else {

View File

@ -6,8 +6,8 @@ function resolve(package) {
}
function highlightTheme(name) {
let file = `${resolve('highlight.js')}/styles/${name}.css`;
let css = fs.readFileSync(file).toString();
const file = `${resolve('highlight.js')}/styles/${name}.css`;
const css = fs.readFileSync(file).toString();
let rule = '';
let background = '';
let foreground = '';
@ -34,8 +34,8 @@ function prismTheme(name) {
}
module.exports = hexo => {
let { config } = hexo;
let theme = hexo.theme.config;
const { config } = hexo;
const theme = hexo.theme.config;
config.highlight.hljs = false;
config.prismjs = config.prismjs || {};
theme.highlight = {

View File

@ -42,7 +42,7 @@ class ViewInject {
// Init injects
function initInject(base_dir) {
let injects = {};
const injects = {};
points.styles.forEach(item => {
injects[item] = new StylusInject(base_dir);
});
@ -54,7 +54,7 @@ function initInject(base_dir) {
module.exports = hexo => {
// Exec theme_inject filter
let injects = initInject(hexo.base_dir);
const injects = initInject(hexo.base_dir);
hexo.execFilterSync('theme_inject', injects);
hexo.theme.config.injects = {};
@ -65,11 +65,11 @@ module.exports = hexo => {
// Inject views
points.views.forEach(type => {
let configs = Object.create(null);
const configs = Object.create(null);
hexo.theme.config.injects[type] = [];
// Add or override view.
injects[type].raws.forEach((injectObj, index) => {
let name = `inject/${type}/${injectObj.name}`;
const name = `inject/${type}/${injectObj.name}`;
hexo.theme.setView(name, injectObj.raw);
configs[name] = {
layout : name,

View File

@ -7,7 +7,7 @@ const { iconText } = require('./common');
// Add comment
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return;
injects.comment.raw('changyan', `
@ -22,7 +22,7 @@ hexo.extend.filter.register('theme_inject', injects => {
// Add post_meta
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return;
injects.postMeta.raw('changyan', `

View File

@ -7,22 +7,22 @@ const path = require('path');
hexo.extend.filter.register('theme_inject', injects => {
injects.comment.raws.forEach(element => {
// Set default button content
let injectName = path.basename(element.name, path.extname(element.name));
const injectName = path.basename(element.name, path.extname(element.name));
element.args[0] = Object.assign({
configKey: injectName,
class : injectName,
button : injectName
}, element.args[0]);
// Get locals and config
let locals = element.args[0];
let config = hexo.theme.config.comments;
const locals = element.args[0];
const config = hexo.theme.config.comments;
// Set activeClass
if (config.active === locals.configKey) {
config.activeClass = locals.class;
}
// Set custom button content
if (config.nav) {
let nav = config.nav[locals.configKey] || {};
const nav = config.nav[locals.configKey] || {};
if (nav.order) {
element.args[2] = nav.order;
}

View File

@ -7,7 +7,7 @@ const { iconText } = require('./common');
// Add comment
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.disqus.enable || !theme.disqus.shortname) return;
injects.comment.raw('disqus', `
@ -24,7 +24,7 @@ hexo.extend.filter.register('theme_inject', injects => {
// Add post_meta
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.disqus.enable || !theme.disqus.shortname || !theme.disqus.count) return;
injects.postMeta.raw('disqus', `

View File

@ -6,7 +6,7 @@ const path = require('path');
// Add comment
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.disqusjs.enable || !theme.disqusjs.shortname || !theme.disqusjs.apikey) return;
injects.comment.raw('disqusjs', `

View File

@ -6,7 +6,7 @@ const path = require('path');
// Add comment
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.gitalk.enable) return;
injects.comment.raw('gitalk', '<div class="comments" id="gitalk-container"></div>', {}, {cache: true});

View File

@ -6,7 +6,7 @@ const path = require('path');
// Add comment
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.livere_uid) return;
injects.comment.raw('livere', `

View File

@ -7,7 +7,7 @@ const { iconText } = require('./common');
// Add comment
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.valine.enable || !theme.valine.appId || !theme.valine.appKey) return;
injects.comment.raw('valine', '<div class="comments" id="valine-comments"></div>', {}, {cache: true});
@ -18,7 +18,7 @@ hexo.extend.filter.register('theme_inject', injects => {
// Add post_meta
hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
if (!theme.valine.enable || !theme.valine.appId || !theme.valine.appKey) return;
injects.postMeta.raw('valine', `

View File

@ -5,7 +5,7 @@
const points = require('../events/lib/injects-point');
hexo.extend.filter.register('theme_inject', injects => {
let filePath = hexo.theme.config.custom_file_path;
const filePath = hexo.theme.config.custom_file_path;
if (!filePath) return;

View File

@ -17,7 +17,7 @@ hexo.extend.filter.register('after_post_render', data => {
if (!href) return match;
// Exit if the url has same host with `config.url`, which means it's an internal link.
let link = url.parse(href);
const link = url.parse(href);
if (!link.protocol || link.hostname === siteHost) return match;
return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}<i class="fa fa-external-link-alt"></i></span>`;

View File

@ -53,7 +53,7 @@ hexo.extend.helper.register('post_nav', function(post) {
});
hexo.extend.helper.register('gitalk_md5', function(path) {
let str = this.url_for(path);
const str = this.url_for(path);
str.replace('index.html', '');
return crypto.createHash('md5').update(str).digest('hex');
});

View File

@ -8,9 +8,9 @@ const url = require('url');
* Export theme config to js
*/
hexo.extend.helper.register('next_config', function() {
let { config, theme, next_version } = this;
const { config, theme, next_version } = this;
config.algolia = config.algolia || {};
let exportConfig = {
const exportConfig = {
hostname : url.parse(config.url).hostname || config.url,
root : config.root,
scheme : theme.scheme,

View File

@ -26,7 +26,7 @@ hexo.extend.helper.register('next_url', function(path, text, options = {}) {
};
}
for (let key in options) {
for (const key in options) {
/**
* If option have `class` attribute, add it to

View File

@ -3,8 +3,8 @@
'use strict';
hexo.extend.helper.register('js_vendors', function() {
let { config, theme } = this;
let vendors = {
const { config, theme } = this;
const vendors = {
anime: 'lib/anime.min.js'
};
if (config.prismjs.enable && !config.prismjs.preprocess) {

View File

@ -43,7 +43,7 @@ hexo.extend.helper.register('next_tagcloud', function(options) {
tags.forEach(tag => {
const ratio = length ? sizes.indexOf(tag.length) / length : 0;
const size = min + ((max - min) * ratio);
let style = `font-size: ${parseFloat(size.toFixed(2))}${unit};`;
const style = `font-size: ${parseFloat(size.toFixed(2))}${unit};`;
result.push(
`<a href="${this.url_for(tag.path)}" style="${style}" class="tag-cloud-${Math.round(ratio * 10)}">${transform ? transform(tag.name) : tag.name}</a>`

View File

@ -8,7 +8,7 @@
function postButton(args) {
args = args.join(' ').split(',');
let url = args[0];
const url = args[0];
let text = args[1] || '';
let icon = args[2] || '';
let title = args[3] || '';

View File

@ -73,7 +73,7 @@ const LAYOUTS = {
function groupBy(group, data) {
const r = [];
for (let count of group) {
for (const count of group) {
r.push(data.slice(0, count));
data = data.slice(count);
}

View File

@ -7,7 +7,7 @@
'use strict';
function pdf(args) {
let theme = hexo.theme.config;
const theme = hexo.theme.config;
return `<div class="pdfobject-container" data-target="${args[0]}" data-height="${args[1] || theme.pdf.height}"></div>`;
}

View File

@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', () => {
const algoliaSettings = CONFIG.algolia;
const { indexName, appID, apiKey } = algoliaSettings;
let search = instantsearch({
const search = instantsearch({
indexName,
searchClient : algoliasearch(appID, apiKey),
searchFunction: helper => {
@ -40,7 +40,7 @@ document.addEventListener('DOMContentLoaded', () => {
container: '#algolia-stats',
templates: {
text: data => {
let stats = algoliaSettings.labels.hits_stats
const stats = algoliaSettings.labels.hits_stats
.replace(/\$\{hits}/, data.nbHits)
.replace(/\$\{time}/, data.processingTimeMS);
return `${stats}
@ -56,7 +56,7 @@ document.addEventListener('DOMContentLoaded', () => {
container: '#algolia-hits',
templates: {
item: data => {
let link = data.permalink ? data.permalink : CONFIG.root + data.path;
const link = data.permalink ? data.permalink : CONFIG.root + data.path;
return `<a href="${link}" class="algolia-hit-item-link">${data._highlightResult.title.value}</a>`;
},
empty: data => {

View File

@ -17,15 +17,15 @@ document.addEventListener('DOMContentLoaded', () => {
const getIndexByWord = (word, text, caseSensitive) => {
if (CONFIG.localsearch.unescape) {
let div = document.createElement('div');
const div = document.createElement('div');
div.innerText = word;
word = div.innerHTML;
}
let wordLen = word.length;
const wordLen = word.length;
if (wordLen === 0) return [];
let startPosition = 0;
let position = [];
let index = [];
const index = [];
if (!caseSensitive) {
text = text.toLowerCase();
word = word.toLowerCase();
@ -41,7 +41,7 @@ document.addEventListener('DOMContentLoaded', () => {
const mergeIntoSlice = (start, end, index, searchText) => {
let item = index[index.length - 1];
let { position, word } = item;
let hits = [];
const hits = [];
let searchTextCountInSlice = 0;
while (position + word.length <= end && index.length !== 0) {
if (word === searchText) {
@ -51,7 +51,7 @@ document.addEventListener('DOMContentLoaded', () => {
position,
length: word.length
});
let wordEnd = position + word.length;
const wordEnd = position + word.length;
// Move to next position of hit
index.pop();
@ -80,7 +80,7 @@ document.addEventListener('DOMContentLoaded', () => {
let prevEnd = slice.start;
slice.hits.forEach(hit => {
result += text.substring(prevEnd, hit.position);
let end = hit.position + hit.length;
const end = hit.position + hit.length;
result += `<b class="search-keyword">${text.substring(hit.position, end)}</b>`;
prevEnd = end;
});
@ -90,17 +90,17 @@ document.addEventListener('DOMContentLoaded', () => {
const inputEventFunction = () => {
if (!isfetched) return;
let searchText = input.value.trim().toLowerCase();
let keywords = searchText.split(/[-\s]+/);
const searchText = input.value.trim().toLowerCase();
const keywords = searchText.split(/[-\s]+/);
if (keywords.length > 1) {
keywords.push(searchText);
}
let resultItems = [];
const resultItems = [];
if (searchText.length > 0) {
// Perform local searching
datas.forEach(({ title, content, url }) => {
let titleInLowerCase = title.toLowerCase();
let contentInLowerCase = content.toLowerCase();
const titleInLowerCase = title.toLowerCase();
const contentInLowerCase = content.toLowerCase();
let indexOfTitle = [];
let indexOfContent = [];
let searchTextCount = 0;
@ -111,7 +111,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Show search results
if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
let hitCount = indexOfTitle.length + indexOfContent.length;
const hitCount = indexOfTitle.length + indexOfContent.length;
// Sort index by position of keyword
[indexOfTitle, indexOfContent].forEach(index => {
index.sort((itemLeft, itemRight) => {
@ -122,17 +122,17 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
let slicesOfTitle = [];
const slicesOfTitle = [];
if (indexOfTitle.length !== 0) {
let tmp = mergeIntoSlice(0, title.length, indexOfTitle, searchText);
const tmp = mergeIntoSlice(0, title.length, indexOfTitle, searchText);
searchTextCount += tmp.searchTextCountInSlice;
slicesOfTitle.push(tmp);
}
let slicesOfContent = [];
while (indexOfContent.length !== 0) {
let item = indexOfContent[indexOfContent.length - 1];
let { position, word } = item;
const item = indexOfContent[indexOfContent.length - 1];
const { position, word } = item;
// Cut out 100 characters
let start = position - 20;
let end = position + 80;
@ -145,7 +145,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (end > content.length) {
end = content.length;
}
let tmp = mergeIntoSlice(start, end, indexOfContent, searchText);
const tmp = mergeIntoSlice(start, end, indexOfContent, searchText);
searchTextCount += tmp.searchTextCountInSlice;
slicesOfContent.push(tmp);
}
@ -161,7 +161,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
// Select top N slices in content
let upperBound = parseInt(CONFIG.localsearch.top_n_per_article, 10);
const upperBound = parseInt(CONFIG.localsearch.top_n_per_article, 10);
if (upperBound >= 0) {
slicesOfContent = slicesOfContent.slice(0, upperBound);
}

View File

@ -45,7 +45,7 @@ NexT.utils = {
registerExtURL: function() {
document.querySelectorAll('span.exturl').forEach(element => {
let link = document.createElement('a');
const link = document.createElement('a');
// https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings
link.href = decodeURIComponent(atob(element.dataset.url).split('').map(c => {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
@ -122,8 +122,8 @@ NexT.utils = {
const box = document.createElement('div');
box.className = 'video-container';
element.wrap(box);
let width = Number(element.width);
let height = Number(element.height);
const width = Number(element.width);
const height = Number(element.height);
if (width && height) {
box.style.paddingTop = (height / width * 100) + '%';
}
@ -278,10 +278,10 @@ NexT.utils = {
},
supportsPDFs: function() {
let ua = navigator.userAgent;
let isFirefoxWithPDFJS = ua.includes('irefox') && parseInt(ua.split('rv:')[1].split('.')[0], 10) > 18;
let supportsPdfMimeType = typeof navigator.mimeTypes['application/pdf'] !== 'undefined';
let isIOS = /iphone|ipad|ipod/i.test(ua.toLowerCase());
const ua = navigator.userAgent;
const isFirefoxWithPDFJS = ua.includes('irefox') && parseInt(ua.split('rv:')[1].split('.')[0], 10) > 18;
const supportsPdfMimeType = typeof navigator.mimeTypes['application/pdf'] !== 'undefined';
const isIOS = /iphone|ipad|ipod/i.test(ua.toLowerCase());
return isFirefoxWithPDFJS || (supportsPdfMimeType && !isIOS);
},
@ -350,8 +350,8 @@ NexT.utils = {
callback();
return;
}
let intersectionObserver = new IntersectionObserver((entries, observer) => {
let entry = entries[0];
const intersectionObserver = new IntersectionObserver((entries, observer) => {
const entry = entries[0];
if (entry.isIntersecting) {
callback();
observer.disconnect();