mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-21 19:32:34 +00:00
Use optional chaining
This commit is contained in:
parent
c8f828dd66
commit
bd3961d350
@ -15,11 +15,11 @@ module.exports = hexo => {
|
|||||||
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);
|
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cache && cache.enable && language_switcher) {
|
if (cache?.enable && language_switcher) {
|
||||||
warning('language_switcher', 'caching');
|
warning('language_switcher', 'caching');
|
||||||
cache.enable = false;
|
cache.enable = false;
|
||||||
}
|
}
|
||||||
if (cache && cache.enable && hexo.config.relative_link) {
|
if (cache?.enable && hexo.config.relative_link) {
|
||||||
warning('caching', '`relative_link` option in Hexo `_config.yml`');
|
warning('caching', '`relative_link` option in Hexo `_config.yml`');
|
||||||
hexo.config.relative_link = false;
|
hexo.config.relative_link = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ module.exports = function() {
|
|||||||
// Get a font list from config
|
// Get a font list from config
|
||||||
let fontFamilies = [];
|
let fontFamilies = [];
|
||||||
['global', 'title', 'headings', 'posts', 'codes'].forEach(item => {
|
['global', 'title', 'headings', 'posts', 'codes'].forEach(item => {
|
||||||
if (config[item] && config[item].family && config[item].external) {
|
if (config[item]?.family && config[item].external) {
|
||||||
fontFamilies = fontFamilies.concat(config[item].family.split(','));
|
fontFamilies = fontFamilies.concat(config[item].family.split(','));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,7 +36,7 @@ hexo.extend.helper.register('next_config', function() {
|
|||||||
hits : __('search.hits', '${hits}')
|
hits : __('search.hits', '${hits}')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (config.algolia && theme.algolia_search && theme.algolia_search.enable) {
|
if (config.algolia && theme.algolia_search?.enable) {
|
||||||
exportConfig.algolia = {
|
exportConfig.algolia = {
|
||||||
appID : config.algolia.applicationID || config.algolia.appId,
|
appID : config.algolia.applicationID || config.algolia.appId,
|
||||||
apiKey : config.algolia.apiKey,
|
apiKey : config.algolia.apiKey,
|
||||||
@ -44,7 +44,7 @@ hexo.extend.helper.register('next_config', function() {
|
|||||||
hits : theme.algolia_search.hits
|
hits : theme.algolia_search.hits
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (config.search && theme.local_search && theme.local_search.enable) {
|
if (config.search && theme.local_search?.enable) {
|
||||||
exportConfig.path = url_for(config.search.path);
|
exportConfig.path = url_for(config.search.path);
|
||||||
exportConfig.localsearch = theme.local_search;
|
exportConfig.localsearch = theme.local_search;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ NexT.boot.registerEvents = function() {
|
|||||||
const tHash = location.hash;
|
const tHash = location.hash;
|
||||||
if (tHash !== '' && !tHash.match(/%\S{2}/)) {
|
if (tHash !== '' && !tHash.match(/%\S{2}/)) {
|
||||||
const target = document.querySelector(`.tabs ul.nav-tabs li a[href="${tHash}"]`);
|
const target = document.querySelector(`.tabs ul.nav-tabs li a[href="${tHash}"]`);
|
||||||
target && target.click();
|
target?.click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -169,7 +169,7 @@ NexT.utils = {
|
|||||||
updateActiveNav() {
|
updateActiveNav() {
|
||||||
if (!Array.isArray(this.sections)) return;
|
if (!Array.isArray(this.sections)) return;
|
||||||
let index = this.sections.findIndex(element => {
|
let index = this.sections.findIndex(element => {
|
||||||
return element && element.getBoundingClientRect().top > 10;
|
return element?.getBoundingClientRect().top > 10;
|
||||||
});
|
});
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
index = this.sections.length - 1;
|
index = this.sections.length - 1;
|
||||||
@ -198,7 +198,7 @@ NexT.utils = {
|
|||||||
this.updateActiveNav();
|
this.updateActiveNav();
|
||||||
}, { passive: true });
|
}, { passive: true });
|
||||||
|
|
||||||
backToTop && backToTop.addEventListener('click', () => {
|
backToTop?.addEventListener('click', () => {
|
||||||
window.anime({
|
window.anime({
|
||||||
targets : document.scrollingElement,
|
targets : document.scrollingElement,
|
||||||
duration : 500,
|
duration : 500,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user