feat: add toc.init_open configuration item in theme _config.yml

This commit is contained in:
XPoet 2021-01-27 12:03:49 +08:00
parent f8e3d6a65a
commit 06d8444c54
2 changed files with 22 additions and 6 deletions

View File

@ -110,6 +110,9 @@ toc:
# If true, all level of TOC in a post will be displayed, rather than the activated part of it. # If true, all level of TOC in a post will be displayed, rather than the activated part of it.
expand_all: false expand_all: false
# If true, open TOC every time when you enter the article page
init_open: false
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# Post copyright info # Post copyright info

View File

@ -67,6 +67,8 @@ function initTOC() {
}, },
showPageAsideWhenHasTOC() { showPageAsideWhenHasTOC() {
const openHandle = () => {
const styleStatus = KEEP.getStyleStatus(); const styleStatus = KEEP.getStyleStatus();
const key = 'isOpenPageAside'; const key = 'isOpenPageAside';
if (styleStatus && styleStatus.hasOwnProperty(key)) { if (styleStatus && styleStatus.hasOwnProperty(key)) {
@ -75,6 +77,17 @@ function initTOC() {
KEEP.utils.leftSideToggle.pageAsideHandleOfTOC(true); KEEP.utils.leftSideToggle.pageAsideHandleOfTOC(true);
} }
} }
const initOpenKey = 'init_open';
if (KEEP.theme_config.toc.hasOwnProperty(initOpenKey)) {
KEEP.theme_config.toc[initOpenKey] ? openHandle() : KEEP.utils.leftSideToggle.pageAsideHandleOfTOC(false);
} else {
openHandle();
}
}
} }
KEEP.utils.showPageAsideWhenHasTOC(); KEEP.utils.showPageAsideWhenHasTOC();