mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-20 19:02:33 +00:00
New eslint rule prefer-const
This commit is contained in:
parent
c485d9d1f3
commit
9ea66544c6
@ -8,7 +8,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = hexo => {
|
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.
|
* 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.
|
// Custom languages support. Introduced in NexT v6.3.0.
|
||||||
if (data.languages) {
|
if (data.languages) {
|
||||||
let { language } = hexo.config;
|
const { language } = hexo.config;
|
||||||
let { i18n } = hexo.theme;
|
const { i18n } = hexo.theme;
|
||||||
|
|
||||||
const mergeLang = lang => {
|
const mergeLang = lang => {
|
||||||
if (data.languages[lang]) i18n.set(lang, merge(i18n.get([lang]), data.languages[lang]));
|
if (data.languages[lang]) i18n.set(lang, merge(i18n.get([lang]), data.languages[lang]));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Array.isArray(language)) {
|
if (Array.isArray(language)) {
|
||||||
for (let lang of language) {
|
for (const lang of language) {
|
||||||
mergeLang(lang);
|
mergeLang(lang);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ function resolve(package) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function highlightTheme(name) {
|
function highlightTheme(name) {
|
||||||
let file = `${resolve('highlight.js')}/styles/${name}.css`;
|
const file = `${resolve('highlight.js')}/styles/${name}.css`;
|
||||||
let css = fs.readFileSync(file).toString();
|
const css = fs.readFileSync(file).toString();
|
||||||
let rule = '';
|
let rule = '';
|
||||||
let background = '';
|
let background = '';
|
||||||
let foreground = '';
|
let foreground = '';
|
||||||
@ -34,8 +34,8 @@ function prismTheme(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = hexo => {
|
module.exports = hexo => {
|
||||||
let { config } = hexo;
|
const { config } = hexo;
|
||||||
let theme = hexo.theme.config;
|
const theme = hexo.theme.config;
|
||||||
config.highlight.hljs = false;
|
config.highlight.hljs = false;
|
||||||
config.prismjs = config.prismjs || {};
|
config.prismjs = config.prismjs || {};
|
||||||
theme.highlight = {
|
theme.highlight = {
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class ViewInject {
|
|||||||
|
|
||||||
// Init injects
|
// Init injects
|
||||||
function initInject(base_dir) {
|
function initInject(base_dir) {
|
||||||
let injects = {};
|
const injects = {};
|
||||||
points.styles.forEach(item => {
|
points.styles.forEach(item => {
|
||||||
injects[item] = new StylusInject(base_dir);
|
injects[item] = new StylusInject(base_dir);
|
||||||
});
|
});
|
||||||
@ -54,7 +54,7 @@ function initInject(base_dir) {
|
|||||||
|
|
||||||
module.exports = hexo => {
|
module.exports = hexo => {
|
||||||
// Exec theme_inject filter
|
// Exec theme_inject filter
|
||||||
let injects = initInject(hexo.base_dir);
|
const injects = initInject(hexo.base_dir);
|
||||||
hexo.execFilterSync('theme_inject', injects);
|
hexo.execFilterSync('theme_inject', injects);
|
||||||
hexo.theme.config.injects = {};
|
hexo.theme.config.injects = {};
|
||||||
|
|
||||||
@ -65,11 +65,11 @@ module.exports = hexo => {
|
|||||||
|
|
||||||
// Inject views
|
// Inject views
|
||||||
points.views.forEach(type => {
|
points.views.forEach(type => {
|
||||||
let configs = Object.create(null);
|
const configs = Object.create(null);
|
||||||
hexo.theme.config.injects[type] = [];
|
hexo.theme.config.injects[type] = [];
|
||||||
// Add or override view.
|
// Add or override view.
|
||||||
injects[type].raws.forEach((injectObj, index) => {
|
injects[type].raws.forEach((injectObj, index) => {
|
||||||
let name = `inject/${type}/${injectObj.name}`;
|
const name = `inject/${type}/${injectObj.name}`;
|
||||||
hexo.theme.setView(name, injectObj.raw);
|
hexo.theme.setView(name, injectObj.raw);
|
||||||
configs[name] = {
|
configs[name] = {
|
||||||
layout : name,
|
layout : name,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const { iconText } = require('./common');
|
|||||||
|
|
||||||
// Add comment
|
// Add comment
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return;
|
||||||
|
|
||||||
injects.comment.raw('changyan', `
|
injects.comment.raw('changyan', `
|
||||||
@ -22,7 +22,7 @@ hexo.extend.filter.register('theme_inject', injects => {
|
|||||||
|
|
||||||
// Add post_meta
|
// Add post_meta
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return;
|
||||||
|
|
||||||
injects.postMeta.raw('changyan', `
|
injects.postMeta.raw('changyan', `
|
||||||
|
|||||||
@ -7,22 +7,22 @@ const path = require('path');
|
|||||||
hexo.extend.filter.register('theme_inject', injects => {
|
hexo.extend.filter.register('theme_inject', injects => {
|
||||||
injects.comment.raws.forEach(element => {
|
injects.comment.raws.forEach(element => {
|
||||||
// Set default button content
|
// 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({
|
element.args[0] = Object.assign({
|
||||||
configKey: injectName,
|
configKey: injectName,
|
||||||
class : injectName,
|
class : injectName,
|
||||||
button : injectName
|
button : injectName
|
||||||
}, element.args[0]);
|
}, element.args[0]);
|
||||||
// Get locals and config
|
// Get locals and config
|
||||||
let locals = element.args[0];
|
const locals = element.args[0];
|
||||||
let config = hexo.theme.config.comments;
|
const config = hexo.theme.config.comments;
|
||||||
// Set activeClass
|
// Set activeClass
|
||||||
if (config.active === locals.configKey) {
|
if (config.active === locals.configKey) {
|
||||||
config.activeClass = locals.class;
|
config.activeClass = locals.class;
|
||||||
}
|
}
|
||||||
// Set custom button content
|
// Set custom button content
|
||||||
if (config.nav) {
|
if (config.nav) {
|
||||||
let nav = config.nav[locals.configKey] || {};
|
const nav = config.nav[locals.configKey] || {};
|
||||||
if (nav.order) {
|
if (nav.order) {
|
||||||
element.args[2] = nav.order;
|
element.args[2] = nav.order;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const { iconText } = require('./common');
|
|||||||
|
|
||||||
// Add comment
|
// Add comment
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!theme.disqus.enable || !theme.disqus.shortname) return;
|
||||||
|
|
||||||
injects.comment.raw('disqus', `
|
injects.comment.raw('disqus', `
|
||||||
@ -24,7 +24,7 @@ hexo.extend.filter.register('theme_inject', injects => {
|
|||||||
|
|
||||||
// Add post_meta
|
// Add post_meta
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!theme.disqus.enable || !theme.disqus.shortname || !theme.disqus.count) return;
|
||||||
|
|
||||||
injects.postMeta.raw('disqus', `
|
injects.postMeta.raw('disqus', `
|
||||||
|
|||||||
@ -6,7 +6,7 @@ const path = require('path');
|
|||||||
|
|
||||||
// Add comment
|
// Add comment
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!theme.disqusjs.enable || !theme.disqusjs.shortname || !theme.disqusjs.apikey) return;
|
||||||
|
|
||||||
injects.comment.raw('disqusjs', `
|
injects.comment.raw('disqusjs', `
|
||||||
|
|||||||
@ -6,7 +6,7 @@ const path = require('path');
|
|||||||
|
|
||||||
// Add comment
|
// Add comment
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
hexo.extend.filter.register('theme_inject', injects => {
|
||||||
let theme = hexo.theme.config;
|
const theme = hexo.theme.config;
|
||||||
if (!theme.gitalk.enable) return;
|
if (!theme.gitalk.enable) return;
|
||||||
|
|
||||||
injects.comment.raw('gitalk', '<div class="comments" id="gitalk-container"></div>', {}, {cache: true});
|
injects.comment.raw('gitalk', '<div class="comments" id="gitalk-container"></div>', {}, {cache: true});
|
||||||
|
|||||||
@ -6,7 +6,7 @@ const path = require('path');
|
|||||||
|
|
||||||
// Add comment
|
// Add comment
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
hexo.extend.filter.register('theme_inject', injects => {
|
||||||
let theme = hexo.theme.config;
|
const theme = hexo.theme.config;
|
||||||
if (!theme.livere_uid) return;
|
if (!theme.livere_uid) return;
|
||||||
|
|
||||||
injects.comment.raw('livere', `
|
injects.comment.raw('livere', `
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const { iconText } = require('./common');
|
|||||||
|
|
||||||
// Add comment
|
// Add comment
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!theme.valine.enable || !theme.valine.appId || !theme.valine.appKey) return;
|
||||||
|
|
||||||
injects.comment.raw('valine', '<div class="comments" id="valine-comments"></div>', {}, {cache: true});
|
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
|
// Add post_meta
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!theme.valine.enable || !theme.valine.appId || !theme.valine.appKey) return;
|
||||||
|
|
||||||
injects.postMeta.raw('valine', `
|
injects.postMeta.raw('valine', `
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
const points = require('../events/lib/injects-point');
|
const points = require('../events/lib/injects-point');
|
||||||
|
|
||||||
hexo.extend.filter.register('theme_inject', injects => {
|
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;
|
if (!filePath) return;
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ hexo.extend.filter.register('after_post_render', data => {
|
|||||||
if (!href) return match;
|
if (!href) return match;
|
||||||
|
|
||||||
// Exit if the url has same host with `config.url`, which means it's an internal link.
|
// 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;
|
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>`;
|
return `<span class="exturl" data-url="${Buffer.from(href).toString('base64')}">${html}<i class="fa fa-external-link-alt"></i></span>`;
|
||||||
|
|||||||
@ -53,7 +53,7 @@ hexo.extend.helper.register('post_nav', function(post) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
hexo.extend.helper.register('gitalk_md5', function(path) {
|
hexo.extend.helper.register('gitalk_md5', function(path) {
|
||||||
let str = this.url_for(path);
|
const str = this.url_for(path);
|
||||||
str.replace('index.html', '');
|
str.replace('index.html', '');
|
||||||
return crypto.createHash('md5').update(str).digest('hex');
|
return crypto.createHash('md5').update(str).digest('hex');
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,9 +8,9 @@ const url = require('url');
|
|||||||
* Export theme config to js
|
* Export theme config to js
|
||||||
*/
|
*/
|
||||||
hexo.extend.helper.register('next_config', function() {
|
hexo.extend.helper.register('next_config', function() {
|
||||||
let { config, theme, next_version } = this;
|
const { config, theme, next_version } = this;
|
||||||
config.algolia = config.algolia || {};
|
config.algolia = config.algolia || {};
|
||||||
let exportConfig = {
|
const exportConfig = {
|
||||||
hostname : url.parse(config.url).hostname || config.url,
|
hostname : url.parse(config.url).hostname || config.url,
|
||||||
root : config.root,
|
root : config.root,
|
||||||
scheme : theme.scheme,
|
scheme : theme.scheme,
|
||||||
|
|||||||
@ -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
|
* If option have `class` attribute, add it to
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
hexo.extend.helper.register('js_vendors', function() {
|
hexo.extend.helper.register('js_vendors', function() {
|
||||||
let { config, theme } = this;
|
const { config, theme } = this;
|
||||||
let vendors = {
|
const vendors = {
|
||||||
anime: 'lib/anime.min.js'
|
anime: 'lib/anime.min.js'
|
||||||
};
|
};
|
||||||
if (config.prismjs.enable && !config.prismjs.preprocess) {
|
if (config.prismjs.enable && !config.prismjs.preprocess) {
|
||||||
|
|||||||
@ -43,7 +43,7 @@ hexo.extend.helper.register('next_tagcloud', function(options) {
|
|||||||
tags.forEach(tag => {
|
tags.forEach(tag => {
|
||||||
const ratio = length ? sizes.indexOf(tag.length) / length : 0;
|
const ratio = length ? sizes.indexOf(tag.length) / length : 0;
|
||||||
const size = min + ((max - min) * ratio);
|
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(
|
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>`
|
`<a href="${this.url_for(tag.path)}" style="${style}" class="tag-cloud-${Math.round(ratio * 10)}">${transform ? transform(tag.name) : tag.name}</a>`
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
function postButton(args) {
|
function postButton(args) {
|
||||||
args = args.join(' ').split(',');
|
args = args.join(' ').split(',');
|
||||||
let url = args[0];
|
const url = args[0];
|
||||||
let text = args[1] || '';
|
let text = args[1] || '';
|
||||||
let icon = args[2] || '';
|
let icon = args[2] || '';
|
||||||
let title = args[3] || '';
|
let title = args[3] || '';
|
||||||
|
|||||||
@ -73,7 +73,7 @@ const LAYOUTS = {
|
|||||||
|
|
||||||
function groupBy(group, data) {
|
function groupBy(group, data) {
|
||||||
const r = [];
|
const r = [];
|
||||||
for (let count of group) {
|
for (const count of group) {
|
||||||
r.push(data.slice(0, count));
|
r.push(data.slice(0, count));
|
||||||
data = data.slice(count);
|
data = data.slice(count);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function pdf(args) {
|
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>`;
|
return `<div class="pdfobject-container" data-target="${args[0]}" data-height="${args[1] || theme.pdf.height}"></div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const algoliaSettings = CONFIG.algolia;
|
const algoliaSettings = CONFIG.algolia;
|
||||||
const { indexName, appID, apiKey } = algoliaSettings;
|
const { indexName, appID, apiKey } = algoliaSettings;
|
||||||
|
|
||||||
let search = instantsearch({
|
const search = instantsearch({
|
||||||
indexName,
|
indexName,
|
||||||
searchClient : algoliasearch(appID, apiKey),
|
searchClient : algoliasearch(appID, apiKey),
|
||||||
searchFunction: helper => {
|
searchFunction: helper => {
|
||||||
@ -40,7 +40,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
container: '#algolia-stats',
|
container: '#algolia-stats',
|
||||||
templates: {
|
templates: {
|
||||||
text: data => {
|
text: data => {
|
||||||
let stats = algoliaSettings.labels.hits_stats
|
const stats = algoliaSettings.labels.hits_stats
|
||||||
.replace(/\$\{hits}/, data.nbHits)
|
.replace(/\$\{hits}/, data.nbHits)
|
||||||
.replace(/\$\{time}/, data.processingTimeMS);
|
.replace(/\$\{time}/, data.processingTimeMS);
|
||||||
return `${stats}
|
return `${stats}
|
||||||
@ -56,7 +56,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
container: '#algolia-hits',
|
container: '#algolia-hits',
|
||||||
templates: {
|
templates: {
|
||||||
item: data => {
|
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>`;
|
return `<a href="${link}" class="algolia-hit-item-link">${data._highlightResult.title.value}</a>`;
|
||||||
},
|
},
|
||||||
empty: data => {
|
empty: data => {
|
||||||
|
|||||||
@ -17,15 +17,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
const getIndexByWord = (word, text, caseSensitive) => {
|
const getIndexByWord = (word, text, caseSensitive) => {
|
||||||
if (CONFIG.localsearch.unescape) {
|
if (CONFIG.localsearch.unescape) {
|
||||||
let div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.innerText = word;
|
div.innerText = word;
|
||||||
word = div.innerHTML;
|
word = div.innerHTML;
|
||||||
}
|
}
|
||||||
let wordLen = word.length;
|
const wordLen = word.length;
|
||||||
if (wordLen === 0) return [];
|
if (wordLen === 0) return [];
|
||||||
let startPosition = 0;
|
let startPosition = 0;
|
||||||
let position = [];
|
let position = [];
|
||||||
let index = [];
|
const index = [];
|
||||||
if (!caseSensitive) {
|
if (!caseSensitive) {
|
||||||
text = text.toLowerCase();
|
text = text.toLowerCase();
|
||||||
word = word.toLowerCase();
|
word = word.toLowerCase();
|
||||||
@ -41,7 +41,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const mergeIntoSlice = (start, end, index, searchText) => {
|
const mergeIntoSlice = (start, end, index, searchText) => {
|
||||||
let item = index[index.length - 1];
|
let item = index[index.length - 1];
|
||||||
let { position, word } = item;
|
let { position, word } = item;
|
||||||
let hits = [];
|
const hits = [];
|
||||||
let searchTextCountInSlice = 0;
|
let searchTextCountInSlice = 0;
|
||||||
while (position + word.length <= end && index.length !== 0) {
|
while (position + word.length <= end && index.length !== 0) {
|
||||||
if (word === searchText) {
|
if (word === searchText) {
|
||||||
@ -51,7 +51,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
position,
|
position,
|
||||||
length: word.length
|
length: word.length
|
||||||
});
|
});
|
||||||
let wordEnd = position + word.length;
|
const wordEnd = position + word.length;
|
||||||
|
|
||||||
// Move to next position of hit
|
// Move to next position of hit
|
||||||
index.pop();
|
index.pop();
|
||||||
@ -80,7 +80,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
let prevEnd = slice.start;
|
let prevEnd = slice.start;
|
||||||
slice.hits.forEach(hit => {
|
slice.hits.forEach(hit => {
|
||||||
result += text.substring(prevEnd, hit.position);
|
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>`;
|
result += `<b class="search-keyword">${text.substring(hit.position, end)}</b>`;
|
||||||
prevEnd = end;
|
prevEnd = end;
|
||||||
});
|
});
|
||||||
@ -90,17 +90,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
const inputEventFunction = () => {
|
const inputEventFunction = () => {
|
||||||
if (!isfetched) return;
|
if (!isfetched) return;
|
||||||
let searchText = input.value.trim().toLowerCase();
|
const searchText = input.value.trim().toLowerCase();
|
||||||
let keywords = searchText.split(/[-\s]+/);
|
const keywords = searchText.split(/[-\s]+/);
|
||||||
if (keywords.length > 1) {
|
if (keywords.length > 1) {
|
||||||
keywords.push(searchText);
|
keywords.push(searchText);
|
||||||
}
|
}
|
||||||
let resultItems = [];
|
const resultItems = [];
|
||||||
if (searchText.length > 0) {
|
if (searchText.length > 0) {
|
||||||
// Perform local searching
|
// Perform local searching
|
||||||
datas.forEach(({ title, content, url }) => {
|
datas.forEach(({ title, content, url }) => {
|
||||||
let titleInLowerCase = title.toLowerCase();
|
const titleInLowerCase = title.toLowerCase();
|
||||||
let contentInLowerCase = content.toLowerCase();
|
const contentInLowerCase = content.toLowerCase();
|
||||||
let indexOfTitle = [];
|
let indexOfTitle = [];
|
||||||
let indexOfContent = [];
|
let indexOfContent = [];
|
||||||
let searchTextCount = 0;
|
let searchTextCount = 0;
|
||||||
@ -111,7 +111,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// Show search results
|
// Show search results
|
||||||
if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
|
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
|
// Sort index by position of keyword
|
||||||
[indexOfTitle, indexOfContent].forEach(index => {
|
[indexOfTitle, indexOfContent].forEach(index => {
|
||||||
index.sort((itemLeft, itemRight) => {
|
index.sort((itemLeft, itemRight) => {
|
||||||
@ -122,17 +122,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let slicesOfTitle = [];
|
const slicesOfTitle = [];
|
||||||
if (indexOfTitle.length !== 0) {
|
if (indexOfTitle.length !== 0) {
|
||||||
let tmp = mergeIntoSlice(0, title.length, indexOfTitle, searchText);
|
const tmp = mergeIntoSlice(0, title.length, indexOfTitle, searchText);
|
||||||
searchTextCount += tmp.searchTextCountInSlice;
|
searchTextCount += tmp.searchTextCountInSlice;
|
||||||
slicesOfTitle.push(tmp);
|
slicesOfTitle.push(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
let slicesOfContent = [];
|
let slicesOfContent = [];
|
||||||
while (indexOfContent.length !== 0) {
|
while (indexOfContent.length !== 0) {
|
||||||
let item = indexOfContent[indexOfContent.length - 1];
|
const item = indexOfContent[indexOfContent.length - 1];
|
||||||
let { position, word } = item;
|
const { position, word } = item;
|
||||||
// Cut out 100 characters
|
// Cut out 100 characters
|
||||||
let start = position - 20;
|
let start = position - 20;
|
||||||
let end = position + 80;
|
let end = position + 80;
|
||||||
@ -145,7 +145,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (end > content.length) {
|
if (end > content.length) {
|
||||||
end = content.length;
|
end = content.length;
|
||||||
}
|
}
|
||||||
let tmp = mergeIntoSlice(start, end, indexOfContent, searchText);
|
const tmp = mergeIntoSlice(start, end, indexOfContent, searchText);
|
||||||
searchTextCount += tmp.searchTextCountInSlice;
|
searchTextCount += tmp.searchTextCountInSlice;
|
||||||
slicesOfContent.push(tmp);
|
slicesOfContent.push(tmp);
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Select top N slices in content
|
// 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) {
|
if (upperBound >= 0) {
|
||||||
slicesOfContent = slicesOfContent.slice(0, upperBound);
|
slicesOfContent = slicesOfContent.slice(0, upperBound);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ NexT.utils = {
|
|||||||
|
|
||||||
registerExtURL: function() {
|
registerExtURL: function() {
|
||||||
document.querySelectorAll('span.exturl').forEach(element => {
|
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
|
// 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 => {
|
link.href = decodeURIComponent(atob(element.dataset.url).split('').map(c => {
|
||||||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||||
@ -122,8 +122,8 @@ NexT.utils = {
|
|||||||
const box = document.createElement('div');
|
const box = document.createElement('div');
|
||||||
box.className = 'video-container';
|
box.className = 'video-container';
|
||||||
element.wrap(box);
|
element.wrap(box);
|
||||||
let width = Number(element.width);
|
const width = Number(element.width);
|
||||||
let height = Number(element.height);
|
const height = Number(element.height);
|
||||||
if (width && height) {
|
if (width && height) {
|
||||||
box.style.paddingTop = (height / width * 100) + '%';
|
box.style.paddingTop = (height / width * 100) + '%';
|
||||||
}
|
}
|
||||||
@ -278,10 +278,10 @@ NexT.utils = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
supportsPDFs: function() {
|
supportsPDFs: function() {
|
||||||
let ua = navigator.userAgent;
|
const ua = navigator.userAgent;
|
||||||
let isFirefoxWithPDFJS = ua.includes('irefox') && parseInt(ua.split('rv:')[1].split('.')[0], 10) > 18;
|
const isFirefoxWithPDFJS = ua.includes('irefox') && parseInt(ua.split('rv:')[1].split('.')[0], 10) > 18;
|
||||||
let supportsPdfMimeType = typeof navigator.mimeTypes['application/pdf'] !== 'undefined';
|
const supportsPdfMimeType = typeof navigator.mimeTypes['application/pdf'] !== 'undefined';
|
||||||
let isIOS = /iphone|ipad|ipod/i.test(ua.toLowerCase());
|
const isIOS = /iphone|ipad|ipod/i.test(ua.toLowerCase());
|
||||||
return isFirefoxWithPDFJS || (supportsPdfMimeType && !isIOS);
|
return isFirefoxWithPDFJS || (supportsPdfMimeType && !isIOS);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -350,8 +350,8 @@ NexT.utils = {
|
|||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let intersectionObserver = new IntersectionObserver((entries, observer) => {
|
const intersectionObserver = new IntersectionObserver((entries, observer) => {
|
||||||
let entry = entries[0];
|
const entry = entries[0];
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
callback();
|
callback();
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user