diff --git a/_config.yml b/_config.yml index af49f61..db0a92a 100644 --- a/_config.yml +++ b/_config.yml @@ -793,7 +793,7 @@ tabs: # PDF tag # NexT will try to load pdf files natively, if failed, pdf.js will be used. # So, you have to install the dependency of pdf.js if you want to use pdf tag and make it available to all browsers. -# See: https://github.com/next-theme/theme-next-pdf +# Dependencies: https://github.com/next-theme/theme-next-pdf pdf: enable: false # Default height diff --git a/layout/_scripts/pjax.njk b/layout/_scripts/pjax.njk index be26c1f..6c74ed6 100644 --- a/layout/_scripts/pjax.njk +++ b/layout/_scripts/pjax.njk @@ -26,11 +26,7 @@ document.addEventListener('pjax:success', () => { } const hasTOC = document.querySelector('.post-toc'); document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC); - if (hasTOC) { - document.querySelector('.sidebar-nav-toc').click(); - } else { - document.querySelector('.sidebar-nav-overview').click(); - } + document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click(); NexT.utils.updateSidebarPosition(); }); diff --git a/scripts/renderer.js b/scripts/renderer.js index 3986ca8..321ac2e 100644 --- a/scripts/renderer.js +++ b/scripts/renderer.js @@ -28,7 +28,13 @@ njkRenderer.compile = function(data) { const compiledTemplate = njkCompile(data); // Need a closure to keep the compiled template. return function(locals) { - return compiledTemplate.render(locals); + let result = ''; + try { + result = compiledTemplate.render(locals); + } catch (error) { + hexo.log.error(error); + } + return result; }; }; diff --git a/source/js/motion.js b/source/js/motion.js index 54ef464..faaab32 100644 --- a/source/js/motion.js +++ b/source/js/motion.js @@ -62,8 +62,8 @@ NexT.motion.middleWares = { document.querySelectorAll('.menu-item').forEach(targets => { sequence.push({ targets, - begin : () => targets.classList.add('animated', 'fadeInDown'), - deltaT: '-=200' + complete: () => targets.classList.add('animated', 'fadeInDown'), + deltaT : '-=200' }); }); @@ -89,8 +89,8 @@ NexT.motion.middleWares = { document.querySelectorAll(selector).forEach(targets => { sequence.push({ targets, - begin : () => targets.classList.add('animated', animation), - deltaT: '-=100' + complete: () => targets.classList.add('animated', animation), + deltaT : '-=100' }); }); } @@ -109,8 +109,8 @@ NexT.motion.middleWares = { // Only for Pisces | Gemini. if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) { return [{ - targets: sidebar, - begin : () => sidebar.classList.add('animated', sidebarTransition) + targets : sidebar, + complete: () => sidebar.classList.add('animated', sidebarTransition) }]; } return []; diff --git a/source/js/utils.js b/source/js/utils.js index d1a849a..92c5c58 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -66,6 +66,7 @@ NexT.utils = { document.querySelectorAll('figure.highlight').forEach(element => { element.querySelectorAll('.code .line span').forEach(span => { span.classList.forEach(name => { + // https://caniuse.com/#feat=mdn-api_element_classlist_replace span.classList.remove(name); span.classList.add(`hljs-${name}`); }); @@ -138,8 +139,8 @@ NexT.utils = { if (backToTop || readingProgressBar) { const docHeight = document.querySelector('.container').offsetHeight; const winHeight = window.innerHeight; - const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight; - const scrollPercent = Math.min(100 * window.scrollY / contentVisibilityHeight, 100); + const contentHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight; + const scrollPercent = contentHeight > 0 ? Math.min(100 * window.scrollY / contentHeight, 100) : 0; if (backToTop) { backToTop.classList.toggle('back-to-top-on', Math.round(scrollPercent) >= 5); backToTop.querySelector('span').innerText = Math.round(scrollPercent) + '%';