Some minor fixes

This commit is contained in:
Mimi 2020-07-09 13:10:08 +08:00
parent 31298d003e
commit 46b4ad92b3
5 changed files with 18 additions and 15 deletions

View File

@ -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

View File

@ -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();
});
</script>

View File

@ -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;
};
};

View File

@ -62,7 +62,7 @@ NexT.motion.middleWares = {
document.querySelectorAll('.menu-item').forEach(targets => {
sequence.push({
targets,
begin : () => targets.classList.add('animated', 'fadeInDown'),
complete: () => targets.classList.add('animated', 'fadeInDown'),
deltaT : '-=200'
});
});
@ -89,7 +89,7 @@ NexT.motion.middleWares = {
document.querySelectorAll(selector).forEach(targets => {
sequence.push({
targets,
begin : () => targets.classList.add('animated', animation),
complete: () => targets.classList.add('animated', animation),
deltaT : '-=100'
});
});
@ -110,7 +110,7 @@ NexT.motion.middleWares = {
if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) {
return [{
targets : sidebar,
begin : () => sidebar.classList.add('animated', sidebarTransition)
complete: () => sidebar.classList.add('animated', sidebarTransition)
}];
}
return [];

View File

@ -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) + '%';