new: Complete modules related to home page, archive page and article page

This commit is contained in:
2024-12-16 14:13:58 +08:00
parent 04267841f0
commit 65e5e9eafc
49 changed files with 1547 additions and 1 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
const tocBox = document.getElementById('toc-box');
const tList = document.getElementById('post-content').querySelectorAll('h1, h2, h3, h4, h5, h6');
const hList = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
let tmpHtml = `<div>\n`;
Array.from(tList, v => {
// get the level number
const H = hList.indexOf(v.nodeName) + 1 || 1;
tmpHtml += `<div class="li li-${H} toc-li"><a id="${v.id}" href="#">${v.textContent}</a></div>\n`;
});
tmpHtml += `</div>`
tocBox.innerHTML = tmpHtml;
Array.from(tList, v => {
const btn = document.getElementById('toc-box').querySelector(`#${v.id}`);
const ele = document.getElementById('post-content').querySelector(`#${v.id}`);
if (!btn || !ele) {
return;
}
btn.addEventListener('click', (event) => {
event.preventDefault();
window.scrollTo({ top: ele.offsetTop - 60, behavior: 'smooth' });
});
});
const tocMenu = document.getElementById('toc-box-menu');
window.addEventListener('scroll', (event) => {
const scrollFromTop = window.scrollY || document.documentElement.scrollTop;
if (scrollFromTop >= 100) {
tocMenu.style.display = 'block';
} else {
tocMenu.style.display = 'none';
}
})
function goto(path) {
window.location.href = path;
}
function backToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
})
}