[opt] toc collapse config

This commit is contained in:
xaoxuu 2024-01-02 19:50:42 +08:00
parent f348f94b79
commit dc0e43688f
3 changed files with 26 additions and 9 deletions

View File

@ -34,6 +34,7 @@ recent:
layout: recent
rss: # /atom.xml # npm i hexo-generator-feed
limit: 5 # Count of posts
# TOC (valid only in layout:post/wiki)
toc:
layout: toc
@ -41,6 +42,8 @@ toc:
min_depth: 2
max_depth: 5
fallback: recent # Use a backup widget when toc does not exist.
collapse: false # true / false / auto
# github user info
ghuser:
layout: ghuser

View File

@ -66,7 +66,7 @@ function layoutDiv(fallback) {
var el = '';
if (type.length > 0) {
el += '<widget class="widget-wrapper toc ' + type + '" id="data-toc">';
el += `<widget class="widget-wrapper toc ${type}" id="data-toc" collapse="${item.collapse}">`;
if (page.layout !== 'wiki') {
// post 布局
el += layoutTocHeader(page.toc_title);

View File

@ -69,14 +69,28 @@
color: $color-theme !important
&:before
visibility: visible
//
.widget-wrapper.toc[collapse='true']
.toc-item a.toc-link+ol
display: none
//
.toc a.toc-link.active+ol
display: block
//
.widget-wrapper.toc[collapse='auto']
.toc-item a.toc-link+ol
display: none
//
.toc a.toc-link.active+ol
display: block
//
&:hover a.toc-link+ol
display: block
//
.toc-item a.toc-link+ol
display: none
.toc a.toc-link.active+ol
display: block
ol:has(> .toc-item a.active)
display: block
.doc-tree:hover a.toc-link+ol
//
.widget-wrapper.toc[collapse='true'] ol:has(> .toc-item a.active)
display: block
.widget-wrapper.toc[collapse='auto'] ol:has(> .toc-item a.active)
display: block