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 # PDF tag
# NexT will try to load pdf files natively, if failed, pdf.js will be used. # 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. # 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: pdf:
enable: false enable: false
# Default height # Default height

View File

@ -26,11 +26,7 @@ document.addEventListener('pjax:success', () => {
} }
const hasTOC = document.querySelector('.post-toc'); const hasTOC = document.querySelector('.post-toc');
document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC); document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC);
if (hasTOC) { document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click();
document.querySelector('.sidebar-nav-toc').click();
} else {
document.querySelector('.sidebar-nav-overview').click();
}
NexT.utils.updateSidebarPosition(); NexT.utils.updateSidebarPosition();
}); });
</script> </script>

View File

@ -28,7 +28,13 @@ njkRenderer.compile = function(data) {
const compiledTemplate = njkCompile(data); const compiledTemplate = njkCompile(data);
// Need a closure to keep the compiled template. // Need a closure to keep the compiled template.
return function(locals) { 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,8 +62,8 @@ NexT.motion.middleWares = {
document.querySelectorAll('.menu-item').forEach(targets => { document.querySelectorAll('.menu-item').forEach(targets => {
sequence.push({ sequence.push({
targets, targets,
begin : () => targets.classList.add('animated', 'fadeInDown'), complete: () => targets.classList.add('animated', 'fadeInDown'),
deltaT: '-=200' deltaT : '-=200'
}); });
}); });
@ -89,8 +89,8 @@ NexT.motion.middleWares = {
document.querySelectorAll(selector).forEach(targets => { document.querySelectorAll(selector).forEach(targets => {
sequence.push({ sequence.push({
targets, targets,
begin : () => targets.classList.add('animated', animation), complete: () => targets.classList.add('animated', animation),
deltaT: '-=100' deltaT : '-=100'
}); });
}); });
} }
@ -109,8 +109,8 @@ NexT.motion.middleWares = {
// Only for Pisces | Gemini. // Only for Pisces | Gemini.
if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) { if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) {
return [{ return [{
targets: sidebar, targets : sidebar,
begin : () => sidebar.classList.add('animated', sidebarTransition) complete: () => sidebar.classList.add('animated', sidebarTransition)
}]; }];
} }
return []; return [];

View File

@ -66,6 +66,7 @@ NexT.utils = {
document.querySelectorAll('figure.highlight').forEach(element => { document.querySelectorAll('figure.highlight').forEach(element => {
element.querySelectorAll('.code .line span').forEach(span => { element.querySelectorAll('.code .line span').forEach(span => {
span.classList.forEach(name => { span.classList.forEach(name => {
// https://caniuse.com/#feat=mdn-api_element_classlist_replace
span.classList.remove(name); span.classList.remove(name);
span.classList.add(`hljs-${name}`); span.classList.add(`hljs-${name}`);
}); });
@ -138,8 +139,8 @@ NexT.utils = {
if (backToTop || readingProgressBar) { if (backToTop || readingProgressBar) {
const docHeight = document.querySelector('.container').offsetHeight; const docHeight = document.querySelector('.container').offsetHeight;
const winHeight = window.innerHeight; const winHeight = window.innerHeight;
const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight; const contentHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight;
const scrollPercent = Math.min(100 * window.scrollY / contentVisibilityHeight, 100); const scrollPercent = contentHeight > 0 ? Math.min(100 * window.scrollY / contentHeight, 100) : 0;
if (backToTop) { if (backToTop) {
backToTop.classList.toggle('back-to-top-on', Math.round(scrollPercent) >= 5); backToTop.classList.toggle('back-to-top-on', Math.round(scrollPercent) >= 5);
backToTop.querySelector('span').innerText = Math.round(scrollPercent) + '%'; backToTop.querySelector('span').innerText = Math.round(scrollPercent) + '%';