From 06d8444c54cdd8b2fdf148e70606ead1bd560f44 Mon Sep 17 00:00:00 2001 From: XPoet Date: Wed, 27 Jan 2021 12:03:49 +0800 Subject: [PATCH] feat: add toc.init_open configuration item in theme _config.yml --- _config.yml | 3 +++ source/js/toc.js | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/_config.yml b/_config.yml index 99f63b5..74a2509 100644 --- a/_config.yml +++ b/_config.yml @@ -110,6 +110,9 @@ toc: # If true, all level of TOC in a post will be displayed, rather than the activated part of it. expand_all: false + # If true, open TOC every time when you enter the article page + init_open: false + # --------------------------------------------------------------------------------------- # Post copyright info diff --git a/source/js/toc.js b/source/js/toc.js index fbbc66f..ceef590 100644 --- a/source/js/toc.js +++ b/source/js/toc.js @@ -67,13 +67,26 @@ function initTOC() { }, showPageAsideWhenHasTOC() { - const styleStatus = KEEP.getStyleStatus(); - const key = 'isOpenPageAside'; - if (styleStatus && styleStatus.hasOwnProperty(key)) { - KEEP.utils.leftSideToggle.pageAsideHandleOfTOC(styleStatus[key]); - } else { - KEEP.utils.leftSideToggle.pageAsideHandleOfTOC(true); + + const openHandle = () => { + const styleStatus = KEEP.getStyleStatus(); + const key = 'isOpenPageAside'; + if (styleStatus && styleStatus.hasOwnProperty(key)) { + KEEP.utils.leftSideToggle.pageAsideHandleOfTOC(styleStatus[key]); + } else { + 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(); + } + } }