Skip to content

Commit

Permalink
perf(side): 如果 sidebar 为空,隐藏 sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
MHuiG committed Sep 4, 2022
1 parent 1072c2e commit a264a8c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const locationHash = () => {
if (target) {
setTimeout(() => {
if (window.location.hash.startsWith('#fn')) { // hexo-reference https://github.com/volantis-x/hexo-theme-volantis/issues/647
volantis.scroll.to(target, { addTop: - volantis.dom.header.offsetHeight - 5, behavior: 'instant', observer:true })
volantis.scroll.to(target, { addTop: - volantis.dom.header.offsetHeight - 5, behavior: 'instant', observer: true })
} else {
// 锚点中上半部有大片空白 高度大概是 volantis.dom.header.offsetHeight
volantis.scroll.to(target, { addTop: 5, behavior: 'instant', observer:true })
volantis.scroll.to(target, { addTop: 5, behavior: 'instant', observer: true })
}
}, 1000)
}
Expand Down Expand Up @@ -71,6 +71,15 @@ const VolantisApp = (() => {
fn.scrolltoElement(volantis.dom.bodyAnchor);
});

// 如果 sidebar 为空,隐藏 sidebar。
const sidebar = document.querySelector("#l_side")
if (sidebar) {
const sectionList = sidebar.querySelectorAll("section")
if (!sectionList.length) {
document.querySelector("#l_main").classList.add("no_sidebar")
}
}

// 站点信息 最后活动日期
if (volantis.GLOBAL_CONFIG.sidebar.for_page.includes('webinfo') || volantis.GLOBAL_CONFIG.sidebar.for_post.includes('webinfo')) {
const lastupd = volantis.GLOBAL_CONFIG.sidebar.webinfo.lastupd;
Expand Down

0 comments on commit a264a8c

Please sign in to comment.